Skip to main content

docs/imgs/

BioKb-ChEBI

BioKb-ChEBI (biokb_chebi) is a python package to import ChEBI (Chemical Entities of Biological Interest) data into a relational database and create RDF triples (turtles) from it. The turtle files can be imported into a Neo4J graph database or any other RDF-compatible graph database like Fuseki. The package is part of the BioKb family of packages to create and connect biological and medical knowledge bases and graphs.

Components

Fig. 1: Components of BioKb-ChEBI: Data are imported from ChEBI into a relational database, transformed into RDF triples, and then imported into a graph database. A Restful API provides access to the data and facilitates queries and data management.

biokb_chebi provides different options to run it:

  1. command line (biokb_chebi import-data, biokb_chebi create-turtles and biokb_chebi import-neo4j)
  2. RESTful API server (FastAPI)
  3. Podman/Docker container
  4. Podman/Docker networked containers with phpMyAdmin, Neo4J and MySQL (using podman-compose or docker-compose).

Quick Start

All further instructions assume that uv (and GitBash on Windows) are installed. . Go here for instructions on installing or upgrading uv.

Setup Virtual Environment

create a test folder and navigate into it:

mkdir test_folder
cd test_folder

create a virtual environment using uv:

Linux / macOS:

# create and activate virtual environment using uv
uv venv
source .venv/bin/activate

Windows (Git Bash):

# create and activate virtual environment using uv
uv venv
source .venv\Scripts\activate

Install biokb_chebi

You have 2 options to install biokb_chebi using uv pip install:

Option 1: Install the latest version from PyPI

uv pip install biokb_chebi

Option 2: Install the latest development version from GitHub

uv pip install git+https://github.com/biokb/biokb_chebi.git

Option 2 is recommended if you want to use the latest version with the most recent updates and features.

Import imported data

In the terminal (cli commands):

biokb_chebi import-data

Output will show some information about the data import and database location/connection:

