Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- tests/test_neo4j.py
- tests/test_redis.py
- tests/test_opensearch.py
- tests/test_qdrant.py

steps:
- name: Checkout
Expand Down
160 changes: 36 additions & 124 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,158 +6,65 @@
[![PyPI](https://img.shields.io/pypi/v/py-dockerdb)](https://pypi.org/project/py-dockerdb/)
[![License](https://img.shields.io/badge/license-MIT-lightgrey)](./LICENSE)

`py-dockerdb` gives you easy Docker database setup in Python for PostgreSQL, MySQL, MongoDB, Microsoft SQL Server, Redis, and Neo4j. It is built for people who teach, demo, and prototype with notebooks or scripts and need repeatable local databases in minutes. Instead of writing Docker commands and per-engine setup code, you use one API to create, start, connect, and clean up containers.

Switch from PostgreSQL to MongoDB and back without changing a line of connection code. This makes side-by-side database comparison a first-class workflow - useful for MVPs where the right engine isn't decided yet, and for RAG and GraphRAG experiments where you want to test one storage backend, then swap it out without rewriting environment glue.

If you teach SQL or data workflows, it removes the environment-setup section from your slides entirely: every student runs the same two lines and gets a working database.
`py-dockerdb` gives you easy Docker database setup in Python for PostgreSQL, MySQL, MongoDB, Microsoft SQL Server, Redis, Cassandra, Neo4j, OpenSearch, Qdrant, and Ollama. It is built for people who teach, demo, and prototype with notebooks or scripts and need repeatable local databases in minutes.

## When to use this

- **Teaching a SQL workshop or notebook tutorial** - every learner starts from the same environment with no per-machine Docker setup required.
- **Comparing databases for an MVP** - run PostgreSQL, MySQL, MongoDB, MSSQL, Redis, and Neo4j under the same Python interface and switch engines without rewriting connection code.
- **Building a local RAG prototype** - spin up a backing store, test your retrieval pipeline, then swap from PostgreSQL to MongoDB in one config change without touching orchestration code.
- **GraphRAG with Neo4j** - provision a local knowledge graph for multi-hop retrieval pipelines. The `Neo4jDB.connection` property returns a `neo4j.Driver` that plugs directly into LlamaIndex's `Neo4jGraphStore` and LangChain's `Neo4jGraph`.
- **Teaching workshops**: every learner starts from the same environment.
- **Comparing databases for an MVP**: switch backends with minimal code changes.
- **Local RAG / GraphRAG prototyping**: run vector and graph backends locally.
- **Local LLM experiments**: use Ollama in Docker for model-serving workflows.

## Supported Databases

[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-4169E1?logo=postgresql&logoColor=white)](https://www.postgresql.org/docs/)
[![MySQL](https://img.shields.io/badge/MySQL-4479A1?logo=mysql&logoColor=white)](https://dev.mysql.com/doc/)
[![MongoDB](https://img.shields.io/badge/MongoDB-47A248?logo=mongodb&logoColor=white)](https://www.mongodb.com/docs/)
[![SQL Server](https://img.shields.io/badge/SQL_Server-CC2927?logo=microsoftsqlserver&logoColor=white)](https://learn.microsoft.com/en-us/sql/sql-server/)
[![Redis](https://img.shields.io/badge/Redis-DC382D?logo=redis&logoColor=white)](https://redis.io/docs/)
[![Neo4j](https://img.shields.io/badge/Neo4j-008CC1?logo=neo4j&logoColor=white)](https://neo4j.com/docs/)
- PostgreSQL
- MySQL
- MongoDB
- Microsoft SQL Server
- Redis
- Cassandra
- Neo4j
- OpenSearch
- Qdrant
- Ollama

## Prerequisites

- Python 3.10+
- Docker installed and running
- Database drivers (installed automatically with package dependencies):
- `psycopg2-binary` for PostgreSQL
- `mysql-connector-python` for MySQL
- `pymongo` for MongoDB
- `pyodbc` for MSSQL
- `redis` for Redis
- `neo4j` for Neo4j

## Installation

```bash
# Core
pip install py-dockerdb

# With graph dependencies (Neo4j driver, LlamaIndex / LangChain graph stores)
pip install "py-dockerdb[graph]"
# Graph/RAG extras
pip install "py-dockerdb[graph,rag]"
```

## Usage

The API is consistent across all engines: define a config, call `create_db()`, run your workload, then tear down with `delete_db()`.

### PostgreSQL example

```python
import uuid
from pathlib import Path
from docker_db.dbs.postgres_db import PostgresConfig, PostgresDB

container_name = f"demo-postgres-{uuid.uuid4().hex[:8]}"
temp_dir = Path("tmp")
temp_dir.mkdir(exist_ok=True)

config = PostgresConfig(
user="demouser",
password="demopass",
database="demodb",
project_name="demo",
container_name=container_name,
workdir=temp_dir.absolute(),
retries=20,
delay=3,
)

db_manager = PostgresDB(config)
db_manager.create_db()

conn = db_manager.connection
cur = conn.cursor()
cur.execute("SELECT version();")
print(cur.fetchone())

cur.close()
conn.close()
db_manager.delete_db(running_ok=True)
```

### Neo4j / GraphRAG example

```python
import uuid
from pathlib import Path
from docker_db.dbs.neo4j_db import Neo4jConfig, Neo4jDB

container_name = f"demo-neo4j-{uuid.uuid4().hex[:8]}"
temp_dir = Path("tmp")
temp_dir.mkdir(exist_ok=True)

config = Neo4jConfig(
password="demopass",
project_name="demo",
container_name=container_name,
workdir=temp_dir.absolute(),
)

db_manager = Neo4jDB(config)
db_manager.create_db()

driver = db_manager.connection
with driver.session() as session:
session.run("CREATE (n:Person {name: 'Alice'})")
result = session.run("MATCH (n:Person) RETURN n.name AS name")
print(result.single()["name"]) # Alice

driver.close()
db_manager.delete_db(running_ok=True)
```
The API is consistent across engines: define a config, call `create_db()`, run your workload, then tear down with `delete_db()`.

### More examples
See runnable notebooks in [`usage/`](./usage/):

Full runnable notebooks for each engine are in the [`usage/`](./usage/) directory:

- [PostgreSQL](./usage/postgres_example.ipynb)
- [MySQL](./usage/mysql_example.ipynb)
- [MongoDB](./usage/mongo_example.ipynb)
- [MSSQL](./usage/mssql_example.ipynb)
- [Redis](./usage/redis_example.ipynb)
- [Neo4j / GraphRAG](./usage/neo4j_example.ipynb)
- [Container lifecycle and management](./usage/db_management_example.ipynb)

### Seeding data for demos and workshops

Use `init_script` to preload tables or documents before handing the environment to students or running a live demo.

```python
config = PostgresConfig(
...
init_script=Path("./configs/postgres/initdb.sh"),
)
```

### SQL magic and client tool integration

```python
conn_string = db_manager.connection_string(sql_magic=True)
```
- `postgres_example.ipynb`
- `mysql_example.ipynb`
- `mongo_example.ipynb`
- `mssql_example.ipynb`
- `redis_example.ipynb`
- `neo4j_example.ipynb`
- `ollama_example.ipynb`

## Roadmap

Docker-friendly vector and graph backends that can be run locally without paid licenses:

- [x] PostgreSQL + `pgvector`
- [x] Neo4j (knowledge graphs, GraphRAG)
- [ ] Qdrant
- [x] Neo4j
- [x] Qdrant
- [ ] Chroma
- [ ] Weaviate

- [ ] Milvus

## Development

Expand All @@ -172,17 +79,22 @@ python -m pip install -e ".[test]"
```bash
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

Pull requests are welcome. Please include tests for behavior changes and keep examples runnable in the `usage/` notebooks when applicable.
Pull requests are welcome. Please include tests for behavior changes and keep examples runnable in `usage/` notebooks when applicable.

## License

Expand Down
4 changes: 4 additions & 0 deletions docker_db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
MSSQLDB,
OpenSearchConfig,
OpenSearchDB,
QdrantConfig,
QdrantDB,
RedisConfig,
RedisDB,
MySQLConfig,
Expand Down Expand Up @@ -37,6 +39,8 @@
"Neo4jConfig",
"OpenSearchDB",
"OpenSearchConfig",
"QdrantDB",
"QdrantConfig",
"RedisDB",
"RedisConfig",
]
3 changes: 3 additions & 0 deletions docker_db/dbs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from docker_db.dbs.neo4j_db import Neo4jDB, Neo4jConfig
from docker_db.dbs.redis_db import RedisDB, RedisConfig
from docker_db.dbs.opensearch_db import OpenSearchDB, OpenSearchConfig
from docker_db.dbs.qdrant_db import QdrantDB, QdrantConfig

__all__ = [
"MongoDB",
Expand All @@ -26,4 +27,6 @@
"RedisConfig",
"OpenSearchDB",
"OpenSearchConfig",
"QdrantDB",
"QdrantConfig",
]
Loading