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 Python infrastructure for HyperI projects.

hyperi-pylib provides metrics, logging, and infrastructure utilities for all HyperI Python projects.

Note: The previous Application.* framework (API/Daemon/CLI/Oneshot/MCP) was removed in 2.13.x. Use the individual modules (logger, metrics, config, kafka, http, cache) directly or restore the legacy package from history if you need it.

Features

  • Logging: Structured JSON logging with sensitive data masking
  • PII Anonymization: ML-based anonymization with Presidio integration
  • Database Utilities: ClickHouse, PostgreSQL, MySQL, Redis connection helpers
  • Configuration: Multi-layer cascade with environment variable support
  • Runtime: Application metadata and environment detection
  • Metrics: Prometheus and OpenTelemetry backends
  • Kafka: Complete Kafka client library with admin, consumer, producer, and schema analysis
  • Harness: Smart timeout monitors and container registry utilities
  • CLI: Typer-based CLI utilities

Installation

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

pyproject.toml Configuration (Recommended)

For projects using uv with both JFrog (hyperi-pylib) and PyPI packages, add this to your pyproject.toml:

[tool.uv]
index-strategy = "unsafe-best-match"

[[tool.uv.index]]
name = "hypersec-jfrog"
url = "https://hypersec.jfrog.io/artifactory/api/pypi/hypersec-pypi/simple"
explicit = true

[[tool.uv.index]]
name = "pypi"
url = "https://pypi.org/simple"
default = true

[tool.uv.sources]
hyperi-pylib = { index = "hypersec-jfrog" }

Key settings:

  • index-strategy = "unsafe-best-match" - Allows mixing packages from JFrog and PyPI
  • explicit = true on JFrog - Only use JFrog for explicitly mapped packages
  • default = true on PyPI - Use PyPI for everything else
  • [tool.uv.sources] - Explicitly route hyperi-pylib to JFrog

Then set credentials via environment variables and install:

# uv looks for UV_INDEX_{NAME}_USERNAME and UV_INDEX_{NAME}_PASSWORD
# where {NAME} is the uppercase index name with non-alphanumeric chars replaced by underscores
export UV_INDEX_HYPERSEC_JFROG_USERNAME="your-email@hypersec.io"
export UV_INDEX_HYPERSEC_JFROG_PASSWORD="your-jfrog-api-key"

uv sync

Command-Line Installation

# Set credentials (same env vars work for CLI)
export UV_INDEX_HYPERSEC_JFROG_USERNAME="your-email@hypersec.io"
export UV_INDEX_HYPERSEC_JFROG_PASSWORD="your-jfrog-api-key"

# Using uv with extra-index-url
uv pip install hyperi-pylib \
  --extra-index-url https://hypersec.jfrog.io/artifactory/api/pypi/hypersec-pypi/simple

# With optional dependencies
uv pip install hyperi-pylib[presidio,opentelemetry] \
  --extra-index-url https://hypersec.jfrog.io/artifactory/api/pypi/hypersec-pypi/simple

Optional Dependencies

  • hyperi-pylib[presidio] - PII anonymization
  • hyperi-pylib[opentelemetry] - OpenTelemetry metrics
  • hyperi-pylib[api] - FastAPI support
  • hyperi-pylib[metrics] - Prometheus metrics

Quick Start

Logging

from hyperi_pylib import logger

logger.setup(app_name="my-app", json_output=True)
logger.info("Application started")
logger.error("Something went wrong", exc_info=True)

Configuration

from hyperi_pylib import config

# Initialize configuration
config.setup(app_name="my-app")

# Access settings
settings = config.get_settings()
db_config = config.get_database_config()

Database Connections

from hyperi_pylib import database

# Get database URLs from environment
postgres_url = database.get_postgresql_url()
redis_url = database.get_redis_url()

# Build custom connection URL
url = database.build_database_url(
    driver="postgresql",
    host="localhost",
    port=5432,
    database="mydb",
    username="user",
    password="pass"
)

Kafka

from hyperi_pylib.kafka import KafkaClient

# Create client with configuration
client = KafkaClient.from_config(config_file="kafka.properties")

# Produce messages
await client.produce("my-topic", {"key": "value"})

# Consume messages
async for message in client.consume("my-topic", group_id="my-group"):
    process(message)

Metrics

from hyperi_pylib.metrics import create_metrics_backend

# Prometheus backend
metrics = create_metrics_backend("prometheus")
counter = metrics.counter("requests_total", "Total requests")
counter.inc()

Documentation

  • Metrics: docs/METRICS.md
  • Logging: docs/LOGGING.md
  • Anonymizer: docs/ANONYMIZER.md

Development

# Quality checks
ruff check src/ tests/
ruff format src/ tests/

# Tests
pytest tests/

# Build
uv build

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.1.tar.gz (176.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.1-py3-none-any.whl (213.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hyperi_pylib-2.24.1.tar.gz
Algorithm Hash digest
SHA256 481e78d684079c5f0ab72b9b7e9cb354fdf47861ee192bbe722b50437c456f48
MD5 5832675e2335a144d1495c871842028d
BLAKE2b-256 ccdf0aa8c2cefda3f342c39654d0361f226863396f38cc32a0423e30d4cfe95e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hyperi_pylib-2.24.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9bad02f60206b40c28da2adf841d516d34df2856449bd22da84f1699f4bf66ea
MD5 3eddd6253e847022f97e436873e1e032
BLAKE2b-256 74077f2faf6308f09421c70acf7d925e9e5f3c81578bc90c889b1190e0b738f6

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