Dependency injection microframework for Python
Project description
What is Dependency Injector?
Dependency Injector is a dependency injection framework for Python.
Why do I need it?
Dependency Injector helps you understand and change the structure of the application.
With the Dependency Injector you keep application structure in one place. This place is called the container. You use the container to manage all the components of the application. All the component dependencies are defined explicitly. This provides the control on the application structure. It is easy to understand and change it.
The container is like a map of your application. You always know what depends on what.
Flask + Dependency Injector example application container:
from dependency_injector import containers, providers
from dependency_injector.ext import flask
from flask import Flask
from flask_bootstrap import Bootstrap
from github import Github
from . import views, services
class ApplicationContainer(containers.DeclarativeContainer):
"""Application container."""
app = flask.Application(Flask, __name__)
bootstrap = flask.Extension(Bootstrap)
config = providers.Configuration()
github_client = providers.Factory(
Github,
login_or_token=config.github.auth_token,
timeout=config.github.request_timeout,
)
search_service = providers.Factory(
services.SearchService,
github_client=github_client,
)
index_view = flask.View(
views.index,
search_service=search_service,
default_query=config.search.default_query,
default_limit=config.search.default_limit,
)
Running such container looks like this:
from .containers import ApplicationContainer
def create_app():
"""Create and return Flask application."""
container = ApplicationContainer()
container.config.from_yaml('config.yml')
container.config.github.auth_token.from_env('GITHUB_TOKEN')
app = container.app()
app.container = container
bootstrap = container.bootstrap()
bootstrap.init_app(app)
app.add_url_rule('/', view_func=container.index_view.as_view())
return app
And testing looks like:
from unittest import mock
import pytest
from github import Github
from flask import url_for
from .application import create_app
@pytest.fixture
def app():
return create_app()
def test_index(client, app):
github_client_mock = mock.Mock(spec=Github)
# Configure mock
with app.container.github_client.override(github_client_mock):
response = client.get(url_for('index'))
assert response.status_code == 200
# Do more asserts
See complete example here - Flask + Dependency Injector Example
How to install?
The package is available on the PyPi:
pip install dependency-injector
Where is the docs?
The documentation is available on the Read The Docs
Have a question?
Open a Github Issue
Found a bug?
Open a Github Issue
Want to help?
⭐️ Star the Dependency Injector on the Github
🆕 Start a new project with the Dependency Injector
💬 Tell your friend about the Dependency Injector
Want to contribute?
🔀 Fork the project
⬅️ Open a pull request to the develop branch
Project details
Release history Release notifications | RSS feed
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
Hashes for dependency-injector-3.25.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8396b6b49e8e521744e0682548dab16b8b76190ea77813e3cb470adc1072cf6e |
|
MD5 | b2435e716f4df8814936b460bafa4cec |
|
BLAKE2b-256 | 36a73726869a2c82ea8752b69f8b02b297e1cc616d72ee32baa9ae7ac72bd2d5 |
Hashes for dependency_injector-3.25.0-pp36-pypy36_pp73-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db8e534e5032dc75ded6c6d4b6baf47d6d57905771b5a0cde1bfed9e641e8d81 |
|
MD5 | ae09af6424d100516762f8862500e21d |
|
BLAKE2b-256 | b731692349d4eab806983546d04104dbe90cb8c81c983dd069a289b49bf87349 |
Hashes for dependency_injector-3.25.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3337e195ae0c7a4991550e4ad1bf95a50ab50e60685dab7afe460a4b412cb00f |
|
MD5 | eefe26120522365690d37c0adcd1a5b3 |
|
BLAKE2b-256 | d2572630d675eec8bdc73f81c922c0f6a83f4405ed4105ba08a99859ae05f6a5 |
Hashes for dependency_injector-3.25.0-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7c68c0804db39ee44e1e5188884da35a33851a0661256a3a1479c3e2f683332 |
|
MD5 | 78566f78314dce0d77b9b7ac885437f7 |
|
BLAKE2b-256 | 577956f039df966f08220ae66fa2145d747df41a2b6c6e106465f80e3193960e |
Hashes for dependency_injector-3.25.0-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14722a4dcb22933ca834c0805a91411d367c3cf2a477ee63806f830a426cd22b |
|
MD5 | 98c2a3fba4b21710a3b0ab6e7cf070fc |
|
BLAKE2b-256 | 40477834f049ef1dc625f6dfff71d14848f5e63fa2fe65e0b666526a5d2a9f13 |
Hashes for dependency_injector-3.25.0-pp27-pypy_73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ffe9af2d27fd8ec5a2e4f8a6bbecb2a2d6d261dba638dc44e12a28dd77e63cb |
|
MD5 | 131917e251a581e98a8540db6cba57ff |
|
BLAKE2b-256 | 5df319232dc4346657b4d2adc770a309d366adf0f7990c7870e5dd32330abe49 |
Hashes for dependency_injector-3.25.0-pp27-pypy_73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fba7557e00a3dc0b083956d3d37f56103eed879d8471503a5f600341d316de9d |
|
MD5 | a8a7eb4af9c58ff0df527535816415e2 |
|
BLAKE2b-256 | 52754abdecc025b0b11f0f0608eb8ba876d2432609322c3bd0325a79c3474efc |
Hashes for dependency_injector-3.25.0-pp27-pypy_73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a854922dd5fbf1924181e981a9902b695d4cde439582789750c4433de584e32 |
|
MD5 | fa3e6294115925b40be33f95758bffdc |
|
BLAKE2b-256 | a4d0d1ceb06e112b6f565f5fb4fbb01c19482fd48294a63e911ee265a35de633 |
Hashes for dependency_injector-3.25.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cde8c1cfa6084c31149b38cf11e83b24cf9fc7f6c38bae9e290950997f28adcf |
|
MD5 | 4eb95011b43fa4b74894db3bf7252c02 |
|
BLAKE2b-256 | b497befa401d38d844f2bf408cbcf026d3c25b5bd9a3fc81d82eeddec16d8e80 |
Hashes for dependency_injector-3.25.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c800a976cfe3a7fff60da014bd1e91a804118f183a2330b5fe59e405d4847ec3 |
|
MD5 | 5f7589cf23e33ec40e632c84c652b7f5 |
|
BLAKE2b-256 | 00e4bab8cd4c7c59b515bba07b752f24c7ea6914c7454d1ab55aba025cb166ef |
Hashes for dependency_injector-3.25.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fec66c7a42796676b71143101c368e8e8a74c6c93f0483c9b81a42892478eb27 |
|
MD5 | afab6853588d595d6625786f903d5e19 |
|
BLAKE2b-256 | 1eeb35c64ff66fba541f97d5bf843a28dc86797e9eb87deb10b3fb4b85667f96 |
Hashes for dependency_injector-3.25.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ce7385f17301780ef5a914555731502b62e0fbe8a3152634b3242aedd6520bc |
|
MD5 | 8a7f4c21232f702269e0b0c86bf74233 |
|
BLAKE2b-256 | 5a3752a829eee66cbbcd4cc4d4abfe960954aa46d3fb48e988ab1837c8548f83 |
Hashes for dependency_injector-3.25.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8dc5a187b75c89145b9b9f71771547ece671a3e204312891112065469213b5 |
|
MD5 | ad38cc81d203315ef198f46f89e65553 |
|
BLAKE2b-256 | da15ed6a34276146b6d0c10ac5a20486deb4b8dbd8b4928c4650c928a5c08b3e |
Hashes for dependency_injector-3.25.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f279898e6fe1837b560138ebb8dcb60262eff7c255d0edb40ff437642841e8ea |
|
MD5 | 887eaa129d32e8ef9cbb98d0c0a747c8 |
|
BLAKE2b-256 | 2239f5d38f046442d4251c75dd6e7886dd4365a47d0ff6eaefab767623705de2 |
Hashes for dependency_injector-3.25.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a6245050f54e5e2d6430262f4d9f1ba1d7d12b4ef14507aeaf774537881eba1 |
|
MD5 | b99ecd288dc9cefcd2359397648f2df6 |
|
BLAKE2b-256 | 480d8212a6ecacc58451fd53782e11c0e336776eaeb450307db0560f2e41aadc |
Hashes for dependency_injector-3.25.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11cc757a4c48bc958a31f5e3b9a4fdea9bebbf72d92be0372eeabff76ad8d2de |
|
MD5 | 6926d9cc5419be805bb7d313ce72fde6 |
|
BLAKE2b-256 | 762e6c18bbcd132c7d1cd8353d559ca1567af5f27dcd04f94f2a233669fe2f29 |
Hashes for dependency_injector-3.25.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bb3eecc4912b5931cb91280b4bef9a0771fb3b1ef6b259cc3bc1781eb51970f |
|
MD5 | bc80297dd2ff85fb264d77fdce893703 |
|
BLAKE2b-256 | b53c4e4cd39e3499e890fb37c8834a6636bb89c9ff432b25bb806e5aa3d6efaa |
Hashes for dependency_injector-3.25.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d324e1e691117d0c0b6e047aed819710565c737fca92b23919284933b5251f7 |
|
MD5 | df3861204eb6b29ecb73a4dade03f71a |
|
BLAKE2b-256 | 8480d3a01e7315a265eb0d13406afb3a0d2977c84b33145dd5b9542367e2e77d |
Hashes for dependency_injector-3.25.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e97b58f9afd49b7f973615998830402da3cf4610503a05673fc08b2283f8009 |
|
MD5 | 196142c4c5ff538d4f9e37176437eb70 |
|
BLAKE2b-256 | ad54516bd73d3ad53bdcb73896526c230fd239fb49f9f24638bbe4ddbbe83f37 |
Hashes for dependency_injector-3.25.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d7571444ed71c475a9cdfc29cd3318af0e7742a33f53868b46ca6acc2254ea4 |
|
MD5 | 5355f36ff0c2a15bab47f9b401537710 |
|
BLAKE2b-256 | 8ceb84f520bac61fcddadc9cb3e01147349e727a15f97ed605386c4bb440093d |
Hashes for dependency_injector-3.25.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f85adf0b00f3efe3f981e5845adc8c0b29dcb707854eb2e2b5f38cad8c81120 |
|
MD5 | 4c041088453f5a786b0e81f9a50c69a4 |
|
BLAKE2b-256 | 7eb0b4cc76ecc3477d7cb15a16573b48bd3f0b19dad287403b0d0aba6a4514e1 |
Hashes for dependency_injector-3.25.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e1ca02df77575504fbcb8a69b279d8946acc04a3a4a346552707d4ddc8ea206 |
|
MD5 | 2e5fb840f327e74c1ec1b4ef14c92b67 |
|
BLAKE2b-256 | 9f2d1529b90ecc63649d4219e92e971d3acc23813f4b99892f5c688c2e5bc84e |
Hashes for dependency_injector-3.25.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8c003ab00ca39d7d4007ae836c6fc92fd3ae32fe59404d49b2a95bec6329bba |
|
MD5 | 8c11b05652d3df520d3e340d96429d46 |
|
BLAKE2b-256 | e78aac7145f2fb253ae8079616bbe476df5762005c2bd09d70cb0c1878a0e42f |
Hashes for dependency_injector-3.25.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f46651f64d6a3cee18f85bb9e772939bb3d36e4bbad5d88a1afae312703f1962 |
|
MD5 | 5c151e7cab1599babb97b0376ea7048c |
|
BLAKE2b-256 | 0cae97b733df3bfb9787ec595daaa4d2b07eb79cdcc7dee54642942eb4bfab57 |
Hashes for dependency_injector-3.25.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 831afe1ca6fb256f3597340babffbf70d0a0baa388df3ea22f394ee348fc6a2f |
|
MD5 | 05a345812d8a8e86291d6a383a88b894 |
|
BLAKE2b-256 | 9b67d4fd52ea8213f04926fa27c2024fde240fd4d368ba491d7c3f305e0f151e |
Hashes for dependency_injector-3.25.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17c1cf0cf7e8cd9817780d5e3223562196111371b103bfafb4b7faf701b0e405 |
|
MD5 | 8bbd175fcebf4cc55bb36b2035f0211f |
|
BLAKE2b-256 | 92fe37f0583b7268d5c45aa3ee027ca150fc376d411c308118a6b4efc96f5947 |
Hashes for dependency_injector-3.25.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e70fd946496b6adcdb3234af0f4831b770469b548e11627a186ad2ec037d9f4 |
|
MD5 | 520595aad1323582ff24e0087591e43e |
|
BLAKE2b-256 | 537b57c559ad847d409dc93fcf1ec67413b264f988fbc410273e42027486f4d2 |
Hashes for dependency_injector-3.25.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12d650f63685b04f48d11b29c4929719d8cb150f6d93417685b7cb3c4b3c2f02 |
|
MD5 | bb651fbabb4b71bff5d72e8d9962ffd2 |
|
BLAKE2b-256 | 28d713bfdf96cbc93d85c4037b720f4f4ed7778e1a2fa609efa4f0c0cad4f4ad |
Hashes for dependency_injector-3.25.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a773da4265aba3b421a54f313bdf5909bf4bc20e8111333cc803f51fd60b6d1b |
|
MD5 | e0e8abad022b0c36ec06c230cc4717c5 |
|
BLAKE2b-256 | 1cb9927801d4529d90d1ba05383de27e3ca31a36f24f660f37313ea9584fe9e4 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 429b8fb411cffa015ff3dfb6bc7b97c4a395596590a500458e8b6fd84f4a9091 |
|
MD5 | 2852286d9ed135a483e71997b1f8d468 |
|
BLAKE2b-256 | d0585aed604d31e7cb5aba142b9681d47c3010922f5c661e071336f61b0a4486 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b05f7fe387cff2e30d2805bca97569d890381670c183b031e02fc0667e73f7e7 |
|
MD5 | f88c7f48dfb0c4201ad2df8554ceb706 |
|
BLAKE2b-256 | ee3f06716b501a920316c83fe32a8711dc286e3ac8b4292a3fcc59bb5878cc76 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4698c8ae46212c86b0bc3d27989709206b4b522527b248f054f77101427e506 |
|
MD5 | 5ae1464a08bd04ac0e845a71642e93fd |
|
BLAKE2b-256 | ae9ac165ba40029d96361d93efa8ef3686a770bed62a73e9b89947092ebd4c28 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb15c25baa001e9554b421007a5fc43c3527970badb5e3dfc6a749358d3a57b |
|
MD5 | 214f84d40dc6eb51ec56ee3112811614 |
|
BLAKE2b-256 | 254eea00cd752577005e3624391ec51e449b0d1b8f028b19252190a9c28b0891 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e505431c48c59bbe58d9837bfc592bdede16686b765ea3a0a599cdacfff1114 |
|
MD5 | 1520d2f4800680351d36464e39f41071 |
|
BLAKE2b-256 | ae5f851b5189cbf7347174504a094dd5fd93fdf57c720fa7975043902ffe6600 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f140092ecdef8ff89a1664d75925da8833e90a67c1cec564161f6377df70650 |
|
MD5 | ae4fa6712a892dc7a9a6b8c9fdc8b551 |
|
BLAKE2b-256 | 796412352e9998f011db39c3746bf32825cdc8f171e2eaabf82efd28f1b231d2 |
Hashes for dependency_injector-3.25.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79467a8b936bee41a718ebde60641505ab1decb85249a4f497c8bdeed4f09fb8 |
|
MD5 | e9f134e5f1a3386cff0e2980c1f15ad8 |
|
BLAKE2b-256 | d68d2761ad818a8dc64079cbfd3f4fafa82855b8d69fb52c5155fef006377ba9 |
Hashes for dependency_injector-3.25.0-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 006a38fa98a40dbbdb24a5f72e232bc59ee309950fd692fc4602dd662578feed |
|
MD5 | c03d8bf4913c1f39c613a5a32be4a2fa |
|
BLAKE2b-256 | 4410e185e7a62d07cae367a7f2f55a0614a8f015f2e1d13d84f0276ff448492a |
Hashes for dependency_injector-3.25.0-cp27-cp27mu-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af0e53b6762787bfc7e12599631fc4a5780d35be94221e6247c006c318b4547 |
|
MD5 | 60e1794a74d01b7d581938dae617caab |
|
BLAKE2b-256 | ff7f02c86756c72675dfd663b3474a0ac7718c0574f1050543f73eccb2e98a73 |
Hashes for dependency_injector-3.25.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e882a0ebb1e0566058cf0df9e4c754bd5fc7d3c6daed163a67d717a3022b935 |
|
MD5 | bc064f7f031643de459ab8123bb0e3c3 |
|
BLAKE2b-256 | e56279f171a39fa17d0bea6e7ce52146cc6bc07bc4be6be49596603974f8fc06 |
Hashes for dependency_injector-3.25.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e204e4f9f651ba268b2ef1f94726d0f86ee5319ddb33c74777369cd64641fe14 |
|
MD5 | 3bdd9e93be8f578b608a659333c027ec |
|
BLAKE2b-256 | c8fc03c3c896e223d99c8198747a7e0c9801f46ffc04a8d5c8513506584fc734 |
Hashes for dependency_injector-3.25.0-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d9e8cc6413adfef9eb924f1dbd6f487221cc1042b9917aeebb62c938eccb25d |
|
MD5 | 74a993af6741faf39e7af509bbae446b |
|
BLAKE2b-256 | b41713fdc1e5f23d1a91e7e001e87b8ae2d6e047dd19334d4486ebef9214297f |
Hashes for dependency_injector-3.25.0-cp27-cp27m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f15133d3155fed00efa4789da84e702bf6e3feddf010de9aa5bc82512edd4748 |
|
MD5 | 2a19d672784a95ff1f67d581c35e7f50 |
|
BLAKE2b-256 | 149cb067b3fb724770c52ec6e35aa9a6de0e1d4e06c402d54524cda8f6c30c36 |
Hashes for dependency_injector-3.25.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f121914c6a02855c7d1ac5a620dda14ca3119d7399d9244a25e74e763e2201b4 |
|
MD5 | c4d6a5f1448a1e1e9125613e867f119b |
|
BLAKE2b-256 | 76447e54dca5fb427e58caf425e5cd2da5411ecf31d043cc498ff12160570b21 |
Hashes for dependency_injector-3.25.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2864af383c47aa3be0b805f0027455648c9aba4484ffb7283dd940f1a05b085 |
|
MD5 | c1676d961acabbfeebaef221c4dbeeea |
|
BLAKE2b-256 | cd436a290060d697d27fedb8d554c6fad3defe6a103841d100bc8f9ccf8eecfb |
Hashes for dependency_injector-3.25.0-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d0e15bfaed0f8cc77eaa0e561982de83cfaf3e7a8b7bfb9cde90c92d30ab91 |
|
MD5 | 1e4633b1f621751b988339e8969abb93 |
|
BLAKE2b-256 | 5a65fb2357315a20dc474600c058908f0f66e33aba833889cc8cc53ed6ba0455 |