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.

Overview

domains brings together five complementary 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

uv add domain-suite

or with pip:

pip install domain-suite

Requires Python 3.11+.

Packages

domain-errors

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

from domain_errors import DomainError, ErrorChain

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

try:
    user = db.query("SELECT * FROM users WHERE id = $1", user_id)
except Exception as e:
    raise ErrorChain.wrap(
        e,
        as_=DatabaseError,
        message=f"Failed to fetch user {user_id}",
        user_id=user_id
    ) from e

See docs/errors/ for full documentation.

domain-security

Security context management and authorization checks.

from domain_security import SecurityContext, 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/security/ for full documentation.

domain-api-limiter

Request rate limiting and quota enforcement.

from domain_api_limiter import ApiLimiter, RateLimitExceeded

limiter = ApiLimiter()

try:
    limiter.check_limit("api.documents", rate="100/hour")
except RateLimitExceeded:
    return {"error": "Rate limit exceeded"}, 429

See docs/api_limiter/ for full documentation.

domain-monitoring

Event monitoring and telemetry.

from domain_monitoring import MonitorRegistry, EventSink

sink = EventSink()
registry = MonitorRegistry()
registry.set_default_sink(sink)

registry.log_event("document.processed", {"doc_id": "doc_123", "status": "success"})

See docs/monitoring/ for full documentation.

domain-aspects

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

from domain_aspects import aspects

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

See docs/aspects/ for full documentation.

Development

Install development dependencies:

uv sync

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.0.tar.gz (247.8 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.0-py3-none-any.whl (60.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: domain_suite-0.1.0.tar.gz
  • Upload date:
  • Size: 247.8 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.0.tar.gz
Algorithm Hash digest
SHA256 3b664211bca79f24c93ec475e0609814a7adec02c76ed406d3dbc2382db92b75
MD5 3e490dc2515dfba46bb87604a49b1496
BLAKE2b-256 2faaefd36f530ada0bd3813ad7b0988c9d1cc55f1eda0e26f19a8fd9fe12c8b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for domain_suite-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: domain_suite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 60.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd54d78d9dde051b2bbde2e2484ab3c66f26b1ccf1d12b51944f32da51437a1
MD5 271e99761171375f990ef3b7825a1390
BLAKE2b-256 32dbbc2eaf937543ae4cb6e140a7d96b48a93d2f2787a1cdbfec3f771eed7338

See more details on using hashes here.

Provenance

The following attestation bundles were made for domain_suite-0.1.0-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