Skip to main content

Enterprise infrastructure for containerized Python applications - configuration, logging, timeouts, database, metrics, and application framework

Project description

hyperi-pylib

Build Status Python Version License

Enterprise infrastructure for all HyperI Python projects — configuration, logging, metrics, database utilities, Kafka, caching, and CLI framework.

Features

Core modules — always installed (uv add hyperi-pylib):

Module Description Third-party deps
logging Structured JSON logging with automatic sensitive data masking loguru
config 8-layer cascade (CLI → ENV → .env → PostgreSQL → YAML → defaults), container-aware dynaconf, pyyaml, python-dotenv, mergedeep, tomli-w, dulwich
runtime Container/K8s/local environment detection with standard path resolution stdlib only
database Connection URL builders for PostgreSQL, Redis, and others stdlib only
cli DfeApp framework — subclass to get run/version/config-check for free typer
harness Timeout monitors and utility helpers stdlib only
version-check Startup check for new hyperi-pylib releases (skipped if httpx absent) httpx (lazy)

Optional modules — enabled by installing the matching extra:

Module Extra Third-party deps
http http httpx, stamina
metrics metrics prometheus-client, psutil
expression expression common-expression-language (CEL via Rust/PyO3)
cache cache cashews, msgpack, psycopg[binary,pool]
kafka kafka confluent-kafka, genson
opentelemetry opentelemetry opentelemetry SDK + OTLP + Prometheus exporters

Installation

Package naming: hyperi-pylib on PyPI, hyperi_pylib for Python imports.

# Core only (logging, config, runtime, database, cli, harness, version-check)
uv add hyperi-pylib

# With common extras
uv add "hyperi-pylib[http,metrics,kafka]"

# Full stack
uv add "hyperi-pylib[http,metrics,expression,cache,kafka,opentelemetry]"

Optional Extras

Extra Packages Size
http httpx + stamina ~1 MB
metrics prometheus-client + psutil ~1 MB
expression common-expression-language (CEL) ~6 MB
cache cashews + msgpack + psycopg[binary,pool] ~14 MB (psycopg C libs)
kafka confluent-kafka + genson ~11 MB (C libs)
opentelemetry OpenTelemetry SDK + exporters ~4 MB
presidio Presidio analyser + anonymiser ~500 MB (spaCy + ML models)
secrets All secrets backends (Vault + AWS + GCP + Azure)
secrets-vault OpenBao / HashiCorp Vault (uses http extra) convenience marker
secrets-aws AWS Secrets Manager via boto3 ~100 MB
secrets-gcp GCP Secret Manager ~80–100 MB
secrets-azure Azure Key Vault ~50 MB

Quick Start

Logging

from hyperi_pylib.logger import logger

logger.info("Service starting", version="1.0.0")
logger.error("DB connection failed", host="postgres", retry=3)

Auto-detects console vs container — structured JSON in containers, human-readable locally.

Configuration

from hyperi_pylib.config import settings

# Automatic cascade: CLI > ENV > .env > PostgreSQL > settings.yaml > defaults
host = settings.database.host
port = settings.api.port

ENV key mapping: settings.database.hostMYAPP_DATABASE_HOST

Database URLs

from hyperi_pylib import build_database_url

postgres = build_database_url("postgresql")  # reads POSTGRES_HOST, POSTGRES_PORT, etc.
redis = build_database_url("redis")          # reads REDIS_HOST, REDIS_PORT, etc.

Runtime Paths

from hyperi_pylib import get_runtime_paths

runtime = get_runtime_paths()
config = runtime.config_dir / "app.yaml"   # /config in K8s, ~/.config locally
data   = runtime.data_dir  / "state.db"   # /data in K8s, ~/.local/share locally

Metrics

from hyperi_pylib import create_metrics

metrics = create_metrics(namespace="myapp")
metrics.http_requests.inc()
metrics.active_users.set(42)
metrics.request_duration.observe(0.123)

Cache

from hyperi_pylib.cache import PostgresCache, generate_cache_key

cache = PostgresCache(dsn="postgresql://user:pass@host/db")
await cache.init()

key = generate_cache_key("analytics", "events", org_id="acme")
await cache.set(key, {"data": [...]}, ttl_seconds=300, namespace="analytics")
value = await cache.get(key)

await cache.close()

Kafka

from hyperi_pylib.kafka import KafkaClient, KafkaConsumer, KafkaProducer

DfeApp CLI Framework

Subclass DfeApp to get standard CLI lifecycle (run, version, config-check) with no boilerplate:

from hyperi_pylib.cli import DfeApp, VersionInfo

class MyService(DfeApp):
    name = "my-service"
    env_prefix = "MY_SVC"

    def version_info(self) -> VersionInfo:
        return VersionInfo(self.name, "1.0.0")

    async def run_service_async(self, config) -> None:
        ...

if __name__ == "__main__":
    MyService().cli()

Config always uses the Dynaconf cascade — no bespoke loading needed.

Development

make quality   # lint, type-check, security audit
make test      # run test suite
make build     # build wheel

License

FSL-1.1-ALv2 — See LICENSE

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

hyperi_pylib-2.24.3.tar.gz (177.5 kB view details)

Uploaded Source

Built Distribution

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

hyperi_pylib-2.24.3-py3-none-any.whl (216.2 kB view details)

Uploaded Python 3

File details

Details for the file hyperi_pylib-2.24.3.tar.gz.

File metadata

  • Download URL: hyperi_pylib-2.24.3.tar.gz
  • Upload date:
  • Size: 177.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hyperi_pylib-2.24.3.tar.gz
Algorithm Hash digest
SHA256 551e314c5e6712821c3a17688d5a294453c87254a0ab08b44c336eb605e20d80
MD5 10c3f9b623ab2800b48cc14635be6d41
BLAKE2b-256 4c47e8cf52c88e29b8a59621158fa2708afc2a5e99a89fc5e7a86f02d874772b

See more details on using hashes here.

File details

Details for the file hyperi_pylib-2.24.3-py3-none-any.whl.

File metadata

  • Download URL: hyperi_pylib-2.24.3-py3-none-any.whl
  • Upload date:
  • Size: 216.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hyperi_pylib-2.24.3-py3-none-any.whl
Algorithm Hash digest
SHA256 513c5cf25ffd05448e2c4f26abe475df6bc15b822e940d8d93f377421d06714c
MD5 e8e6bd113d0efa5d0a8169cd24889c3f
BLAKE2b-256 e5b8b822524c1bf4ea0fe60ceab7a6ff7d97a26351d1387f3a72bd112347c99f

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