Clone or download
Latest commit e8483d9 Oct 30, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
bblfsh Add type hints Oct 30, 2018
proto/ Fix PB imports (#122) Sep 4, 2018
.gitignore Fix PB imports (#122) Sep 4, 2018
.travis.yml avoid double uploads to pypi on CI Oct 24, 2018
DCO Added DCO Aug 2, 2017
LICENSE Initial commit Jun 14, 2017
MAINTAINERS docs: Add MAINTAINERS file Jul 5, 2017 Add missing file to MANIFEST Mar 9, 2018 fix broken links in Oct 9, 2018
requirements.txt Bump grpcio version Jul 25, 2018 dump version Oct 24, 2018

client-python Build Status PyPI

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


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

pip install bblfsh

From sources

git clone
cd client-python
python install


You need to install libxml2 and its header files. You also will need a curl cli tool to dowload libuast, and a g++ for building libtuast Python bindings. The command for Debian and derived distributions would be:

sudo apt install libxml2-dev
sudo apt install curl
sudo apt install build-essential


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 -v bblfsh_cache:/var/lib/bblfshd --name bblfshd bblfsh/bblfshd
docker exec -it bblfshd bblfshctl driver install python bblfsh/python-driver:latest

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

import bblfsh

client = bblfsh.BblfshClient("")
uast = client.parse("/path/to/").uast
# "filter' allows you to use XPath queries to filter on result nodes:
print(bblfsh.filter(uast, "//Import[@roleImport and @roleDeclaration]//alias"))

# filter\_[bool|string|number] must be used when using XPath functions returning
# these types:
print(bblfsh.filter_bool(uast, "boolean(//*[@strtOffset or @endOffset])"))
print(bblfsh.filter_string(uast, "name(//*[1])"))
print(bblfsh.filter_number(uast, "count(//*)"))

# You can also iterate on several tree iteration orders:
it = bblfsh.iterator(uast, bblfsh.TreeOrder.PRE_ORDER)
for node in it:

Please read the Babelfish clients guide section to learn more about babelfish clients and their query language.


Apache License 2.0, see LICENSE