Skip to main content

Consolidated domain packages: typed errors, security, API rate limiting, monitoring, and cross-cutting aspects

Project description

domain-suite

Consolidated domain packages for Python services: typed errors, security context, API rate limiting, event monitoring, and cross-cutting aspects.

PyPI Python versions License CI

Overview

domain-suite brings together five complementary domain packages into a single distribution:

  • domain-errors: Typed domain error hierarchy with wrapping and chaining
  • domain-security: Security context management and authorization checks
  • domain-api-limiter: Request rate limiting and quota enforcement
  • domain-monitoring: Event monitoring and telemetry
  • domain-aspects: Composable decorators for logging, auth, throttling, error wrapping, and sensitivity masking

Each package maintains its namespace and API; the consolidation is organizational (single distribution, unified testing).

Installation

# Base install
uv add domain-suite

# With all optional extras (logging + sensitivity)
uv add "domain-suite[all]"

# Or select extras
uv add "domain-suite[logging]"    # for mixin-logging support
uv add "domain-suite[sensitivity]" # for mixin-sensitivity support

or with pip:

pip install domain-suite
pip install "domain-suite[all]"

Requires Python 3.11+.

Packages

domain-errors

Typed domain error hierarchy with wrapping and chaining for Python services.

Public API: DomainError, ErrorChain, WrapErrorsClient, wrap_errors, ChainLink, ChainVia, DomainClassifier, DomainCrossing.

Example:

from domain_errors import DomainError, wrap_errors

class DatabaseError(DomainError):
    domain = "database"
    code = "db_connection_failed"
    http_status = 503
    retryable = True

@wrap_errors(as_=DatabaseError)
def fetch_user(user_id: str):
    # ... implementation
    pass

See docs/domain_errors/ for full documentation.

domain-security

Security context management and authorization checks.

Public API: SecurityContext, SecurityContextManager, Principal, requires, tenant_scoped, Authorizer, Permission, PolicyDecision, SecretRef, SecretValue, security error classes.

Example:

from domain_security import SecurityContext, SecurityContextManager, requires

# Set security context
ctx = SecurityContext(user_id="usr_123", tenant_id="org_abc", claims={"role": "admin"})
SecurityContextManager.set(ctx)

# Enforce authorization via decorator
@requires(permission="admin.read")
def admin_only_function():
    return "Admin access granted"

See docs/domain_security/ for full documentation.

domain-api-limiter

Request rate limiting and quota enforcement.

Public API: throttled, PolicyRegistry, RateLimit, ThrottlePolicy, TierRate, Period, RateLimitExceeded, throttle error classes.

Example:

from domain_api_limiter import throttled

@throttled(scope="api.documents", rate="100/hour")
def create_document(title: str):
    return {"id": "doc_123", "title": title}

See docs/domain_api_limiter/ for full documentation.

domain-monitoring

Event monitoring and telemetry.

Public API: monitored, MonitorRegistry, MetricSink, MetricEvent, Outcome, CollectingSink, NullSink, monitoring error classes.

Example:

from domain_monitoring import monitored, MonitorRegistry

@monitored(event="document.processed")
def process_document(doc_id: str):
    return {"status": "success"}

See docs/domain_monitoring/ for full documentation.

domain-aspects

Composable decorators for logging, auth, throttling, error wrapping, and sensitivity masking.

Public API: aspects, Logged, Requires, Throttled, TenantScoped, WrapErrors, Sensitive, AspectEntry, AspectKind, aspect error classes.

Example:

from domain_aspects import aspects, Logged, Requires, Throttled

@aspects(
    Logged(event="document.create"),
    Requires(permission="documents.write"),
    Throttled(scope="api.documents", rate="100/hour"),
)
def create_document(title: str, content: str) -> dict:
    return {"id": "doc_123", "title": title}

See docs/domain_aspects/ for full documentation.

Consolidated From

This distribution consolidates five independent domain packages (originally domain-errors, domain-security, domain-api-limiter, domain-monitoring, and domain-aspects) into a single unified distribution to simplify dependency management and testing.

Each package retains its original public API and namespace. Internal dependencies between packages within the suite are resolved locally (no external package re-imports required).

Optional Extras

  • [logging]: Integrates with mixin-logging>=0.6.0 for structured event logging adapters.
  • [sensitivity]: Integrates with mixin-sensitivity>=0.4.0 for automatic PII/PHI field masking.
  • [all]: Includes both mixin-logging and mixin-sensitivity.

Future versions may introduce new extras or migrate integrations (e.g., mixin-suite packages if they consolidate similarly).

Development

Install development dependencies:

uv sync --all-extras

Run tests:

pytest

Run linting and type checking:

ruff check .
ruff format --check .
mypy

License

Apache License 2.0. See LICENSE for details.

Contributing

See CONTRIBUTING.md for guidelines.

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

domain_suite-0.1.1.tar.gz (256.5 kB view details)

Uploaded Source

Built Distribution

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

domain_suite-0.1.1-py3-none-any.whl (60.7 kB view details)

Uploaded Python 3

File details

Details for the file domain_suite-0.1.1.tar.gz.

File metadata

  • Download URL: domain_suite-0.1.1.tar.gz
  • Upload date:
  • Size: 256.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for domain_suite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6a4441a684e2837289ca833063d7cad76035a9b8a7b1ae1f898f01e1d184c0ab
MD5 51a2535ccb4cf0ba6df24b12b4c1b2e6
BLAKE2b-256 9711b78f1d9e9e0e9539f4a38b49cf4779776aaa872a9b1d98af8ce78f2dc592

See more details on using hashes here.

Provenance

The following attestation bundles were made for domain_suite-0.1.1.tar.gz:

Publisher: publish.yml on jekhator/domain-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file domain_suite-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: domain_suite-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 60.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for domain_suite-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad8897927240500ef0132f46ec35190336a46e2eab29a541005b3b912178eff6
MD5 68ec849664eec1ffcfefd03069e06d93
BLAKE2b-256 58c4c66250183d65ea8175607f6812e307144b520ef805325842f562fbfd9e32

See more details on using hashes here.

Provenance

The following attestation bundles were made for domain_suite-0.1.1-py3-none-any.whl:

Publisher: publish.yml on jekhator/domain-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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