Dependency injection container
Project description
Independency
Independency is a DI container library. Unlike many other Python DI containers Independency operates in the local scope. It's inspired by punq, so the API is very similar.
Independency supports generics and other specific typings.
Installation
pip install independency
Examples
Let's begin with a simple example.
import requests
from independency import Container, ContainerBuilder
class Config:
def __init__(self, url: str):
self.url = url
class Getter:
def __init__(self, config: Config):
self.config = config
def get(self):
return requests.get(self.config.url)
def create_container() -> Container:
builder = ContainerBuilder()
builder.singleton(Config, Config, url='http://example.com')
builder.singleton(Getter, Getter)
return builder.build()
def main():
container = create_container()
getter: Getter = container.resolve(Getter)
print(getter.get().status_code)
if __name__ == '__main__':
main()
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
independency-1.1.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for independency-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67237787c1d11442497f17d74d4d7dbc8be2ee3e8e1008beaa13b06d2a58c1ab |
|
MD5 | 09a7c24053b4a47a8f6b18b0e5a3e03e |
|
BLAKE2b-256 | f51e7e82cd3847908453a1543c126d9bc70e8b57043a40c093b07fb6fc21229d |