Skip to main content

Corekit Python Library

Corekit-py is a comprehensive utility library ported from corekit-js, designed to facilitate building Python applications with standardized integrations for Azure services, databases, logging, and other common utilities.

Table of Contents

Features

  • App Configuration: Integration with Azure App Configuration and Key Vault for centralized settings.
  • Azure Blob Storage: Asynchronous client for efficient blob operations.
  • Azure Event Hubs: Robust async producers and consumers with automatic checkpointing using Azure Blob Storage.
  • ClickHouse: Client for high-performance querying and data streaming.
  • Cloudinary: Service for image and video upload, transformation, and management.
  • Cosmos DB: Repository pattern implementation with caching, soft-deletes, and async wrapper around the synchronous SDK.
  • HTTP: httpx-based wrapper for resilient HTTP requests with default timeouts and pooling.
  • Logger: Structured logging supporting console, Slack notifications, and OpenTelemetry (OTLP) export.
  • Middleware: ASGI middleware for Firebase Authentication, Rate Limiting, and Request Sanitization (compatible with Starlette/FastAPI).
  • PostgreSQL: Asynchronous client and repository pattern using asyncpg.
  • Queue: Azure Storage Queue management including poison message handling.
  • Redis Cache: Redis client and caching utilities supporting context-based keys and JSON serialization.
  • Utils: Extensive collection of helpers for date/time, geospatial calculations, encryption, retry logic, distributed locking, and more.

Installation

pip install corekit-py

Library Structure

The library is organized into modular services within src/corekit:

src/corekit/
├── app_config/        # Azure App Configuration & Key Vault
├── azure_blob/        # Azure Blob Storage Client
├── azure_event_hubs/  # Event Hubs Producer & Consumer
├── clickhouse/        # ClickHouse Client
├── cloudinary/        # Cloudinary Service
├── cosmos/            # Cosmos DB Repository & Client
├── http/              # HTTP Client Wrapper
├── logger/            # Structured & OTLP Logger
├── middleware/        # ASGI Middleware (Auth, RateLimit)
├── postgres/          # PostgreSQL Async Client
├── queue/             # Azure Queue Storage
├── redis_cache/       # Redis Client & Cache
└── utils/             # Shared Utilities (Date, Geo, etc.)

Dependency Mapping

Corekit-py relies on several external packages. Here is how they map to the internal modules:

Corekit Module Primary Dependencies Description
app_config azure-appconfiguration, azure-keyvault-secrets, azure-identity Fetches config and secrets.
azure_blob azure-storage-blob Blob storage operations.
azure_event_hubs azure-eventhub, azure-eventhub-checkpointstoreblob-aio Event ingestion and processing.
cosmos azure-cosmos, cachetools Database operations and in-memory caching.
clickhouse clickhouse-connect ClickHouse database interaction.
cloudinary cloudinary, httpx Media management.
http httpx Async HTTP requests.
logger opentelemetry-api, opentelemetry-sdk, opentelemetry-exporter-otlp-proto-http, httpx Telemetry and Slack alerts.
middleware starlette, firebase-admin Web framework integration and Auth.
postgres asyncpg Async PostgreSQL driver.
queue azure-storage-queue Queue messaging.
redis_cache redis Async Redis client.
utils cryptography, cachetools Encryption and locking mechanisms.
Global pydantic, pydantic-settings Data validation and settings management.

Usage Guide

App Configuration

Load configuration from Azure App Config and Key Vault on startup.

from corekit.app_config import AppConfigClient

client = AppConfigClient(connection_string="Endpoint=...")
await client.load_configurations()

# Access a configuration value
feature_flag = client.get("my-feature-flag")
secret_value = client.get("my-secret")

Azure Blob

Upload and manage blobs asynchronously.

from corekit.azure_blob import AzureBlobClient

client = AzureBlobClient(connection_string="...")
await client.upload_blob(
    container_name="my-container",
    blob_name="file.txt",
    data="Hello World"
)

Azure Event Hubs

Consume events with checkpointing.

from corekit.azure_event_hubs import AzureEventsHubsConsumer

async def process_events(events, partition_context):
    for event in events:
        print(f"Received: {event.body_as_str()}")
        await partition_context.update_checkpoint(event)

