Skip to main content

Common utilities and FIPS-compliant cryptography for EmpowerNow packages

Project description

EmpowerNow Common SDK

PyPI CI

The EmpowerNow Common SDK provides authentication helpers, configuration management and utilities shared across EmpowerNow micro-services and platform integrations.

pip install "empowernow-common[fastapi]"

Quick-start

Async OAuth

from empowernow_common import async_oauth

cfg = {
    "client_id": "svc",
    "client_secret": "***",
    "token_url": "https://auth.empowernow.io/oauth/token",
    "authorization_url": "https://auth.empowernow.io/oauth/authorize",
}

async with async_oauth(**cfg) as oauth:
    token = await oauth.get_token()
    print(token.access_token)

FastAPI integration

from empowernow_common.fastapi import build_auth_dependency, init
from empowernow_common.settings import EmpowerNowSettings

settings = EmpowerNowSettings.from_env()  # or from_yaml()
init(settings=settings)

app = FastAPI()
app.dependency_overrides[build_auth_dependency()] = lambda: {"sub": "demo"}

See the docs/ folder for full guides. For upgrading to the AuthZEN Draft‑04 API, read docs/authzen_migration_draft04.md.

Optional extras

  • redis – distributed caches
  • kafka – log sink and event bus
  • metrics – Prometheus client
  • fastapi – web-framework helpers

Development

git clone https://github.com/empowernow/empowernow-common.git
cd empowernow-common
pip install -e .[dev]
pre-commit install
pytest -q

Secret Loader

empowernow_common provides a zero-dependency helper to resolve secrets delivered as Docker/K8s secrets or environment variables.

from empowernow_common import load_secret

# read from /run/secrets/primary/db-password
password = load_secret("file:primary:db-password")

# read environment variable MY_API_KEY (dev only)
api_key = load_secret("env:MY_API_KEY")

Pointer grammar:

  • file:<instance>:<id> – Reads <mount>/<instance>/<id> where mount defaults to /run/secrets or $FILE_MOUNT_PATH.
  • filex:<instance>:<id> – Same as file: but returns rich structures: JSON objects or line-based key=value pairs are parsed into a dict.
  • env:<VAR> – Returns the environment variable value.

Providers are pluggable:

from empowernow_common.secret_loader import register_provider

def vault_provider(path: str):
    ...
register_provider("vault", vault_provider)

Audit: pass audit_hook to load_secret to stream access events to Kafka/SIEM.

Shared Kafka Producer

The SDK includes an optional, zero-config Kafka helper so services can publish structured events without re-implementing connection logic.

from empowernow_common.kafka.platform_producer import publish_structured
from empowernow_common.kafka.topics import TOPICS

await publish_structured(
    "pdp.decisions",                     # event_type
    {"decision": "allow", "id": "123"},  # payload (JSON-serialisable)
    topic=TOPICS["pdp.decisions"],       # canonical topic
    key="123"                            # partition key (optional)
)

Key points:

  • Optional dependency – install with pip install empowernow-common[kafka].
  • Reads KAFKA_BOOTSTRAP_SERVERS, SERVICE_NAME, KAFKA_ENABLED env vars.
  • No-ops automatically if Kafka is disabled or aiokafka isn’t installed.
  • empowernow_common.kafka.topics provides a central map so topic names evolve without touching every service.
  • Secret-access audit hook already uses the shared producer; you can register additional hooks via:
    from empowernow_common.kafka.platform_producer import publish
    

See kafka/platform_producer.py for full documentation and kafka/topics.py for the canonical topic list.


© EmpowerNow, Inc. MIT 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

empowernow_common-2.3.13.tar.gz (119.2 kB view details)

Uploaded Source

Built Distribution

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

empowernow_common-2.3.13-py3-none-any.whl (136.6 kB view details)

Uploaded Python 3

File details

Details for the file empowernow_common-2.3.13.tar.gz.

File metadata

  • Download URL: empowernow_common-2.3.13.tar.gz
  • Upload date:
  • Size: 119.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for empowernow_common-2.3.13.tar.gz
Algorithm Hash digest
SHA256 94f4ec537dba460b362b8bf79c82f5e30e48810ddbef22ee2ff96591451364ba
MD5 1809b4d377848d840d649b24298af084
BLAKE2b-256 7bec4d91c7ea4a5c2a7de599bf34eb1687b618390d71c58c26f43b23279e8b85

See more details on using hashes here.

File details

Details for the file empowernow_common-2.3.13-py3-none-any.whl.

File metadata

File hashes

Hashes for empowernow_common-2.3.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ddda5324c79499d9b5c62a86c4bde47d74d32d80111ae04f9cfb227a0a6b88f0
MD5 8e373c3564674ddca02c777e7a403856
BLAKE2b-256 405de137c171699438b85ab32e312213ea50f05ccb791b90c50f48894a855061

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