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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_infrastructure_exceptions-0.1.0.tar.gz.
File metadata
- Download URL: python_infrastructure_exceptions-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da39abed0586eff27ec35c304b944a904b24a29caa428e64687f05fc42a75394
|
|
| MD5 |
cade2ba619aa16c02bcb2d90b12cfffe
|
|
| BLAKE2b-256 |
43dfbf8aa0fbb330a860bdd59b6df6019aca048977e3373bcaffda06a196a11d
|
File details
Details for the file python_infrastructure_exceptions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_infrastructure_exceptions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
580e5dd07f0a318a0f0312fccc5c31a5ca912792d5dcb8977a3181aaf1fdef23
|
|
| MD5 |
9d7078f5d66d62fd03a2015af37f2746
|
|
| BLAKE2b-256 |
b3854d426acd00b40ee0abc30827c18f0bb99900ce3018209224d38faff7cf99
|