PostgreSQL database tools including DDL migration management and connection pooling
Project description
The37Lab Database Tools
A collection of PostgreSQL database utilities for Python, including DDL migration management and connection pooling.
Packages
This package contains two main modules:
ddl_manager
A PostgreSQL DDL migration management tool that tracks schema changes using APPLY/REVERT migration files. Provides both a CLI interface and programmatic API.
Features:
- File-based migration system using
.ddlfiles - Automatic validation of APPLY/REVERT file pairs
- Migration tracking in database
- Rollback support
- CLI and programmatic interfaces
See ddl_manager documentation for detailed usage.
postgres_pool
PostgreSQL connection pooling and database utilities with convenient abstractions for common database operations.
Features:
- Thread-safe connection pooling
- Database conversion utilities (
DBConversionclass) - JSON column support
- Tag management helpers
- Post-insert hooks
Installation
From Source (Development)
pip install -e .
Regular Install
pip install .
Dependencies
- Python 3.7+
psycopg2-binary>=2.9.0
Quick Start
DDL Manager
from ddl_manager import DDLManager
manager = DDLManager(
dsn="postgresql://user:password@host:port/database",
ddl_directory="path/to/ddl/files"
)
# Check status
applied, unapplied = manager.status()
# Apply migrations
manager.update()
CLI Usage:
Set environment variables:
export POSTGRES_DSN="postgresql://user:password@host:port/database"
export DDL_DIRECTORY="path/to/ddl/files"
Then run:
ddl_manager status
ddl_manager update
ddl_manager log --json
Or use as a module:
python -m ddl_manager status
Postgres Pool
from postgres_pool import init_pool, get_connection, get_cursor, DBConversion
# Initialize the connection pool with DSN
init_pool("postgresql://user:password@host:port/database")
# Use connection pool
with get_connection() as conn:
with get_cursor(conn) as cur:
cur.execute("SELECT * FROM users")
results = cur.fetchall()
# Use DBConversion for table operations
conv = DBConversion(
table="users",
cols=["id", "name", "email"],
convs={},
bools=[],
autos=["id"]
)
with get_cursor() as cur:
user = conv.select_id(cur, 1)
new_user = conv.insert(cur, {"name": "John", "email": "john@example.com"})
Environment Variables
DDL Manager
POSTGRES_DSN: PostgreSQL connection stringDDL_DIRECTORY: Path to directory containing DDL migration files
Postgres Pool
The connection pool must be initialized explicitly by calling init_pool(dsn) before use. No environment variables are required.
License
MIT
Development
Install development dependencies:
pip install -e ".[dev]"
Project details
Release history Release notifications | RSS feed
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 the37lab_database_tools-0.1.1768749078.tar.gz.
File metadata
- Download URL: the37lab_database_tools-0.1.1768749078.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c4869670a6acbe5400fe50931a65b6fcf204d23212f2872309f1a690e1952bf
|
|
| MD5 |
7b32359146ba4181fe30ec1d70bd69bb
|
|
| BLAKE2b-256 |
5052f137c62b58acb2725e90cf0eaa11a0e62738907495e26351e1cad374f098
|
File details
Details for the file the37lab_database_tools-0.1.1768749078-py3-none-any.whl.
File metadata
- Download URL: the37lab_database_tools-0.1.1768749078-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30436ff74eb0ff58387a6d5df67aeef4e10f65f79ae562b0de5418c90f46c8db
|
|
| MD5 |
e0034c3802ae918223b7d5981d833100
|
|
| BLAKE2b-256 |
03539a701c2adf873df3b78e0740223bb8bf1c3c40bafb6aa1829d239a62d9ed
|