consumer = AzureEventsHubsConsumer(
    event_hub_namespace_connection_string="...",
    event_hub_name="my-hub",
    consumer_group="$Default",
    storage_connection_string="...", # For checkpointing
    block_container_name="checkpoints"
)

await consumer.subscribe(process_events)

Cosmos DB

Use the repository pattern for standardized database access.

from corekit.cosmos import CosmosClientService, CosmosRepo

# Setup
service = CosmosClientService(endpoint="...", key="...")
client = service.get_cosmos_client()
container = client.get_database_client("my-db").get_container_client("users")

# Repository
repo = CosmosRepo(container, partition_key="userId")

# Operations
user = await repo.get_item("user-123")
await repo.upsert_item({"id": "user-123", "userId": "user-123", "name": "Aryan"})

Logger

Initialize a structured logger with OTLP export support.

from corekit.logger import LoggerService

service = LoggerService(
    service_name="my-service",
    log_level="INFO",
    enable_console=True
)
logger = service.get_logger()

logger.info("Service started", {"env": "production"})

Middleware

Add middleware to your FastAPI or Starlette app.

from starlette.applications import Starlette
from corekit.middleware import RateLimiterMiddleware

app = Starlette()
app.add_middleware(RateLimiterMiddleware, limit=100, window=60)

PostgreSQL

High-performance async PostgreSQL access.

from corekit.postgres import create_pg_pool, PgRepo

# Initialize connection pool
pool = await create_pg_pool(dsn="postgres://user:pass@host/db")

# Use Generic Repository
repo = PgRepo(pool, "users")
user = await repo.get_item(1)

# Custom Query
rows = await repo.run_query("SELECT * FROM users WHERE active = $1", True)

Redis Cache

from corekit.redis_cache import RedisClientService, RedisCache

client = RedisClientService(host="localhost", port=6379)
cache = RedisCache(client.get_client())

await cache.set("key", {"foo": "bar"}, expiry_in_seconds=60)
value = await cache.get("key")

Utils

Access standardized utility functions.

from corekit.utils import sleep, get_distance_from_lat_lon_in_km, encrypt_key

# Async Sleep
await sleep(1000) # 1 second

# Geo
dist = get_distance_from_lat_lon_in_km(40.7128, -74.0060, 34.0522, -118.2437)

# Encryption
encrypted = encrypt_key("my-secret", security_key="master-key")

Configuration

Most modules can be configured via constructor arguments. For seamless integration, it is recommended to use pydantic-settings or environment variables to inject credentials securely.

Common Environment Variables used implicitly by some underlying SDKs:

  • AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID (for Azure Identity)
  • OTEL_EXPORTER_OTLP_ENDPOINT (for OpenTelemetry)

Contributing

  1. Clone the repository.
  2. Create settings for your local dependencies (Redis, Postgres, etc.) or use mocks.
  3. Install dependencies: pip install -e ".[dev]"
  4. Run tests with pytest.

License

MIT

Metadata

Release files for corekit-py 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for corekit-py 0.1.0
File Size Uploaded Provenance Actions
corekit_py-0.1.0.tar.gz 46.2 kB Without provenance Details for corekit_py-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for corekit-py 0.1.0
File Interpreter ABI Platform Actions
corekit_py-0.1.0-py3-none-any.whl Python 3 none any Details for corekit_py-0.1.0-py3-none-any.whl

Total release size: 99.5 kB

Release files / corekit_py-0.1.0.tar.gz

Download URL corekit_py-0.1.0.tar.gz
Size 46.2 kB
Tags Source
SHA-256 checksum
How to use checksums
022c2862729e565657f0772d5f2ddb57242813b3664e7298e41106f72f69c6dd
BLAKE2b-256 checksum
How to use checksums
e80e84bc318a071e6d44553ceec2ae7e88dc9d215d55baa4e656e4f343f0d602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / corekit_py-0.1.0-py3-none-any.whl

Download URL corekit_py-0.1.0-py3-none-any.whl
Size 53.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9582049ab1875d88c139e37c8bfed488ad0acc7bdc33c9154548a67be719d668
BLAKE2b-256 checksum
How to use checksums
a1b3197f0ae2fc5fcf795a9d6890f5c501f5ecf9eae6b35f6470214b47bae978
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for corekit-py 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page