PostgreSQL DataPulse connector using psycopg3
Project description
metronome-pulse-postgres-psycopg3
Modern PostgreSQL DataPulse connector using psycopg3 with async support.
🚀 Standalone Usage
This package provides a modern, async-first PostgreSQL connector that can be used independently of the DataMetronome project. Built on psycopg3 for maximum compatibility and performance.
Installation
pip install metronome-pulse-postgres-psycopg3
Quick Start
import asyncio
from metronome_pulse_postgres_psycopg3 import PostgresPsycopg3Pulse
async def main():
# Configure your PostgreSQL connection
credentials = {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "your_password",
"database": "your_database"
}
# Optional pool configuration
pool_config = {
"min_size": 5,
"max_size": 20,
"timeout": 30,
"check": True
}
# Use as async context manager (recommended)
async with PostgresPsycopg3Pulse(credentials, pool_config) as pulse:
# Query data
results = await pulse.query("SELECT * FROM users WHERE active = true")
print(f"Found {len(results)} active users")
# Parameterized query
results = await pulse.query_with_params(
"SELECT * FROM users WHERE age > %s AND city = %s",
{"age": 18, "city": "New York"}
)
print(f"Found {len(results)} users in New York over 18")
# Write data
new_users = [
{"name": "Alice", "email": "alice@example.com", "age": 25},
{"name": "Bob", "email": "bob@example.com", "age": 30}
]
await pulse.write(new_users, "users")
print("Added new users")
# Get table information
table_info = await pulse.get_table_info("users")
print(f"Table structure: {table_info}")
# Run the example
asyncio.run(main())
Manual Lifecycle Management
async def manual_example():
pulse = PostgresPsycopg3Pulse(credentials)
try:
await pulse.connect()
# Your operations here
results = await pulse.query("SELECT COUNT(*) FROM users")
print(f"Total users: {results[0]['count']}")
finally:
await pulse.close()
📋 Features
- Modern psycopg3: Latest PostgreSQL driver with async support
- Connection Pooling: Configurable pool with automatic management
- Async-First: Full async/await support
- Type Safety: Modern Python type hints
- Flexible Queries: Support for parameterized queries
- Bulk Operations: Efficient batch inserts and updates
- Table Metadata: Built-in table inspection capabilities
🔧 Configuration Options
Connection Parameters
host: Database host (default: localhost)port: Database port (default: 5432)user: Database usernamepassword: Database passworddatabase: Database name
Pool Configuration
min_size: Minimum pool size (default: 1)max_size: Maximum pool size (default: 10)timeout: Connection timeout in seconds (default: 30)check: Validate connections (default: True)
📖 API Reference
Core Methods
connect(): Initialize connection poolclose(): Close connection poolquery(query_config): Execute SQL querywrite(data, destination): Write data to tableexecute(query, params): Execute non-query SQLexecute_many(query, params_list): Execute batch operations
Utility Methods
query_with_params(query, params): Parameterized queriesget_table_info(table_name): Get table metadatais_connected: Check connection statuspool_size: Get current pool size
🔗 Integration with DataMetronome
While this package is designed for standalone use, it's also a DataPulse connector for the DataMetronome ecosystem. It implements the standard DataPulse interfaces for consistent behavior.
📚 Documentation
📄 License
MIT License - see LICENSE file for details.
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 metronome_pulse_postgres_psycopg3-0.1.0.tar.gz.
File metadata
- Download URL: metronome_pulse_postgres_psycopg3-0.1.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0feb051c92de419bf726bdbc69f53a6ab81c1be1c07e4864102ae3a4c8d5dfae
|
|
| MD5 |
4cca02dd031f15670a9ce39db37434c2
|
|
| BLAKE2b-256 |
9db96c8387cad338e313d077a9e2d6fbbeb54e41f8c310d8fd4dce8a03e0eb39
|
File details
Details for the file metronome_pulse_postgres_psycopg3-0.1.0-py3-none-any.whl.
File metadata
- Download URL: metronome_pulse_postgres_psycopg3-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f61d90ab95d0c6ae0ff8e7ce98e26891e9687b3edab7a318b8811ec0cc04ceeb
|
|
| MD5 |
bae533ac500a2db7ae3a94f09592bd02
|
|
| BLAKE2b-256 |
9d5c3b9be8970d5bd5d0e78fdc697f1cd4b4aff969ff937cbea02809264149bb
|