Skip to main content

Provision Docker databases in Python — Postgres, Neo4j, MongoDB, MySQL, MSSQL with a unified one-call API

Project description

py-dockerdb

Pythonic Docker database management for notebooks, tutorials, and fast MVPs.

Build PyPI License Docs

pip install py-dockerdb

py-dockerdb gives you one Python API to create, connect, and clean up Docker databases: PostgreSQL, MySQL, MongoDB, MSSQL, Redis, Neo4j, and Ollama. It is built for people who teach, demo, and prototype with notebooks and need repeatable local databases in seconds.

Switch from PostgreSQL to MongoDB without changing a line of connection code. Test a pgvector RAG pipeline, then swap to Neo4j for GraphRAG with one config change. Or hand every student a pre-seeded database at the start of class without touching Docker on their machine.

When to use this

  • Teaching a SQL workshop: two lines give every learner a working, pre-seeded database, identical across Windows/Mac/Linux.
  • Comparing databases for an MVP: run Postgres, MongoDB, Redis, and Neo4j through the same interface and pick based on behaviour, not setup time.
  • Local RAG prototype: spin up pgvector, validate retrieval, swap to another backend in one config change without touching orchestration code.
  • GraphRAG with Neo4j: Neo4jDB.connection returns a neo4j.Driver that plugs directly into LlamaIndex's Neo4jGraphStore and LangChain's Neo4jGraph.

Supported Databases

PostgreSQL MySQL MongoDB SQL Server Redis Neo4j Ollama

Prerequisites

  • Python 3.10+ · Docker running

Installation

pip install py-dockerdb                # core
pip install "py-dockerdb[graph]"       # + Neo4j / LlamaIndex / LangChain
pip install "py-dockerdb[rag]"         # + pgvector / LlamaIndex

Usage

Define a config, call create_db(), run your workload, tear down with delete_db().

PostgreSQL

from docker_db.dbs.postgres_db import PostgresConfig, PostgresDB

db = PostgresDB(PostgresConfig(user="u", password="p", database="d", project_name="demo"))
db.create_db()
conn = db.connection          # psycopg2 connection
cur = conn.cursor()
cur.execute("SELECT version();")
print(cur.fetchone())
db.delete_db(running_ok=True)

Neo4j / GraphRAG

from docker_db.dbs.neo4j_db import Neo4jConfig, Neo4jDB

db = Neo4jDB(Neo4jConfig(password="p", project_name="demo"))
db.create_db()
driver = db.connection        # neo4j.Driver -> hand to Neo4jGraphStore or Neo4jGraph
with driver.session() as s:
    s.run("CREATE (n:Person {name: 'Alice'})")
    print(s.run("MATCH (n:Person) RETURN n.name").single()[0])
db.delete_db(running_ok=True)

Ollama

from docker_db.dbs.ollama_db import OllamaConfig, OllamaDB

db = OllamaDB(OllamaConfig(project_name="demo"))
db.create_db()
session = db.connection       # requests.Session
db.pull_model("llama3")
resp = session.post(f"{db.base_url}/api/generate", json={"model": "llama3", "prompt": "Hello", "stream": False})
print(resp.json()["response"])
db.delete_db(running_ok=True)

More examples

Full runnable notebooks are in usage/:

PostgreSQL · MySQL · MongoDB · MSSQL · Redis · Neo4j / GraphRAG · pgvector RAG · Lifecycle

Roadmap

  • PostgreSQL + pgvector
  • Neo4j
  • Qdrant
  • Chroma
  • Weaviate
  • Milvus

Development

git clone https://github.com/amadou-6e/docker-db.git
cd docker-db
pip install -e ".[test]"

Testing

python -m pytest -vv -s tests/test_manager.py
python -m pytest -vv -s tests/test_postgres.py
python -m pytest -vv -s tests/test_postgres_pgvector.py
python -m pytest -vv -s tests/test_mysql.py
python -m pytest -vv -s tests/test_mongodb.py
python -m pytest -vv -s tests/test_mssql.py
python -m pytest -vv -s tests/test_redis.py
python -m pytest -vv -s tests/test_cassandra.py
python -m pytest -vv -s tests/test_neo4j.py
python -m pytest -vv -s tests/test_opensearch.py
python -m pytest -vv -s tests/test_qdrant.py
python -m pytest -vv -s tests/test_ollama.py
python -m pytest -vv -s tests/test_notebooks.py

Contributing

PRs welcome. Include tests for behaviour changes and keep notebooks runnable.

License

MIT License. See LICENSE.

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

py_dockerdb-1.0.0.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_dockerdb-1.0.0-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

Details for the file py_dockerdb-1.0.0.tar.gz.

File metadata

  • Download URL: py_dockerdb-1.0.0.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_dockerdb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0730fc347bac72be2a22084064982b16360490a9b399547acc185f4c9e71c546
MD5 ba92541a77766ec4b1f4ab88ddcff18f
BLAKE2b-256 75e8f2191e42b2fa2942b9fb9abb276854353ba904f1c372849696b7e3dc0885

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_dockerdb-1.0.0.tar.gz:

Publisher: cicd.yml on amadou-6e/py-docker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_dockerdb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_dockerdb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 43.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_dockerdb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40853481f97d15b468a89648dc52ea7ca41050c4889eb2b35b76eec5561130f7
MD5 544ad467f2844b65c210f1f138089630
BLAKE2b-256 d56a0a4daeba4049c15fd76a29ccaecb361417531fa5874733cc8b4e78a614b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_dockerdb-1.0.0-py3-none-any.whl:

Publisher: cicd.yml on amadou-6e/py-docker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page