Python API¶
Quick Start¶
from dbcreds import get_connection, get_engine
# Get a connection
with get_connection("dev") as conn:
cursor = conn.cursor()
cursor.execute("SELECT 1")
# Get SQLAlchemy engine
engine = get_engine("dev")
Shortcut Functions¶
dbcreds.utils.shortcuts
¶
Convenience functions for common dbcreds operations.
This module provides simple shortcuts for the most common use cases, making it easy to get started with dbcreds.
Classes¶
Functions¶
get_async_engine(environment: str = 'default', **kwargs) -> AsyncEngine
async
¶
Get an async SQLAlchemy engine for an environment.
Args: environment: Environment name (default: "default") **kwargs: Additional engine parameters
Returns: SQLAlchemy AsyncEngine object
Examples: >>> engine = await get_async_engine("dev") >>> async with engine.connect() as conn: ... result = await conn.execute("SELECT 1")
Source code in dbcreds\utils\shortcuts.py
get_connection(environment: str = 'default', **kwargs)
¶
Get a database connection for an environment.
Args: environment: Environment name (default: "default") **kwargs: Additional connection parameters
Yields: Database connection object
Examples: >>> with get_connection("dev") as conn: ... cursor = conn.cursor() ... cursor.execute("SELECT 1")
Source code in dbcreds\utils\shortcuts.py
get_connection_string(environment: str = 'default', include_password: bool = True) -> str
¶
Get a database connection string for an environment.
Args: environment: Environment name (default: "default") include_password: Whether to include password in the string
Returns: Database connection URI
Examples: >>> uri = get_connection_string("dev") >>> print(uri) 'postgresql://user:pass@localhost:5432/mydb'
Source code in dbcreds\utils\shortcuts.py
get_credentials(environment: str = 'default') -> DatabaseCredentials
¶
Get database credentials for an environment.
Args: environment: Environment name (default: "default")
Returns: DatabaseCredentials object
Examples: >>> creds = get_credentials("dev") >>> print(f"Connecting to {creds.host}:{creds.port}")
Source code in dbcreds\utils\shortcuts.py
get_engine(environment: str = 'default', **kwargs) -> Engine
¶
Get a SQLAlchemy engine for an environment.
Args: environment: Environment name (default: "default") **kwargs: Additional engine parameters
Returns: SQLAlchemy Engine object
Examples: >>> engine = get_engine("dev") >>> with engine.connect() as conn: ... result = conn.execute("SELECT 1")
Source code in dbcreds\utils\shortcuts.py
Core Classes¶
See API Reference for detailed class documentation.