DI container for Python applications
Project description
Injex - DI Container for Python
Injex is a lightweight and easy-to-use Dependency Injection (DI) container for Python applications. It simplifies dependency management, making your code more modular, testable, and maintainable. Injex is inspired by popular DI frameworks in other programming languages and brings similar capabilities to Python.
Features
🌟 Simple API: Easy to understand and use. 🔄 Multiple Lifestyles: Support for singleton, transient, and scoped services. 🧩 Flexible Registrations: Register services, factories, and instances. 🏷️ Named Registrations: Register multiple implementations of the same interface using names. 🔍 Property Injection: Inject dependencies into properties after object creation. 🛠 Optional Dependencies: Handle optional dependencies gracefully. 🚀 No External Dependencies: Pure Python implementation without third-party packages.
Installation
pip install injex
Why Use Dependency Injection?
Dependency Injection is a design pattern that helps in:
- Modularity: Breaking down your application into interchangeable components.
- Testability: Facilitating unit testing by allowing dependencies to be mocked or stubbed.
- Maintainability: Making it easier to update, replace, or refactor components without affecting other parts of the application.
- Flexibility: Configuring different implementations of the same interface for various scenarios (e.g., testing, production).
Quick Start
Here's a simple example of usage Injex:
from abc import ABC, abstractmethod
from injex import Container
class IService(ABC):
@abstractmethod
def perform_action(self):
pass
class ServiceImplementation(IService):
def perform_action(self):
print("Service is performing an action.")
container = Container()
container.add_transient(IService, ServiceImplementation)
service = container.resolve(IService)
service.perform_action() # output: Service is performing an action.
Another examples in examples folder.
Documentation
For detailed documentation on all functionalities, usage examples, and best practices, please refer to the Documentation.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
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
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 injex-1.0.0.tar.gz.
File metadata
- Download URL: injex-1.0.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56292381b06cc8314a0adf42bc6b633f5a3ef2d82d6a33611f071720fb3acbee
|
|
| MD5 |
922efceec82dc0cd8172b91596c69658
|
|
| BLAKE2b-256 |
f9335c91af99bb073f2a7da26ea8fedeb4cf2952653eae732e69da549ef80d77
|
File details
Details for the file injex-1.0.0-py3-none-any.whl.
File metadata
- Download URL: injex-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72ebba6d6626d0405d433e3080f0ea85526876801acba1590f1a84e5362a5c1d
|
|
| MD5 |
e87c9583cb7c7f130b63ff98763439d4
|
|
| BLAKE2b-256 |
5e43bbf72126c82e0eec2a0803fe1df183cba9fb4e27c89fa7cad3f7b7d18965
|