Sign inDemoInstall


Package Overview
File Explorer

Install Socket

Protect your apps from supply chain attacks



Parsing, validation, compilation, and data exchange of Biological Expression Language (BEL)




PyBEL |zenodo| |build| |coverage| |documentation| |bioregistry| |black|
`PyBEL <>`_ is a pure Python package for parsing and handling biological networks encoded in
the `Biological Expression Language <>`_

It facilitates data interchange between data formats like `NetworkX <>`_,
Node-Link JSON, `JGIF <>`_, CSV, SIF,
`Cytoscape <>`_, `CX <>`_,
`INDRA <>`_, and `GraphDati <>`_; database systems
like SQL and `Neo4J <>`_; and web services like `NDEx <>`_,
`BioDati Studio <>`_, and `BEL Commons <>`_. It also
provides exports for analytical tools like `HiPathia <>`_,
`Drug2ways <>`_ and `SPIA <>`_;
machine learning tools like `PyKEEN <>`_ and
`OpenBioLink <>`_; and others.

Its companion package, `PyBEL Tools <>`_, contains a
suite of functions and pipelines for analyzing the resulting biological networks.

We realize that we have a name conflict with the python wrapper for the cheminformatics package, OpenBabel. If you're
looking for their python wrapper, see `here <>`_.

If you find PyBEL useful for your work, please consider citing:

.. [1] Hoyt, C. T., *et al.* (2017). `PyBEL: a Computational Framework for Biological Expression Language
       <>`_. *Bioinformatics*, 34(December), 1–2.

Installation |pypi_version| |python_versions| |pypi_license|
PyBEL can be installed easily from `PyPI <>`_ with the following code in
your favorite shell:

.. code-block:: sh

    $ pip install pybel

or from the latest code on `GitHub <>`_ with:

.. code-block:: sh

    $ pip install git+

See the `installation documentation <>`_ for more advanced
instructions. Also, check the change log at `CHANGELOG.rst <>`_.

Getting Started
More examples can be found in the `documentation <>`_ and in the
`PyBEL Notebooks <>`_ repository.

Compiling and Saving a BEL Graph
This example illustrates how the a BEL document from the `Human Brain Pharmacome
<>`_ project can be loaded and compiled directly from GitHub.

.. code-block:: python

   >>> import pybel
   >>> url = ''
   >>> graph = pybel.from_bel_script_url(url)

Other functions for loading BEL content from many formats can be found in the
`I/O documentation <>`_.
Note that PyBEL can handle `BEL 1.0 <>`_
and `BEL 2.0+ <>`_

After you have a BEL graph, there are numerous ways to save it. The ``pybel.dump`` function knows
how to output it in many formats based on the file extension you give. For all of the possibilities,
check the `I/O documentation <>`_.

.. code-block:: python

   >>> import pybel
   >>> graph = ...
   >>> # write as BEL
   >>> pybel.dump(graph, 'my_graph.bel')
   >>> # write as Node-Link JSON for network viewers like D3
   >>> pybel.dump(graph, 'my_graph.bel.nodelink.json')
   >>> # write as GraphDati JSON for BioDati
   >>> pybel.dump(graph, 'my_graph.bel.graphdati.json')
   >>> # write as CX JSON for NDEx
   >>> pybel.dump(graph, '')
   >>> # write as INDRA JSON for INDRA
   >>> pybel.dump(graph, 'my_graph.indra.json')

Summarizing the Contents of the Graph
The ``BELGraph`` object has several "dispatches" which are properties that organize its various functionalities.
One is the ``BELGraph.summarize`` dispatch, which allows for printing summaries to the console.

These examples will use the `RAS Model <>`_  from EMMAA,
so you'll have to be sure to ``pip install indra`` first. The graph can be acquired and summarized with
``BELGraph.summarize.statistics()`` as in:

.. code-block:: python

    >>> import pybel
    >>> graph = pybel.from_emmaa('rasmodel', date='2020-05-29-17-31-58')  # Needs
    >>> graph.summarize.statistics()
    ---------------------  -------------------
    Name                   rasmodel
    Version                2020-05-29-17-31-58
    Number of Nodes        126
    Number of Namespaces   5
    Number of Edges        206
    Number of Annotations  4
    Number of Citations    1
    Number of Authors      0
    Network Density        1.31E-02
    Number of Components   1
    Number of Warnings     0
    ---------------------  -------------------

The number of nodes of each type can be summarized with ``BELGraph.summarize.nodes()`` as in:

.. code-block:: python

    >>> graph.summarize.nodes(examples=False)
    Type (3)        Count
    ------------  -------
    Protein            97
    Complex            27
    Abundance           2

The number of nodes with each namespace can be summarized with ``BELGraph.summarize.namespaces()`` as in:

.. code-block:: python

    >>> graph.summarize.namespaces(examples=False)
    Namespace (4)      Count
    ---------------  -------
    HGNC                  94
    FPLX                   3
    CHEBI                  1
    TEXT                   1

The edges can be summarized with ``BELGraph.summarize.edges()`` as in:

