https://github.com/vshulcz/injex
DI container for Python applications
https://github.com/vshulcz/injex
container ddd dependency-injection di injector singleton transient
Last synced: 6 months ago
JSON representation
DI container for Python applications
- Host: GitHub
- URL: https://github.com/vshulcz/injex
- Owner: vshulcz
- License: mit
- Created: 2024-10-14T15:09:03.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-20T05:15:04.000Z (over 1 year ago)
- Last Synced: 2025-11-05T14:14:04.578Z (9 months ago)
- Topics: container, ddd, dependency-injection, di, injector, singleton, transient
- Language: Python
- Homepage:
- Size: 53.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dependency-injection-in-python - Injex - Tiny typed dependency injection container with constructor injection, singleton/transient/scoped lifetimes, test overrides, and graph validation before startup. Zero runtime dependencies. [🐍, MIT License]. (Software / DI Frameworks / Containers)
README
# Injex - DI Container for Python

[](https://pypi.python.org/pypi/injex)
[](https://codecov.io/gh/vshulcz/injex)
[](https://github.com/vshulcz/injex)
[](https://github.com/vshulcz/injex/LICENSE)
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
```bash
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:
```python
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](./examples).
## Documentation
For detailed documentation on all functionalities, usage examples, and best practices, please refer to the [Documentation](./docs/tutorial.md).
## Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.