Skip to main content

PostgreSQL storage plugin for PyConfBox

Project description

PyConfBox PostgreSQL Plugin

PostgreSQL database storage backend for PyConfBox

This plugin provides PostgreSQL database storage backend for PyConfBox, enabling persistent configuration storage with advanced PostgreSQL features like JSONB support and full-text search.

한국어 문서: README_ko.md | English Documentation: README.md (current)

🚀 Installation

pip install pyconfbox-postgresql

📋 Requirements

  • Python 3.8+
  • pyconfbox >= 0.1.0
  • psycopg2-binary >= 2.9.0 or asyncpg >= 0.27.0

💡 Usage

Basic Usage

from pyconfbox_postgresql import PostgreSQLStorage
from pyconfbox import Config

# PostgreSQL storage configuration
postgresql_storage = PostgreSQLStorage(
    host='localhost',
    port=5432,
    user='postgres',
    password='password',
    database='config_db'
)

config = Config(default_storage=postgresql_storage)

# Store and retrieve configurations
config.set('app_name', 'MyApp')
config.set('debug', True)
config.set('max_connections', 100)

app_name = config.get('app_name')
debug_mode = config.get('debug')

Connection String Usage

from pyconfbox_postgresql import PostgreSQLStorage

# Using connection string
postgresql_storage = PostgreSQLStorage(
    connection_string='postgresql://user:password@localhost:5432/config_db'
)

config = Config(default_storage=postgresql_storage)

Advanced Configuration with JSONB

from pyconfbox_postgresql import PostgreSQLStorage

postgresql_storage = PostgreSQLStorage(
    host='localhost',
    port=5432,
    user='config_user',
    password='secure_password',
    database='app_config',
    table_name='configurations',  # Custom table name
    use_jsonb=True,  # Enable JSONB for complex data types
    pool_size=10,  # Connection pool size
    pool_timeout=30,  # Pool timeout in seconds
    ssl_mode='require',  # SSL mode
    application_name='PyConfBox'  # Application name for monitoring
)

config = Config(default_storage=postgresql_storage)

# Store complex data structures
config.set('database_config', {
    'host': 'db.example.com',
    'port': 5432,
    'connections': {
        'read': 5,
        'write': 2
    }
})

Async Support

from pyconfbox_postgresql import AsyncPostgreSQLStorage
from pyconfbox import Config
import asyncio

async def main():
    # Async PostgreSQL storage
    async_storage = AsyncPostgreSQLStorage(
        host='localhost',
        port=5432,
        user='postgres',
        password='password',
        database='config_db'
    )
    
    config = Config(default_storage=async_storage)
    
    # Async operations
    await config.aset('async_key', 'async_value')
    value = await config.aget('async_key')
    
    await async_storage.close()

asyncio.run(main())

🎯 Features

  • 🔄 Full CRUD Operations: Create, read, update, delete configurations
  • 📊 JSONB Support: Native JSON storage with indexing and querying
  • 🔒 Transaction Support: ACID-compliant transactions
  • ⚡ Connection Pooling: Efficient connection management
  • 🛡️ SSL Support: Secure connections with various SSL modes
  • 🔍 Full-text Search: Advanced search capabilities
  • ⚙️ Async Support: Asynchronous operations with asyncpg
  • 📈 Performance: Optimized queries and indexing strategies

🏗️ Database Schema

The plugin automatically creates the following table structure:

CREATE TABLE configurations (
    id SERIAL PRIMARY KEY,
    config_key VARCHAR(255) NOT NULL UNIQUE,
    config_value TEXT,
    config_json JSONB,  -- When use_jsonb=True
    data_type VARCHAR(50),
    scope VARCHAR(50),
    is_immutable BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT unique_config_key UNIQUE (config_key)
);

-- Indexes for performance
CREATE INDEX idx_config_key ON configurations (config_key);
CREATE INDEX idx_scope ON configurations (scope);
CREATE INDEX idx_config_json ON configurations USING GIN (config_json);  -- For JSONB

🔧 Configuration Options

Parameter Type Default Description
host str 'localhost' PostgreSQL server host
port int 5432 PostgreSQL server port
user str Required Database username
password str Required Database password
database str Required Database name
table_name str 'configurations' Table name for storing configs
connection_string str None Complete connection string
use_jsonb bool False Enable JSONB for complex data
pool_size int 5 Connection pool size
pool_timeout int 30 Pool timeout in seconds
ssl_mode str 'prefer' SSL mode (disable, allow, prefer, require)
application_name str 'PyConfBox' Application name for monitoring

🔍 Advanced Querying

from pyconfbox_postgresql import PostgreSQLStorage

# Enable JSONB for advanced querying
storage = PostgreSQLStorage(
    host='localhost',
    database='config_db',
    use_jsonb=True
)

config = Config(default_storage=storage)

# Store complex configuration
config.set('api_config', {
    'endpoints': {
        'users': '/api/v1/users',
        'orders': '/api/v1/orders'
    },
    'rate_limits': {
        'requests_per_minute': 1000,
        'burst_size': 100
    }
})

# Query using JSONB operators (PostgreSQL-specific)
# This would be implemented in custom storage methods

📖 Documentation

🔗 Related Packages

🤝 Contributing

Contributions are welcome! Please see our Contributing Guide for details.

📄 License

MIT License - See the LICENSE file for details.


Leverage PostgreSQL's power for your configurations! 🚀

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

pyconfbox_postgresql-0.1.2.tar.gz (63.3 kB view details)

Uploaded Source

Built Distribution

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

pyconfbox_postgresql-0.1.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pyconfbox_postgresql-0.1.2.tar.gz.

File metadata

  • Download URL: pyconfbox_postgresql-0.1.2.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyconfbox_postgresql-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b6445dedb7604c007b00d5c5bc5584ab2f99e079642980a9b2b14c1259b25eb4
MD5 aef199569acac2a7cb945117a0f803e5
BLAKE2b-256 03f970154f01fdcad3a803628edb5c1440b030c62c9db91d0b874850a92fed32

See more details on using hashes here.

File details

Details for the file pyconfbox_postgresql-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyconfbox_postgresql-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 113109f475d97616f3898c106638ba7327b7deb8cd8466f69ec85832b7b4e44f
MD5 5943f2fba686343f85a9032e29d43e66
BLAKE2b-256 62907531d9893f05ab88ec3f6d70ac5c5ef08e31fc5539323f08db053f94bf61

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