https://github.com/turborg/turbolightdi
TurboLightDI is a optimized Dependency Injection (DI) container engineered for speed and simplicity. Designed to deliver minimal overhead.
https://github.com/turborg/turbolightdi
automation clean-architecture decorators dependency-injection design-patterns high-performance inversion-of-control ioc-container lightweight microservices pypi python singleton software-architecture solid-principles testing turbolightdi turborg turboroid type-hints
Last synced: 4 months ago
JSON representation
TurboLightDI is a optimized Dependency Injection (DI) container engineered for speed and simplicity. Designed to deliver minimal overhead.
- Host: GitHub
- URL: https://github.com/turborg/turbolightdi
- Owner: turborg
- License: mit
- Created: 2025-12-28T22:49:51.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-12-31T12:16:55.000Z (5 months ago)
- Last Synced: 2026-01-03T13:25:10.464Z (5 months ago)
- Topics: automation, clean-architecture, decorators, dependency-injection, design-patterns, high-performance, inversion-of-control, ioc-container, lightweight, microservices, pypi, python, singleton, software-architecture, solid-principles, testing, turbolightdi, turborg, turboroid, type-hints
- Language: Python
- Homepage: https://turborg.com/turbolightdi
- Size: 45.9 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
[](https://github.com/turborg/turbolightdi/actions/workflows/release.yml)
[](https://github.com/turborg/turbolightdi/actions/workflows/test-daily.yml)


[](https://pepy.tech/projects/turbolightdi)
TurboLightDI is a lightweight, high-performance Inversion of Control container for Python.
## Usage
**TurboLightDI** uses a special hierarchy to manage your application's lifecycle. Components are divided into **External Components** and **Internal Logic**.
### Install
```bash
pip install turbolightdi
```
### Quick Example
```python
from TurboLightDI import cy, borg, service, repository
@cy
class DatabaseConfig:
@borg
def session_factory(self) -> Session:
return create_session_factory()
@repository
class UserRepository(TurboquentRepository):
pass
@service
class UserService:
def __init__(self, user_repository: UserRepository):
self.user_repository = user_repository
```
## About TurboLightDI
TurboLightDI aims to provide elegant dependency injection using decorators and type hints, allowing you to build decoupled, testable, and maintainable applications.
Core features:
* Zero Configuration: Use standard Python decorators.
* Constructor Injection: Automatic wiring based on Python type hints.
* Lifecycle Management: Efficiently manages object lifecycles (singleton, prototype...)
* Third-Party Support: Use `@borg` to inject objects from libraries like Redis, SQLAlchemy or any other third party lib.
* Circular Dependency Detection: Built-in protection against recursive injections (for example, A → B, B → A).
---
## Development
```bash
uv venv --python 3.12
uv pip install .[dev]
pre-commit install
```
### External Integration
Use these decorators to integrate third-party libraries (like Redis, SQLAlchemy etc..) into your application.
* **`@cy` (Configuration Yield)**: A class-level decorator for modules that house the configurations required to yield the objects your application needs.
* **`@borg` (Bound Object Resource Graph)**: A method-level decorator used within a `@cy` class. It holds and registers third-party libraries as assimilated components in the DI graph.
### Internal Logic (components)
For classes created within your own codebase, use the following decorators to enable auto DI:
* **`@component`**: The base decorator for any general-purpose class managed by the TurboLightDIContainer.
#### Specialized Components
To maintain clean architectural separation, use these specific aliases:
| Decorator | Role | Description |
|:------------------| :--- |:---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **`@controller`** | **REST APIs** | Entry points that orchestrate RESTful communication and handle incoming requests |
| **`@service`** | **Business Logic** | Encapsulates business logic. |
| **`@repository`** | **Data Access** | Communicates with data holders. Usually implements `TurboquentRepository`, providing a powerful abstraction layer for common DB operations with minimal boilerplate. |
---
*Part of the [**Turborg**](https://turborg.com) AI-First Open Source Suite Ecosystem*