Dependency Injector is a dependency injection microframework for Python. It was designed to be unified, developer-friendly tool that helps to implement dependency injection design pattern in formal, pretty, Pythonic way.
Dependency Injector framework key features are:
Easy, smart, pythonic style.
Obvious, clear structure.
Extensibility and flexibility.
High performance.
Memory efficiency.
Thread safety.
Documentation.
Semantic versioning.
Dependency Injector containers and providers are implemented as C extension types using Cython.
Example code:
"""Example of dependency injection in Python."""importloggingimportsqlite3importboto3importexample.mainimportexample.servicesimportdependency_injector.containersascontainersimportdependency_injector.providersasprovidersclassCore(containers.DeclarativeContainer):"""IoC container of core component providers."""config=providers.Configuration('config')logger=providers.Singleton(logging.Logger,name='example')classGateways(containers.DeclarativeContainer):"""IoC container of gateway (API clients to remote services) providers."""database=providers.Singleton(sqlite3.connect,Core.config.database.dsn)s3=providers.Singleton(boto3.client,'s3',aws_access_key_id=Core.config.aws.access_key_id,aws_secret_access_key=Core.config.aws.secret_access_key)classServices(containers.DeclarativeContainer):"""IoC container of business service providers."""users=providers.Factory(example.services.UsersService,db=Gateways.database,logger=Core.logger)auth=providers.Factory(example.services.AuthService,db=Gateways.database,logger=Core.logger,token_ttl=Core.config.auth.token_ttl)photos=providers.Factory(example.services.PhotosService,db=Gateways.database,s3=Gateways.s3,logger=Core.logger)classApplication(containers.DeclarativeContainer):"""IoC container of application component providers."""main=providers.Callable(example.main.main,users_service=Services.users,auth_service=Services.auth,photos_service=Services.photos)
What's the difference between this Python project and similar ones?
Enumerate comparisons.
Provides clear and simple structure: Containers -> Providers.
Use Python language features, deeply follow Pythonic style and Zen of Python.
Does NOT provide @inject decorator (or any other way of monkey-patching) that pollutes the code. Instead of this, provides feature of clean overriding of providers.
Very fast, implemented using Cython.
--
Anyone who agrees with this pull request could vote for it by adding a 👍 to it, and usually, the maintainer will merge it when votes reach 20.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/vinta/awesome-python/pull/879
**Author:** [@rmk135](https://github.com/rmk135)
**Created:** 4/23/2017
**Status:** ❌ Closed
**Base:** `master` ← **Head:** `master`
---
### 📝 Commits (1)
- [`58c9776`](https://github.com/vinta/awesome-python/commit/58c9776bb7554438a7144cb0de142e07baba26d7) Add Dependency Injector
### 📊 Changes
**1 file changed** (+1 additions, -0 deletions)
<details>
<summary>View changed files</summary>
📝 `README.md` (+1 -0)
</details>
### 📄 Description
## What is this Python project?
Dependency Injector is a dependency injection microframework for Python. It was designed to be unified, developer-friendly tool that helps to implement dependency injection design pattern in formal, pretty, Pythonic way.
Dependency Injector framework key features are:
* Easy, smart, pythonic style.
* Obvious, clear structure.
* Extensibility and flexibility.
* High performance.
* Memory efficiency.
* Thread safety.
* Documentation.
* Semantic versioning.
Dependency Injector containers and providers are implemented as C extension types using Cython.
Example code:
```python
"""Example of dependency injection in Python."""
import logging
import sqlite3
import boto3
import example.main
import example.services
import dependency_injector.containers as containers
import dependency_injector.providers as providers
class Core(containers.DeclarativeContainer):
"""IoC container of core component providers."""
config = providers.Configuration('config')
logger = providers.Singleton(logging.Logger, name='example')
class Gateways(containers.DeclarativeContainer):
"""IoC container of gateway (API clients to remote services) providers."""
database = providers.Singleton(sqlite3.connect, Core.config.database.dsn)
s3 = providers.Singleton(
boto3.client, 's3',
aws_access_key_id=Core.config.aws.access_key_id,
aws_secret_access_key=Core.config.aws.secret_access_key)
class Services(containers.DeclarativeContainer):
"""IoC container of business service providers."""
users = providers.Factory(example.services.UsersService,
db=Gateways.database,
logger=Core.logger)
auth = providers.Factory(example.services.AuthService,
db=Gateways.database,
logger=Core.logger,
token_ttl=Core.config.auth.token_ttl)
photos = providers.Factory(example.services.PhotosService,
db=Gateways.database,
s3=Gateways.s3,
logger=Core.logger)
class Application(containers.DeclarativeContainer):
"""IoC container of application component providers."""
main = providers.Callable(example.main.main,
users_service=Services.users,
auth_service=Services.auth,
photos_service=Services.photos)
```
For more examples, please, follow https://github.com/ets-labs/python-dependency-injector
## What's the difference between this Python project and similar ones?
Enumerate comparisons.
1. Provides clear and simple structure: Containers -> Providers.
2. Use Python language features, deeply follow Pythonic style and Zen of Python.
3. Does NOT provide ``@inject`` decorator (or any other way of monkey-patching) that pollutes the code. Instead of this, provides feature of clean overriding of providers.
4. Very fast, implemented using Cython.
--
Anyone who agrees with this pull request could vote for it by adding a :+1: to it, and usually, the maintainer will merge it when votes reach **20**.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/vinta/awesome-python/pull/879
Author: @rmk135
Created: 4/23/2017
Status: ❌ Closed
Base:
master← Head:master📝 Commits (1)
58c9776Add Dependency Injector📊 Changes
1 file changed (+1 additions, -0 deletions)
View changed files
📝
README.md(+1 -0)📄 Description
What is this Python project?
Dependency Injector is a dependency injection microframework for Python. It was designed to be unified, developer-friendly tool that helps to implement dependency injection design pattern in formal, pretty, Pythonic way.
Dependency Injector framework key features are:
Dependency Injector containers and providers are implemented as C extension types using Cython.
Example code:
For more examples, please, follow https://github.com/ets-labs/python-dependency-injector
What's the difference between this Python project and similar ones?
Enumerate comparisons.
@injectdecorator (or any other way of monkey-patching) that pollutes the code. Instead of this, provides feature of clean overriding of providers.--
Anyone who agrees with this pull request could vote for it by adding a 👍 to it, and usually, the maintainer will merge it when votes reach 20.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.