a13x-depinj
A lightweight, yet powerful dependency injection framework for Python applications.
Features
- Simple and intuitive API
- YAML-based component configuration
- Lazy component initialization
- Automatic dependency management
- Component lifecycle management
- Type hints support
- Context manager interface
Installation
pip install a13x-depinj
Quick Start
- Define your components:
from dataclasses import dataclass
@dataclass
class DatabaseConfig:
url: str
port: int
class Database:
def __init__(self, config: dict):
self.config = DatabaseConfig(**config)
def connect(self):
# Implementation
pass
class UserService:
def __init__(self, config: dict):
self.db = ComponentRegistry().get(Database)
- Create a deployment configuration (deployment.yaml):
components:
- module: myapp.database
class: Database
config_path: database.config
- module: myapp.services
class: UserService
config_path: services.user
where config_path references a starting entry in the config.yaml file:
services:
user:
name: "a13x"
email: "a13x.h.cc@gmail.com"
database:
config:
db_path: "data/market_data.db"
enable_wal: true
pragma_synchronous: "NORMAL"
pragma_journal_mode: "WAL"
pragma_cache_size: -2000 # 2MB cache
max_connections: 10
- Initialize the registry:
from a13x_depinj import ComponentRegistry, Config
# Load application configuration
config = Config.load_config('config.yaml')
# Initialize components
with ComponentRegistry.from_yaml(config, 'deployment.yaml') as registry:
# Get component instances
db = registry.get(Database)
user_service = registry.get(UserService)
# Use components
db.connect()
Advanced Usage
Lazy Initialization
Components can be initialized lazily when first accessed:
registry = ComponentRegistry.from_yaml(config, 'deployment.yaml', lazy=True)
Component Lifecycle Management
Components can implement cleanup methods:
class Database:
def cleanup(self):
# Cleanup resources
pass
The registry will automatically call cleanup when using the context manager or when unregistering components.
Type Hints
The registry supports type hints for better IDE integration:
from typing import TypeVar, Type
T = TypeVar('T')
registry = ComponentRegistry[T]()
db: Database = registry.get(Database)
Contributing
Contributions are welcome! Please check our Contributing Guidelines for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for a13x-depinj 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| a13x_depinj-0.2.0.tar.gz | 14.2 kB | Without provenance | Details for a13x_depinj-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| a13x_depinj-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for a13x_depinj-0.2.0-py3-none-any.whl |
Total release size: 27.0 kB
Release files / a13x_depinj-0.2.0.tar.gz
| Download URL | a13x_depinj-0.2.0.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a15c6fe5b4c9a7a6825418933a2148c17a12865c636658d879237ef43b07836
|
|
BLAKE2b-256 checksum How to use checksums |
9a9897b166566f2b88944662b8abcf652f182da9abdfcdf0481b3e39d6276d54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.12.9 Linux/6.11.0-19-generic
|
Release files / a13x_depinj-0.2.0-py3-none-any.whl
| Download URL | a13x_depinj-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d9b44cc508458feb0511d87d46e8a2b31f29340c49b9c86560899ac238772f4
|
|
BLAKE2b-256 checksum How to use checksums |
88212934fa878d63f43ce2b829ef632d0c238f4185d38f3bb600cf03614ad292
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.12.9 Linux/6.11.0-19-generic
|
Security for a13x-depinj 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.