biokb_chebi.tools - INFO - No environment file provided or CONNECTION_STR not found. Using default connection string sqlite:////path/to/your/home/.biokb/biokb.db.
biokb_chebi.db.manager - INFO - Engine: Engine(sqlite:////path/to/your/home/.biokb/biokb.db)
biokb_chebi.db.manager - INFO - Data folder: /path/to/your/home/.biokb/chebi/data
biokb_chebi.db.manager - INFO - Start download of data
100%|███████████████████████████████████████████████████████████████████████████████████| 11/11 [00:00<00:00, 121414.06it/s]
biokb_chebi.db.manager - INFO - Files already exist: 11
biokb_chebi.db.manager - INFO - Files downloaded: 0
biokb_chebi.db.manager - INFO - Insert data in database
100%|███████████████████████████████████████████████████████████████████████████████████| 11/11 [02:18<00:00, 12.57s/it]

As Python functions in a script:

from biokb_chebi import import_data, create_ttls
import_data()
create_ttls()

If you want to test the import into a Neo4j database, start a temporary container wiith podman:

podman run --rm --name biokb-neo4j-test -p7474:7474 -p7687:7687 -e NEO4J_AUTH=neo4j/neo4j_password neo4j:latest

and then in the terminal (still in the same virtual enviroment) ...

biokb_chebi import-neo4j

Type in your password (neo4j_password), and open http://localhost:7474 for checking the import.

Features

biokb_chebi allows to ...

  1. Query ChEBI data with SQLAlchemy or raw SQL -> see examples in the Relational Database Jupyter Notebook
  2. Load, query and manage ChEBI data with GUIs for knowledge base and graphs (phpMyAdmin, Neo4J Browser)
  3. Query data via a RESTful API (FastAPI) with OpenAPI documentation and interactive Swagger-UI

to provide this biokb_chebi ...

  • imports ChEBI data into a relational database
  • creates RDF triples (turtles) from the relational database
  • imports the RDF triples into a Neo4J graph database

Supported databases: SQLite, MariaDB/MySQL, PostgreSQL, Oracle, Microsoft SQL Server, and any other database supported by SQLAlchemy.

Options to run BioKb-ChEBI

All biokb packages share the same API and CLI structure. You have different options to run the packages:

  1. from command line (simplest way to get started)
  2. as RESTful API server (can start directly from command line)
  3. as Podman/Docker container (without import into Neo4J, but export of turtles possible)
  4. as Podman/Docker networked containers (with all features) and 3 containers:
    1. high-performance relational databases (PostgreSQL, Oracle, MySQL, ...)
    2. RESTful API (fastAPI) for queries, data import and export
    3. GUI for querying and administration of MySQL over the Web

Installation

If uv is installed:

uv venv
source .venv/bin/activate
uv pip install biokb_chebi

Otherwise:

python3 -m venv .venv
source .venv/bin/activate
pip install biokb_chebi

Run BioKb-ChEBI

From command line

For sure the simplest way is to run all steps:

biokb_chebi import-data
biokb_chebi create-turtles

Before importing into Neo4J, make sure Neo4J is running (see below "How to run Neo4J").

Then import into Neo4J:

biokb_chebi import-neo4j -p neo4j_password

http://localhost:7474 (user/password: neo4j/neo4j_password)

For more options see the CLI options section below.

As RESTful API server

Usage: biokb_chebi run-server [OPTIONS]

biokb_chebi run-server
  • user: admin
  • password: admin
Option long Description default
-P --port API server port 8000
-u --user API username admin
-p --password API password admin

http://localhost:8000/docs#/

  1. Import data
  2. Export ttls
  3. Run Neo4J (see below "How to run Neo4J")
  4. Import Neo4J

Be patient, each step takes several minutes.

As Podman/Docker container

For docker just replace podman with docker in the commands below.

Build & run with Podman:

git clone https://github.com/biokb/biokb_chebi.git
cd biokb_chebi
podman build -t biokb_chebi_image .
podman run -d --rm --name biokb_chebi_simple -p 8000:8000 biokb_chebi_image
  • Login: admin
  • Password: admin

With environment variable for user and password for more security:

podman run -d --rm --name biokb_chebi_simple -p 8000:8000 -e API_PASSWORD=your_secure_password -e API_USER=your_secure_user biokb_chebi_image

http://localhost:8000/docs

On the website:

  1. Import data
  2. Export ttls

Neo4j import in this context is not possible because Neo4J is not running in the same network as service, but the exported turtles can be imported into any Neo4J instance using the CLI (biokb_chebi import-neo4j).

to stop the container:

podman stop biokb_chebi_simple

to rerun the container:

podman start biokb_chebi_simple

Run as Podman/Docker networked containers

If you have docker or podman on your system, the easiest way to run all components (relational database, RESTful API server, phpMyAdmin GUI) is to use networked containers with podman-compose/docker-compose.

git clone https://github.com/biokb/biokb_taxtree.git
cd biokb_taxtree
podman-compose -f docker-compose.yml --env-file .env_template up -d
podman-compose --env-file .env_template up -d

http://localhost:8001/docs

On the website:

  1. Import data
  2. Export ttls
  3. Import Neo4J

stop with:

podman pod stop pod_biokb_db
podman-compose stop

rerun with:

podman pod start pod_biokb_db
podman-compose start

Tip: Copy the .env_template to .env and change the default passwords in the .env file before starting the containers for better security. If you have done that you need to use --env-file .env instead of --env-file .env_template in the commands above or just omit the --env-file option (because the default is .env).

CLI Options

Import data into relational database

Usage: biokb_chebi import-data [OPTIONS]

biokb_chebi import-data

-> SQLite database in ~/.biokb/biokb.db. Open with e.g. DB Browser for SQLite

Option long Description default
-f --force-download Force re-download of the source file False
-k --keep-files Keep downloaded source files after import False
-c --connection-string TEXT SQLAlchemy engine URL sqlite:///chebi.db

If you want to use different relational database (MySQL, PostgreSQL, etc.), provide the connection string with -c option. Examples:

  • MySQL: mysql+pymysql://user:password@localhost/biokb
  • PostgreSQL: postgresql+psycopg2://user:password@localhost/biokb

For more examples please check how to create database URLs

Create RDF turtles

Usage: biokb_chebi create-turtles [OPTIONS]

biokb_chebi create-turtles

-> RDF turtles will be created in ~/.biokb/chebi/data/ttls.zip

Option long Description default
-c --connection-string TEXT SQLAlchemy engine URL sqlite:///chebi.db

Import into Neo4J

Start Neo4J ...

podman run --rm --name biokb-neo4j-test -p7474:7474 -p7687:7687 -e NEO4J_AUTH=neo4j/neo4j_password neo4j:latest

Note: Remove --rm if you want to keep the container after stopping it. Replace podman with docker if you use Docker.

... and import into Neo4J:

biokb_chebi import-neo4j -p neo4j_password
Option long Description default
-i --uri Neo4j database URI bolt://localhost:7687
-u --user Neo4j username neo4j
-p --password Neo4j password

http://localhost:7474 (user/password: neo4j/neo4j_password)

How to run Neo4J

For the options "Run BioKb-ChEBI as ..."

  1. From command line
  2. As RESTful API server

you need to run Neo4J separately.

If you have not already a Neo4j instance running, the easiest way is to run Neo4J as Podman/ Docker container.

For docker just replace podman with docker in the commands below.

podman run -d --rm --name biokb-neo4j -p7474:7474 -p7687:7687 -e NEO4J_AUTH=neo4j/neo4j_password neo4j:latest
# Remove `--rm` if you want to keep the container after stopping it.

Neo4J is then available at: http://localhost:7474 (user/password: neo4j/neo4j_password

Stop Neo4J with:

podman stop biokb-neo4j

if you have not used --rm above, you can restart Neo4J with:

podman start biokb-neo4j

Query database with SQLAlchemy

In order to query the database with SQLAlchemy you can use the following code snippet:

import os
from biokb_chebi import get_session
from biokb_chebi.db.models import Compound
os.environ.pop("CONNECTION_STR", None)  # to make sure no environment variable is used
with get_session() as session:
    results = session.query(Compound).filter(Compound.name.ilike("%glucose%")).limit(2)
    for row in results:
        print(f"Name: {row.ascii_name}, Name: {row.source}")

Output:

Name: 1,2,3,4-tetrakis-O-galloyl-alpha-D-glucose, Name: KEGG COMPOUND
Name: 1-caffeoyl-beta-D-glucose, Name: KEGG COMPOUND

UV installation/upgrade

It's strongly recommended to use a virtual environment to avoid conflicts with other Python packages. Best modern practice is to use uv to create an isolated environment for your project. If you have not installed uv yet, you can do by:

Linux / macOS:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

If you have already uv on your system and want to upgrade:

uv self update

Metadata

Release files for biokb-chebi 26.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for biokb-chebi 26.11.1
File Size Uploaded Provenance Actions
biokb_chebi-26.11.1.tar.gz 922.9 kB With provenance Details for biokb_chebi-26.11.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for biokb-chebi 26.11.1
File Interpreter ABI Platform Actions
biokb_chebi-26.11.1-py3-none-any.whl Python 3 none any Details for biokb_chebi-26.11.1-py3-none-any.whl

Total release size: 953.9 kB

Release files / biokb_chebi-26.11.1.tar.gz

Download URL biokb_chebi-26.11.1.tar.gz
Size 922.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9980d008c9462ac7df4000affa90e493e8e7309def2bc3e73590ee73ca5481d2
BLAKE2b-256 checksum
How to use checksums
f64d1ccd95d3956fc6c5c28700b1fa5bbd2b716a3b649c35e1892e4532d46982
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / biokb_chebi-26.11.1-py3-none-any.whl

Download URL biokb_chebi-26.11.1-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
687f10e7161b6573a7547cca4c58d91dfb83daa9916fcae6a7f7e6928103f3d6
BLAKE2b-256 checksum
How to use checksums
0366c15e731c6b0080d8073f4216b55c35b34bc94a6702a8d775217f6e192b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for biokb-chebi 26.11.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for biokb_chebi-26.11.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page