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
Metadata
Release files for metapg 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| metapg-0.0.1.tar.gz | 16.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| metapg-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.4 kB
Release files / metapg-0.0.1.tar.gz
| Download URL | metapg-0.0.1.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eecb390de3525040c07789a495983fbaa488a820e46d375e120b383a56ab1295
|
|
BLAKE2b-256 checksum How to use checksums |
8415fd12b4f2d2755f90bdfc257dbb4d72815cccaed41b4cc5ca4cef50824102
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / metapg-0.0.1-py3-none-any.whl
| Download URL | metapg-0.0.1-py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb8ce1fdb9eeb6666979f9385c5ad2cb57b77f0f641129726f0431edc2e7f140
|
|
BLAKE2b-256 checksum How to use checksums |
c0e983fcaf74dadf24df75e7d5a7247abd55aae79c9a8c1619fc07c4c9084b3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for metapg 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.