Metapackage for PostgreSQL operations - pools, migrations, and CLI
Project description
metapg
Meta PostgreSQL pools and raw SQL migrations for multi-database applications
metapg is a metapackage that provides a unified interface for PostgreSQL operations through independently installable components.
Installation
Install Everything
pip install metapg[all]
Install Individual Components
# Connection pooling only
pip install metapg[pool]
# Migrations only
pip install metapg[migration]
# CLI tools only
pip install metapg[cli]
# Custom combination
pip install metapg[pool,migration]
Quick Start
import metapg
# 🎯 Smart cursor - works with both sync and async!
# Synchronous usage
with metapg.cursor() as cur:
cur.execute("SELECT * FROM users")
users = cur.fetchall()
# Asynchronous usage (same interface!)
async with metapg.cursor() as cur:
await cur.execute("SELECT * FROM users")
users = await cur.fetchall()
# Migrations
runner = metapg.migration.MigrationRunner()
await runner.apply_pending()
Components
metapg.pool - Connection Pooling
High-performance async and sync PostgreSQL connection pooling.
# Smart interface adapts to context
async with metapg.pool.cursor() as cur:
await cur.execute("SELECT * FROM users")
with metapg.pool.cursor() as cur: # Sync version
cur.execute("SELECT * FROM users")
metapg.migration - Schema Migrations
Raw SQL migrations with dependency tracking and rollback support.
runner = metapg.migration.MigrationRunner()
status = await runner.get_status()
await runner.apply_pending()
metapg.cli - Command Line Interface
Beautiful terminal interface for database operations.
metapg migration status
metapg migration apply
metapg pool init mydb --dsn postgresql://localhost/mydb
Features
- 🎯 Smart Cursor - Same interface works with both
with(sync) andasync with(async) - ⚡ Async-first - Built on psycopg3 with full async/await support
- 🔄 Sync Support - Full synchronous API when you don't need async
- 🎛️ Multi-database - Manage multiple PostgreSQL databases with named pools
- 📜 Raw SQL migrations - Simple, powerful migrations using plain SQL files
- 🧠 Context-aware - Smart connection reuse with contextvars
- ⚙️ Zero-config - Works out of the box with sensible defaults
- 🚀 Production-ready - Proper connection pooling, transactions, and error handling
- 💻 Rich CLI - Beautiful terminal interface for migration management
- 📦 Modular - Install only what you need
Package Architecture
metapg/ # Metapackage (this package)
├── metapg.pool # Connection pooling
├── metapg.migration # Schema migrations
└── metapg.cli # Command-line interface
Each component is independently installable and maintained, but they work seamlessly together through the metapackage interface.
Usage Patterns
Full Stack (All Components)
pip install metapg[all]
import metapg
# Connection pooling
async with metapg.cursor() as cur:
await cur.execute("SELECT * FROM users")
# Migrations
runner = metapg.migration.MigrationRunner()
await runner.apply_pending()
# CLI access
metapg.cli.app() # For programmatic CLI access
Minimal (Pool Only)
pip install metapg[pool]
import metapg
# Only pooling functionality available
async with metapg.cursor() as cur:
await cur.execute("SELECT * FROM users")
# migration and cli will be None
print(metapg.migration) # None
print(metapg.cli) # None
Migration Focus
pip install metapg[pool,migration]
import metapg
# Pooling + migrations available
async with metapg.cursor() as cur:
await cur.execute("SELECT * FROM users")
runner = metapg.migration.MigrationRunner()
await runner.apply_pending()
# CLI not available
print(metapg.cli) # None
Environment Variables
DATABASE_URL- Default database connection stringDATABASE_URL_{NAME}- Connection string for named database
Error Handling
The metapackage provides helpful error messages when components aren't installed:
import metapg
# If metapg.pool not installed
metapg.cursor() # ImportError: metapg.pool is required. Install with: pip install metapg.pool
License
MIT License - see LICENSE file for details.
Contributing
See CONTRIBUTING.md for development setup and contribution guidelines.
Individual Package Documentation
- metapg.pool - Connection pooling
- metapg.migration - Schema migrations
- metapg.cli - Command-line interface
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 metapg-0.0.1.tar.gz.
File metadata
- Download URL: metapg-0.0.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eecb390de3525040c07789a495983fbaa488a820e46d375e120b383a56ab1295
|
|
| MD5 |
ca2f6268ba16144a3cbc167c2e87e4e6
|
|
| BLAKE2b-256 |
8415fd12b4f2d2755f90bdfc257dbb4d72815cccaed41b4cc5ca4cef50824102
|
File details
Details for the file metapg-0.0.1-py3-none-any.whl.
File metadata
- Download URL: metapg-0.0.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb8ce1fdb9eeb6666979f9385c5ad2cb57b77f0f641129726f0431edc2e7f140
|
|
| MD5 |
13793e748f643e8f56161ae917388f70
|
|
| BLAKE2b-256 |
c0e983fcaf74dadf24df75e7d5a7247abd55aae79c9a8c1619fc07c4c9084b3c
|