Skip to main content

Infrastructure layer exception classes for Python applications

Project description

python-infrastructure-exceptions

Infrastructure layer exception classes for Python applications.

Purpose: Low-level infrastructure errors (database, network, external services).

Separation:

  • python-infrastructure-exceptions = Infrastructure layer (DB, network, cache, queue)
  • python-app-exceptions = Business/application layer (validation, business rules)

Installation

pip install python-infrastructure-exceptions

Usage

from python_infrastructure_exceptions import (
    InfrastructureException,
    DatabaseError,
    ExternalServiceError,
    ConfigurationError,
    CacheError,
    MessageQueueError
)

# Database errors
raise DatabaseError("Connection pool exhausted", details="Max connections: 20")

# External service errors
raise ExternalServiceError("Stripe API timeout", service_name="stripe")

# Configuration errors
raise ConfigurationError("Missing DATABASE_URL environment variable")

# Cache errors
raise CacheError("Redis connection failed", details="Connection refused")

# Message queue errors
raise MessageQueueError("Kafka broker unavailable", details="broker.example.com:9092")

Exception Hierarchy

InfrastructureException (base)
├── DatabaseError              # Database connection, query failures
├── ExternalServiceError       # Third-party API failures
├── ConfigurationError         # Missing/invalid configuration
├── CacheError                 # Redis, Memcached failures
└── MessageQueueError          # Kafka, RabbitMQ failures

When to Use

Exception Type Use For Example
InfrastructureException Base class for custom infrastructure errors Custom database adapter error
DatabaseError Database connection, query, transaction failures PostgreSQL connection pool exhausted
ExternalServiceError Third-party API failures Stripe API timeout, SendGrid error
ConfigurationError Missing or invalid configuration Missing DATABASE_URL env var
CacheError Cache layer failures Redis connection refused
MessageQueueError Message broker failures Kafka broker unavailable

Comparison with python-app-exceptions

Layer Library Exceptions Example
Infrastructure python-infrastructure-exceptions DatabaseError, ExternalServiceError PostgreSQL timeout
Business python-app-exceptions ValidationError, BusinessRuleViolation Invalid email format

Features

  • ✅ Infrastructure-specific error types
  • ✅ Detailed error context (service name, connection details)
  • ✅ Framework-agnostic
  • ✅ Zero dependencies
  • ✅ Type-safe error handling

License

MIT

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

python_infrastructure_exceptions-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

File details

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

File metadata

File hashes

Hashes for python_infrastructure_exceptions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 da39abed0586eff27ec35c304b944a904b24a29caa428e64687f05fc42a75394
MD5 cade2ba619aa16c02bcb2d90b12cfffe
BLAKE2b-256 43dfbf8aa0fbb330a860bdd59b6df6019aca048977e3373bcaffda06a196a11d

See more details on using hashes here.

File details

Details for the file python_infrastructure_exceptions-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_infrastructure_exceptions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 580e5dd07f0a318a0f0312fccc5c31a5ca912792d5dcb8977a3181aaf1fdef23
MD5 9d7078f5d66d62fd03a2015af37f2746
BLAKE2b-256 b3854d426acd00b40ee0abc30827c18f0bb99900ce3018209224d38faff7cf99

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