Skip to main content

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 username
  • password: Database password
  • database: 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 pool
  • close(): Close connection pool
  • query(query_config): Execute SQL query
  • write(data, destination): Write data to table
  • execute(query, params): Execute non-query SQL
  • execute_many(query, params_list): Execute batch operations

Utility Methods

  • query_with_params(query, params): Parameterized queries
  • get_table_info(table_name): Get table metadata
  • is_connected: Check connection status
  • pool_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metronome_pulse_postgres_psycopg3-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file metronome_pulse_postgres_psycopg3-0.1.0.tar.gz.

File metadata

File hashes

Hashes for metronome_pulse_postgres_psycopg3-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0feb051c92de419bf726bdbc69f53a6ab81c1be1c07e4864102ae3a4c8d5dfae
MD5 4cca02dd031f15670a9ce39db37434c2
BLAKE2b-256 9db96c8387cad338e313d077a9e2d6fbbeb54e41f8c310d8fd4dce8a03e0eb39

See more details on using hashes here.

File details

Details for the file metronome_pulse_postgres_psycopg3-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for metronome_pulse_postgres_psycopg3-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f61d90ab95d0c6ae0ff8e7ce98e26891e9687b3edab7a318b8811ec0cc04ceeb
MD5 bae533ac500a2db7ae3a94f09592bd02
BLAKE2b-256 9d5c3b9be8970d5bd5d0e78fdc697f1cd4b4aff969ff937cbea02809264149bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page