Very fast Dependency Injection library
Project description
Very fast Dependency Injection for Python, which is highly uses typing features. Sometimes faster then similar call in Python.
Requirements
Only works with Python 3.7 or greater
c++ 11 comaptible compiler. (only if u want to build from source)
Wheels provided for windows x86/x64 and linux x86/x64
Usage
from typing import Generic, TypeVar
from yapic.di import *
T = TypeVar("T")
class Car(Generic[T]):
engine: T
def __init__(self, engine: T):
self.engine = engine
# simplified Car class
class Car(Generic[T]):
engine: Inject[T]
class Gasoline:
pass
class Diesel:
pass
class Electronic:
pass
class DieselCar(Car[Diesel]):
pass
ELECTRONIC_CAR = Token("ELECTRONIC_CAR")
injector = Injector()
injector.provide(Gasoline)
injector.provide(Diesel)
injector.provide(Electronic)
injector.provide(DieselCar)
injector.provide(ELECTRONIC_CAR, Car[Electronic])
diesel = injector[DieselCar]
assert isinstance(diesel, DieselCar)
assert isinstance(diesel.engine, Diesel)
electronic = injector[ELECTRONIC_CAR]
assert isinstance(electronic, Car)
assert isinstance(electronic.engine, Electronic)
def drive_diesel(car: DieselCar):
assert isinstance(car, DieselCar)
assert isinstance(car.engine, Diesel)
injector.exec(drive_diesel)
# you can set constant values, like a dict
MEANING_OF_LIFE = Token("MEANING_OF_LIFE")
injector[MEANING_OF_LIFE] = 42
assert injector[MEANING_OF_LIFE] == 42
def question(q: MEANING_OF_LIFE):
assert q == 42
injector.exec(question)
# cached injectable
life_q = Injectable(question)
# this is same as with injector.exec(question), but injectable is precached
life_q(injector)
Keyword Only Arguments
class Config(dict):
def __init__(self):
super().__init__(some_key=42)
def get_kwarg(config: Config, *, name, type):
if name == "some_key":
return config[name]
else:
raise NoKwOnly()
def fn(*, some_key: str):
assert some_key == 42
injector = Injector()
injector.provide(Config)
injector.provide(fn, provide=[KwOnly(get_kwarg)])
For more info see Python Stub file or test files
Release Process
change VERSION in setup.py
git add setup.py
git commit -m "chore(bump): VERSION"
git checkout release
git merge master
git tag -a VERSION -m "chore(bump): VERSION"
git push && git push --tags
git checkout master
git merge release
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 Distributions
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 yapic.di-2.0.12.tar.gz.
File metadata
- Download URL: yapic.di-2.0.12.tar.gz
- Upload date:
- Size: 40.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43dd741f73a03baa2524478ef651dcdba40140615dc71df2d20a9e1852719c0e
|
|
| MD5 |
2981ad8708c4873dc052e415a179c9b2
|
|
| BLAKE2b-256 |
4e1f2e3199ed44536e82af0ad95171170fc01c0b9459f68021f2698732b78815
|
File details
Details for the file yapic.di-2.0.12-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 41.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39265574e1a92e9fa03781411310da01bed663ae441e55ea0725a67d443aec1f
|
|
| MD5 |
3c5dde834bba64de4068de0386418c6f
|
|
| BLAKE2b-256 |
f2d8009d7bfa7b48d3edb7943865e0e35f678da6ed23ad74dff3c65046655e01
|
File details
Details for the file yapic.di-2.0.12-cp311-cp311-win32.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp311-cp311-win32.whl
- Upload date:
- Size: 37.3 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0eb462eef2bf721ca3ab0684a18be30af02a0a96f33497520608664f2327f2e
|
|
| MD5 |
e37d0d25f07ccad309041ac23fa0e63c
|
|
| BLAKE2b-256 |
ce0e35b7ecccd45d765709475b65448fbc9667eb48f7916656c7fd73ad5a01ed
|
File details
Details for the file yapic.di-2.0.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 362.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b316d5e3f2bc663db3d7888af55a4aca3f15dcd3ca889ae03ae5744af34518e2
|
|
| MD5 |
3d206d1b7002401cfff84e0deef576e2
|
|
| BLAKE2b-256 |
eb225fec400b64fc1e8dcf1514a5f6666d5cfbaacb589effd54c937ed2781093
|
File details
Details for the file yapic.di-2.0.12-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 41.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9bbc034ad350452e9076900638077acd6923d0521e1846d817561a8d919f247
|
|
| MD5 |
ded2ee5617edcbbc8de5220db239b5e0
|
|
| BLAKE2b-256 |
60545a7ee08b42bfc530a840575322981944266f774050c432913b6798cd5d15
|
File details
Details for the file yapic.di-2.0.12-cp310-cp310-win32.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp310-cp310-win32.whl
- Upload date:
- Size: 37.3 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9206685af7f222a35c391bf046117d428d2d74cb7f0ffd4658fbef96490303f
|
|
| MD5 |
1a7b88e725d3faef7696af8fa8a16a96
|
|
| BLAKE2b-256 |
a143688909839605c9115f514ac355ca0eda816a4e60b243e6e42ce3bd6c4b1e
|
File details
Details for the file yapic.di-2.0.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 343.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb871f0744c29a45e913327f69eb77855c32ba5a94f00a7f0bb5ec941cb441d3
|
|
| MD5 |
ea8fcca9471ec139ec4a4ea885b1fb01
|
|
| BLAKE2b-256 |
f30e9faf5a017d462e0435da1cedb9db321faacd22949d781a48e5f432729e94
|
File details
Details for the file yapic.di-2.0.12-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 43.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
629163bb0fce6c1fe8de3fce995054e65f6ff2a71a70bf00b5c028f209ab423f
|
|
| MD5 |
19d29737172c04485d032503e80608eb
|
|
| BLAKE2b-256 |
e262b405e6befc0d45ae513f9aa6d9b5bee897d67b1da580be7e7a494d21c306
|
File details
Details for the file yapic.di-2.0.12-cp39-cp39-win32.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp39-cp39-win32.whl
- Upload date:
- Size: 39.7 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1200b795f7267cc9ada870f24573ecb9d7379bf0f6b20f89ffcd0fe8754076ff
|
|
| MD5 |
7bf3f83e2f59c343af45b402588b69e3
|
|
| BLAKE2b-256 |
9edeca25a49914c6566de70243d2cf6d621bd2b5b145a4dc42141db565309ed8
|
File details
Details for the file yapic.di-2.0.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 341.6 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40066404dfdb5002f61cd52e78acbb26902b0a9e1385e21ee9d694cd5a1aafe0
|
|
| MD5 |
5149c5e7511ff0044e0b6838c656be28
|
|
| BLAKE2b-256 |
714ddfae472eb1be05d062b8c7af443fb3842a4bb5109cbef882109c1e25071e
|
File details
Details for the file yapic.di-2.0.12-cp39-cp39-macosx_10_9_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 53.5 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af212d8870478272aced5b605fd7bc4d1f055447975d0731d532417734037264
|
|
| MD5 |
5ad5df2a0ddb5fc5c0707ee01495ef06
|
|
| BLAKE2b-256 |
2be5634dddc73daceb126450485b66106fc3c1ecce1f4f93abf5711af698f6b9
|
File details
Details for the file yapic.di-2.0.12-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 44.1 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7131c8e5144215a2e1b7cf5eaa81b07143195a6d23224c78fb455bc65ab81c97
|
|
| MD5 |
b09bd725c7ffd9fce3839feda371850d
|
|
| BLAKE2b-256 |
60c3614e288489c2267daf5a5e3692276f1587a0f3f63807f1da3c1f61c970fe
|
File details
Details for the file yapic.di-2.0.12-cp38-cp38-win32.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp38-cp38-win32.whl
- Upload date:
- Size: 39.8 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d37377ebaa871a65edd35941c02dfaa2a150ad5df1e61a582bb63ade0df4655
|
|
| MD5 |
638f2c8461fbf1b8b47dd01e75ab8298
|
|
| BLAKE2b-256 |
17a37ee78b226cb363120b214e86f73b9ffe3518b888284a9695c771bf862806
|
File details
Details for the file yapic.di-2.0.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 350.7 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
236e471a2289f8605985923284b4edcbb1ea7ca1161ff2401b2e5f904bd643f1
|
|
| MD5 |
86e2971cac1212759370d9d5ad228ccf
|
|
| BLAKE2b-256 |
fb8759d2570cba927ef7428e1c1ed8f88f80d4d586048c4e14d466c8032c5812
|
File details
Details for the file yapic.di-2.0.12-cp38-cp38-macosx_10_9_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 53.5 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4f8101f6a561b703afabeca12d7b16c1663146aa1585299387db7fe16ef6414
|
|
| MD5 |
326855b9d34e354a4e7fd7d05fe00415
|
|
| BLAKE2b-256 |
6dd544df9da9a9aec93f425afb9ccc760fe6d694db1f92612b0663fe9dd6394b
|
File details
Details for the file yapic.di-2.0.12-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 44.1 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f89fb7360bf77489300454f57b26de38473c4da323afa2b30fe7c707cf0cb164
|
|
| MD5 |
9110fe26d6790e3d57f208f7d31afe8c
|
|
| BLAKE2b-256 |
6b71d3245423747c90467249671aee502036b18c3780a81a210b045e13282cdd
|
File details
Details for the file yapic.di-2.0.12-cp37-cp37m-win32.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp37-cp37m-win32.whl
- Upload date:
- Size: 40.7 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52325d7c6b09b8ea1b5ac04a764a28e4f4c215c1cadb94d96d9646d327430a0a
|
|
| MD5 |
c2d97ce83be1464894f2662e4460e1e6
|
|
| BLAKE2b-256 |
b3adaa1adc39b67f6aec285fba5de26a855d79a508fed85927ddfab4d95911d1
|
File details
Details for the file yapic.di-2.0.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 346.0 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7495d03ce66d143c872d9057cd7b0c17653f1ccbc336d896b93b98ea76607ef
|
|
| MD5 |
43dc6f348cee986681a7ba390d4c5364
|
|
| BLAKE2b-256 |
96cd715aa5c9028475994ba4bacc01982608e5f2739cd394c92809684b102dbd
|
File details
Details for the file yapic.di-2.0.12-cp37-cp37m-macosx_10_9_x86_64.whl.
File metadata
- Download URL: yapic.di-2.0.12-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 52.3 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f74b8ee8c182775b4f69528e51fc9af6f962cf8b2cbd41d65ede687f249551d7
|
|
| MD5 |
a5feddbdfcca2ee94714ad6843b30e53
|
|
| BLAKE2b-256 |
2b29384e8974cd011472ca50ab7c0e459c67b063039fa173c85797341943d1f7
|