PostgreSQL DataPulse connector using SQLAlchemy
Project description
metronome-pulse-postgres-sqlalchemy
Flexible PostgreSQL DataPulse connector using SQLAlchemy with full ORM support.
🚀 Standalone Usage
This package provides a flexible, ORM-capable PostgreSQL connector that can be used independently of the DataMetronome project. Built on SQLAlchemy for maximum flexibility and ORM features.
Installation
pip install metronome-pulse-postgres-sqlalchemy
Quick Start
import asyncio
from metronome_pulse_postgres_sqlalchemy import PostgresSQLAlchemyPulse
async def main():
# Configure your PostgreSQL connection
credentials = {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "your_password",
"database": "your_database"
}
# Optional engine configuration
engine_config = {
"pool_size": 10,
"max_overflow": 20,
"pool_pre_ping": True,
"echo": False
}
# Use as async context manager (recommended)
async with PostgresSQLAlchemyPulse(credentials, engine_config) as pulse:
# Query data with SQL string
results = await pulse.query("SELECT * FROM users WHERE active = true")
print(f"Found {len(results)} active users")
# Query with structured configuration
query_config = {
"sql": "SELECT * FROM users WHERE age > :min_age AND city = :city",
"params": {"min_age": 18, "city": "New York"}
}
results = await pulse.query(query_config)
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 = PostgresSQLAlchemyPulse(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
- Full SQLAlchemy Support: Access to all SQLAlchemy features and ORM capabilities
- Flexible Query Interface: Support for both SQL strings and structured query configs
- Connection Pooling: Configurable pool with automatic management
- Async-First: Full async/await support with SQLAlchemy async engine
- Type Safety: Modern Python type hints
- Table Metadata: Built-in table inspection capabilities
- Transaction Support: Full transaction management
🔧 Configuration Options
Connection Parameters
host: Database host (default: localhost)port: Database port (default: 5432)user: Database usernamepassword: Database passworddatabase: Database name
Engine Configuration
pool_size: Pool size (default: 10)max_overflow: Maximum overflow connections (default: 20)pool_pre_ping: Pre-ping connections (default: True)pool_recycle: Connection recycle time (default: 3600)echo: SQL logging (default: False)
📖 API Reference
Core Methods
connect(): Initialize SQLAlchemy engineclose(): Close engine and release resourcesquery(query_config): Execute query (supports string or dict)write(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 detailed table metadatais_connected: Check connection statusengine: Access to SQLAlchemy enginesession_maker: Access to session maker
🔗 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_sqlalchemy-0.1.0.tar.gz.
File metadata
- Download URL: metronome_pulse_postgres_sqlalchemy-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63959f6f5c8015cce3cf14eaa71da364e0e87cb54ddfbed5439b15d700d4c547
|
|
| MD5 |
b1884c0cae9a77d18dc6a053dd9fa40d
|
|
| BLAKE2b-256 |
bc98ca47f9666db0647135732c6d0fc0b4df53e1561cadb73d5550597001fea4
|
File details
Details for the file metronome_pulse_postgres_sqlalchemy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: metronome_pulse_postgres_sqlalchemy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 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 |
4b7fa4ac80e7631d1acc80764b5ebcfdd44c5e2b75ebac19780be403518cb9c1
|
|
| MD5 |
59a38e1f4a5f5afcd4707777b7276e21
|
|
| BLAKE2b-256 |
4d3c412bc0e5c2f58aafe088cedfe2dcffc2cd1cde788a3455633a64c6556a91
|