A Python package to import Coconut data in MySQL and Neo4J databases for the BioKB knowledge base.
Project description
BioKb-Coconut
BioKb-Coconut (biokb_coconut) is a python package to import Coconut data into a relational database and create RDF triples (turtles) from it. The turtles can be imported into a Neo4J graph database. The package is part of the BioKb family of packages to create and connect biological and medical knowledge bases and graphs.
The package provides different options to run it: from command line, as RESTful API server, as Podman/Docker container, or as Podman/Docker networked containers with Neo4J and a relational database.
Features
biokb_coconut allows to ...
- Query Coconut data with SQLAlchemy or raw SQL
- Load, query and manage Coconut data with GUIs for knowledge base and graphs (phpMyAdmin, Neo4J Browser)
- Query data via a RESTful API (FastAPI) with OpenAPI documentation and interactive Swagger-UI
to provide this biokb_coconut ...
- imports Coconut 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-Coconut
All biokb packages share the same API and CLI structure. You have different options to run the packages:
- from command line (simplest way to get started)
- as RESTful API server (can start directly from command line)
- as Podman/Docker container (without import into Neo4J, but export of turtles possible)
- as Podman/Docker networked containers (with all features) and 3 containers:
- high-performance relational databases (PostgreSQL, Oracle, MySQL, ...)
- RESTful API (fastAPI) for queries, data import and export
- 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_coconut
Otherwise:
python3 -m venv .venv
source .venv/bin/activate
pip install biokb_coconut
Run BioKb-Coconut
From command line
For sure the simplest way is to run all steps:
biokb_coconut import-data
biokb_coconut create-ttls
Before importing into Neo4J, make sure Neo4J is running (see below "How to run Neo4J").
Then import into Neo4J:
biokb_coconut 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_coconut run-api [OPTIONS]
biokb_coconut run-api
- user: admin
- password: admin
| Option | long | Description | default |
|---|---|---|---|
| -P | --port | API server port | 8000 |
| -u | --user | API username | admin |
| -p | --password | API password | admin |
- Import data
- Export ttls
- Run Neo4J (see below "How to run Neo4J")
- 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_coconut.git
cd biokb_coconut
podman build -t biokb_coconut_image .
podman run -d --rm --name biokb_coconut_simple -p 8000:8000 biokb_coconut_image
- Login: admin
- Password: admin
With environment variable for user and password for more security:
podman run -d --rm --name biokb_coconut_simple -p 8000:8000 -e API_PASSWORD=your_secure_password -e API_USER=your_secure_user biokb_coconut_image
On the website:
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_coconut import-neo4j).
to stop the container:
podman stop biokb_coconut_simple
to rerun the container:
podman start biokb_coconut_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_coconut.git
cd biokb_coconut
podman-compose -f docker-compose.db_neo.yml --env-file .env_template up -d
On the website:
stop with:
docker stop biokb_coconut
rerun with:
docker start biokb_coconut
Tip: Change the default passwords in the .env_template file before starting the containers for better security.
CLI Options
Import data into relational database
Usage: biokb_coconut import-data [OPTIONS]
biokb_coconut 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:///coconut.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_coconut create-ttls [OPTIONS]
biokb_coconut create-ttls
-> RDF turtles will be created in ~/.biokb/coconut/data/ttls.zip
| Option | long | Description | default |
|---|---|---|---|
| -c | --connection-string TEXT | SQLAlchemy engine URL | sqlite:///coconut.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_coconut 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-Coconut as ..."
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
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file biokb_coconut-0.1.2.tar.gz.
File metadata
- Download URL: biokb_coconut-0.1.2.tar.gz
- Upload date:
- Size: 511.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dcc167ab2d21e421a59a7da388b01b67d72c1a943fc28072c86e488ee326ac6
|
|
| MD5 |
dc046eb60ba74f4700059aae521d2479
|
|
| BLAKE2b-256 |
1ff062c73a3caf178ba1ccc8fa1bfeb2ad965fbaae3ba37173c4694609c1ab51
|
Provenance
The following attestation bundles were made for biokb_coconut-0.1.2.tar.gz:
Publisher:
pypi-publish.yml on biokb/biokb_coconut
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
biokb_coconut-0.1.2.tar.gz -
Subject digest:
8dcc167ab2d21e421a59a7da388b01b67d72c1a943fc28072c86e488ee326ac6 - Sigstore transparency entry: 808855209
- Sigstore integration time:
-
Permalink:
biokb/biokb_coconut@ebac945cf43de3453aa3b889bd82b1ee0b61db79 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/biokb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@ebac945cf43de3453aa3b889bd82b1ee0b61db79 -
Trigger Event:
push
-
Statement type:
File details
Details for the file biokb_coconut-0.1.2-py3-none-any.whl.
File metadata
- Download URL: biokb_coconut-0.1.2-py3-none-any.whl
- Upload date:
- Size: 34.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ec691e4d4d1b567ad686081d951eacb29f1de48501a78031017af4a8a53e21c
|
|
| MD5 |
4ceb62f482a52ce899d7831a078a72ef
|
|
| BLAKE2b-256 |
ace2a47ab4e23c9a88a536237eeca34626b6d4a117a1603e994f985916501502
|
Provenance
The following attestation bundles were made for biokb_coconut-0.1.2-py3-none-any.whl:
Publisher:
pypi-publish.yml on biokb/biokb_coconut
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
biokb_coconut-0.1.2-py3-none-any.whl -
Subject digest:
7ec691e4d4d1b567ad686081d951eacb29f1de48501a78031017af4a8a53e21c - Sigstore transparency entry: 808855279
- Sigstore integration time:
-
Permalink:
biokb/biokb_coconut@ebac945cf43de3453aa3b889bd82b1ee0b61db79 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/biokb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@ebac945cf43de3453aa3b889bd82b1ee0b61db79 -
Trigger Event:
push
-
Statement type: