Skip to main content

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 .ddl files
  • 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 (DBConversion class)
  • 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 string
  • DDL_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

the37lab_database_tools-0.1.1769097189.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file the37lab_database_tools-0.1.1769097189.tar.gz.

File metadata

File hashes

Hashes for the37lab_database_tools-0.1.1769097189.tar.gz
Algorithm Hash digest
SHA256 53d287afa1556913cebcc609dac96de65dabd5f1afffd1c83351584b22660e03
MD5 884655b29a3ee105eba4bbcaf825f942
BLAKE2b-256 373cf937c3485c5dd541f7cad1b8e08435f829b607126851e45052f06badbd53

See more details on using hashes here.

File details

Details for the file the37lab_database_tools-0.1.1769097189-py3-none-any.whl.

File metadata

File hashes

Hashes for the37lab_database_tools-0.1.1769097189-py3-none-any.whl
Algorithm Hash digest
SHA256 5f6f4d10c54959e3b9cec367587c7f92568193998811f9a1ccc12b48359036a3
MD5 eeeb8b5b7fafff71d50f2f529ecca8ed
BLAKE2b-256 8cda99ec9802c8877fad48b5fa7015740bb82a4d3a6aeb6d154a0cd09a0872c8

See more details on using hashes here.

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