pgmonkey

One config file, every PostgreSQL connection type. Sync, async, pooled, and async-pooled — all from a single YAML.

$ pip install pgmonkey
Read the Docs Quick Reference

One Config, Four Connection Types

Write your connection settings once. Choose the connection type at call time — or let the config default handle it.

from pgmonkey import PGConnectionManager

manager = PGConnectionManager()

# Same config file, different connection types
conn = manager.get_database_connection('config.yaml', 'normal')
conn = manager.get_database_connection('config.yaml', 'pool')
conn = await manager.get_database_connection('config.yaml', 'async')
conn = await manager.get_database_connection('config.yaml', 'async_pool')

What pgmonkey Does

Unified Configuration

Define connection settings, pool sizes, async timeouts, and SSL in a single YAML file. No more juggling separate configs per connection type.

Connection Pooling

Built-in sync and async connection pooling via psycopg_pool. Configure pool sizes, idle timeouts, max lifetimes, checkout timeouts, and health checks.

Async Support

First-class async connections and async pooling powered by psycopg3. Async settings are applied via SQL SET commands automatically.

SSL & Certificate Auth

Full support for SSL modes from disable to verify-full, plus client certificate authentication for enterprise environments.

CLI Tools

Create config templates, test connections, generate Python code (using pgmonkey or native psycopg), get server config recommendations, and audit live server settings — all from the command line.

Import & Export

Bulk import CSV data into PostgreSQL tables and export query results to CSV, with auto-generated config templates for column mapping.

Quick Start

Up and running in three steps.

1

Install

pip install pgmonkey

2

Create a config file

pgmonkey pgconfig create --type pg --filepath config.yaml

Edit the generated YAML with your database credentials.

3

Test your connection

pgmonkey pgconfig test --connconfig config.yaml --connection-type normal

Try pool, async, or async_pool to test other types.

Compatibility

pgmonkey works with a wide range of Python and dependency versions.

Python

3.10 – 3.13

psycopg

≥ 3.1.20

psycopg3 with binary support

psycopg_pool

≥ 3.1.9

Sync & async pooling

PyYAML

≥ 6.0.2

YAML configuration parsing