.. code-block:: python

    >>> graph.summarize.edges(examples=False)
    Edge Type (12)                       Count
    ---------------------------------  -------
    Protein increases Protein               64
    Protein hasVariant Protein              48
    Protein partOf Complex                  47
    Complex increases Protein               20
    Protein decreases Protein                9
    Complex directlyIncreases Protein        8
    Protein increases Complex                3
    Abundance partOf Complex                 3
    Protein increases Abundance              1
    Complex partOf Complex                   1
    Protein decreases Abundance              1
    Abundance decreases Protein              1

Grounding the Graph
Not all BEL graphs contain both the name and identifier for each entity. Some even use non-standard prefixes
(also called **namespaces** in BEL). Usually, BEL graphs are validated against controlled vocabularies,
so the following demo shows how to add the corresponding identifiers to all nodes.

.. code-block:: python

    from urllib.request import urlretrieve

    url = ''
    urlretrieve(url, 'large_corpus.bel.nodelink.json.gz')

    import pybel
    graph = pybel.load('large_corpus.bel.nodelink.json.gz')

    import pybel.grounding
    grounded_graph = pybel.grounding.ground(graph)

Note: you have to install ``pyobo`` for this to work and be running Python 3.7+.

Displaying a BEL Graph in Jupyter
After installing ``jinja2`` and ``ipython``, BEL graphs can be displayed in Jupyter notebooks.

.. code-block:: python

   >>> from pybel.examples import sialic_acid_graph
   >>> from import to_jupyter
   >>> to_jupyter(sialic_acid_graph)

Using the Parser
If you don't want to use the ``pybel.BELGraph`` data structure and just want to turn BEL statements into JSON
for your own purposes, you can directly use the ``pybel.parse()`` function.

.. code-block:: python

    >>> import pybel
    >>> pybel.parse('p(hgnc:4617 ! GSK3B) regulates p(hgnc:6893 ! MAPT)')
    {'source': {'function': 'Protein', 'concept': {'namespace': 'hgnc', 'identifier': '4617', 'name': 'GSK3B'}}, 'relation': 'regulates', 'target': {'function': 'Protein', 'concept': {'namespace': 'hgnc', 'identifier': '6893', 'name': 'MAPT'}}}

This functionality can also be exposed through a Flask-based web application with ``python -m pybel.apps.parser`` after
installing ``flask`` with ``pip install flask``. Note that the first run requires about a ~2 second delay to generate
the parser, after which each parse is very fast.

Using the CLI
PyBEL also installs a command line interface with the command :code:`pybel` for simple utilities such as data
conversion. In this example, a BEL document is compiled then exported to `GraphML <>`_
for viewing in Cytoscape.

.. code-block:: sh

    $ pybel compile ~/Desktop/example.bel
    $ pybel serialize ~/Desktop/example.bel --graphml ~/Desktop/example.graphml

In Cytoscape, open with :code:`Import > Network > From File`.

Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See
`CONTRIBUTING.rst <>`_ for more information on getting

The development of PyBEL has been supported by several projects/organizations (in alphabetical order):

- `The Cytoscape Consortium <>`_
- `Enveda Biosciences <>`_
- `Fraunhofer Center for Machine Learning <>`_
- `Fraunhofer Institute for Algorithms and Scientific Computing (SCAI) <>`_
- `Harvard Program in Therapeutic Science - Laboratory of Systems Pharmacology <>`_
- `University of Bonn <>`_

- DARPA Young Faculty Award W911NF2010255 (PI: Benjamin M. Gyori).
- The `European Union <>`_, `European Federation of Pharmaceutical Industries and Associations
  (EFPIA) <>`_, and `Innovative Medicines Initiative <>`_ Joint
  Undertaking under `AETIONOMY <>`_ [grant number 115568], resources of which
  are composed of financial contribution from the European Union's Seventh Framework Programme (FP7/2007-2013) and
  EFPIA companies in kind contribution.

The PyBEL `logo <>`_ was designed by `Scott Colby <>`_.

.. |build| image::
    :alt: Build Status

.. |coverage| image::
    :alt: Development Coverage Status

.. |documentation| image::
    :alt: Development Documentation Status

.. |climate| image::
    :alt: Code Climate

.. |python_versions| image::
    :alt: Stable Supported Python Versions

.. |pypi_version| image::
    :alt: Current version on PyPI

.. |pypi_license| image::
    :alt: MIT License

.. |zenodo| image::

.. |bioregistry| image::;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAEnAAABJwGNvPDMAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAACi9JREFUWIWtmXl41MUZxz/z291sstmQO9mQG0ISwHBtOOSwgpUQhApWgUfEowKigKI81actypaqFbWPVkGFFKU0Vgs+YgvhEAoqEUESrnDlEEhCbkLYJtlkk9399Y/N/rKbzQXt96+Zed+Z9/t7Z+adeecnuA1s5yFVSGrLOAf2qTiEEYlUZK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iTnpatwTJOFMIKcgvPVX/kNIcM1gSgC8iTZfii3aEL+7fyG+C+6O8izl1GE5gAAAABJRU5ErkJggg==
    :alt: Powered by the Bioregistry

.. |black| image::
    :alt: Code style: black



Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc