Skip to content

About

Babelfish Python client

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Latest commit

 

History

60 Commits

Folders and files

Repository files navigation

client-python Build Status PyPI

Babelfish Python client library provides functionality to both connect to the Babelfish server to parse code (obtaining an UAST as a result) and to analyse UASTs with the functionality provided by libuast.

Installation

The recommended way to install client-python is using our pip package:

pip install bblfsh

From sources

git clone https://github.com/bblfsh/client-python.git
cd client-python
make install

Dependencies

You need to install libxml2 and its header files. The command for Debian and derived distributions would be:

sudo apt install libxml2-dev

Usage

A small example of how to parse a Python file and extract the import declarations from the UAST.

If you don't have a bblfsh server running you can execute it using the following command:

docker run --privileged --rm -it -p 9432:9432 --name bblfsh bblfsh/server

Please, read the getting started guide to learn more about how to use and deploy a bblfsh server.

from bblfsh import BblfshClient, filter

client = BblfshClient("0.0.0.0:9432")
print(client.parse("/path/to/file.py"))
# "filter' allows you to use XPath queries to filter on result nodes:
print(client.filter("//Import[@roleImportDeclaration]//alias")

License

Apache License 2.0, see LICENSE

About

Babelfish Python client

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages