Internal Partenamut library for PostgreSQL access using Psycopg 3
Project description
aa-psycopg
Internal Partenamut library for PostgreSQL access using Psycopg 3.
Provides a simple and efficient interface for interacting with PostgreSQL using:
- A direct connection (
PostgreSQLConnection) - A connection pool (
PostgreSQLPool)
Supports query execution (SELECT, INSERT, UPDATE, DELETE), transactions, schema caching, and query runtime statistics.
Installation
pip install aa-psycopg
Requires Python 3.11+ and PostgreSQL driver psycopg3.
Features
- Easy-to-use wrapper for psycopg3.
- Connection pooling via psycopg_pool.
- Automatic query runtime tracking.
- Safe connection string handling (masks passwords in logs).
- Schema caching for executed queries.
API overview
ping(retries=0, timeout=60, query_name="ping") -> bool
Test database connectivity.read(query, params=None, query_name=None) -> list[dict]
Execute a SELECT query.write(query, params=None, returning=False, query_name=None) -> list[dict] | None
Execute INSERT/UPDATE/DELETE (optionally returning results).execute_transaction(queries_params, query_name=None)
Run multiple queries inside a transaction.get_stats() -> dict
Retrieve runtime stats (execution time & call count per query).get_schema(query) -> list[psycopg.Column]
Get schema for a previously executed query.
Usage
Direct Connection
from aa_psycopg.connection import PostgreSQLConnection
with PostgreSQLConnection(
user="myuser",
password="mypassword",
host="localhost",
port=5432,
db="mydatabase"
) as client:
# Check if database is alive
if client.ping():
print("Database reachable!")
# Read data
rows = client.read("SELECT * FROM my_table", query_name="fetch_all")
print(rows)
# Write data
client.write(
"INSERT INTO my_table (name) VALUES (%(name)s)",
params={"name": "example"},
query_name="insert_row"
)
# Transaction
client.execute_transaction([
("INSERT INTO my_table (name) VALUES (%(name)s)", {"name": "row1"}),
("INSERT INTO my_table (name) VALUES (%(name)s)", {"name": "row2"}),
], query_name="bulk_insert")
# Query stats
print(client.get_stats())
Connection Pool
from aa_psycopg.pool import PostgreSQLPool
with PostgreSQLPool(
user="myuser",
password="mypassword",
host="localhost",
port=5432,
db="mydatabase",
min_size=1,
max_size=5
) as client:
# Check connectivity
client.ping()
# Fetch results
results = client.read("SELECT * FROM users WHERE active = true", query_name="active_users")
print(results)
# Insert with RETURNING
new_ids = client.write(
"INSERT INTO users (name) VALUES (%(name)s) RETURNING id",
params={"name": "Alice"},
returning=True,
query_name="insert_user"
)
print(new_ids)
# Bulk transaction
client.execute_transaction([
("UPDATE users SET active=false WHERE id=%(id)s", {"id": 1}),
("DELETE FROM users WHERE active=false", None),
], query_name="cleanup")
# Stats
print(client.get_stats())
Requirements
- Python 3.11+
- psycopg 3
- psycopg_pool
License
Internal use at Partenamut. Not intended for public distribution.
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 aa_psycopg-0.1.1.tar.gz.
File metadata
- Download URL: aa_psycopg-0.1.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e9fc62cf58f366924cd013b4273b7f843c8a4a3a3d32f8eb6271feb3604c2e6
|
|
| MD5 |
614325c492d92d330a3c5bd4c7ff40e5
|
|
| BLAKE2b-256 |
df62b751e94361ae52a82bd7a054beff1230984b88dde3b168d58f7cf1956564
|
File details
Details for the file aa_psycopg-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aa_psycopg-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59515b0a1601cef25c76a9d70044cab5924e3444bc2f2d6806732761a5a1dc9d
|
|
| MD5 |
129f78db4e522638bcaf5e0e54a0e8f5
|
|
| BLAKE2b-256 |
22365f63875b1ec919b5f7308a02f5c9f80d888dffc7477348c1a1870397033d
|