Lagom is a dependency injection container designed to give you 'just enough' help with building your dependencies.
Project description
What
Lagom is a dependency injection container designed to give you "just enough" help with building your dependencies. The intention is that almost all of your code doesn't know about or rely on lagom. Lagom will only be involved at the top level to pull everything together.
Features
- Type based auto wiring with zero configuration.
- Fully based on types. Strong integration with mypy.
- Minimal changes to existing code.
- Integration with a few common web frameworks.
- Support for async python.
- Thread-safe at runtime
You can see a comparison to other frameworks here
🎉 Version 2.0.0 is now released! 🎉
For users of python 3.7 and above this should require no changes. Full details can be found in the release notes upgrade instructions.
Installation
pip install lagom
# or:
# pipenv install lagom
# poetry add lagom
Note: if you decide to clone from source then make sure you use the latest version tag. The master
branch may contain features that will be removed.
For the versioning policy read here: SemVer in Lagom
Usage
Everything in Lagom is based on types. To create an object you pass the type to the container:
container = Container()
some_thing = container[SomeClass]
Auto-wiring (with zero configuration)
Most of the time Lagom doesn't need to be told how to build your classes. If
the __init__
method has type hints then lagom will use these to inject
the correct dependencies. The following will work without any special configuration:
class MyDataSource:
pass
class SomeClass:
# 👇 type hint is used by lagom
def __init__(datasource: MyDataSource):
pass
container = Container()
some_thing = container[SomeClass] # An instance of SomeClass will be built with an instance of MyDataSource provided
and later if you extend your class no changes are needed to lagom:
class SomeClass:
# 👇 This is the change.
def __init__(datasource: MyDataSource, service: SomeFeatureProvider):
pass
# Note the following code is unchanged
container = Container()
some_thing = container[SomeClass] # An instance of SomeClass will be built with an instance of MyDataSource provided
Singletons
You can tell the container that something should be a singleton:
container[SomeExpensiveToCreateClass] = SomeExpensiveToCreateClass("up", "left")
Explicit build instructions when required
You can explicitly tell the container how to construct something by giving it a function:
container[SomeClass] = lambda: SomeClass("down", "spiral")
All of this is done without modifying any of your classes. This is one of the design goals of lagom.
Hooks in to existing systems
A decorator is provided to hook top level functions into the container.
@bind_to_container(container)
def handle_move_post_request(request: typing.Dict, game: Game = lagom.injectable):
# do something to the game
return Response()
(There's also a few common framework integrations provided here)
Contributing
Contributions are very welcome. Please see instructions here
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 Distributions
Built Distributions
Hashes for lagom-2.2.0b1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16c3768bef3421daa9cacc624482373fce6d9af7674ac4c4da3e7fe24694ab3c |
|
MD5 | 87d341e4a12cc0264159a8a409d4dbc5 |
|
BLAKE2b-256 | bb4f96b6ba318da5ccd3b93631d7cc8beacb8bd9bb88b8a5be66e8b0db9a7c87 |
Hashes for lagom-2.2.0b1-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f1064c0820c5dfbe75def665af8fce10ff229dedebcb189793da25258fa412 |
|
MD5 | a724bccceac0a66410b7bb469dfc7e0e |
|
BLAKE2b-256 | 6ff3c70e59526b01d9c7d7e50e802cddf0533663c58bbe8677e18a297ed44caf |
Hashes for lagom-2.2.0b1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa782f86ca9afd845096050f1caadc8fc94b158229fb64284f7a58b72bbc8338 |
|
MD5 | 64aa47787468e9b6bbf1f4c92b03b7a6 |
|
BLAKE2b-256 | 95c2486be20d44e9992beac446544159f569702f150723d2c408e5c6392395ba |
Hashes for lagom-2.2.0b1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e8f9cd2d0d513c3ff7e2abcc43d883ce90b4e9b1c515421461d7ba70bfd87b |
|
MD5 | 934f71c614c09f4fcca278ee7462ec41 |
|
BLAKE2b-256 | 339b9bf37d312082c796054533a22a0f0aa21af2289160d428dcfe6f5724f94d |
Hashes for lagom-2.2.0b1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcdc57414fd01739cf056263b043d383b5f25c776dab6d020cc0af2803795e78 |
|
MD5 | fff16e9bf93bcac382f781c7b9db9648 |
|
BLAKE2b-256 | 7b5af6f73e958a075313adf4b191467a69ca08ba2391b16ba99892aae940ab01 |
Hashes for lagom-2.2.0b1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75d89b38ccaa4ecd0a59dc0d935d141e8dc6ccfb49b1cf248acb8ae3fc543462 |
|
MD5 | 5f6ea0104ca629d186a9baae17137585 |
|
BLAKE2b-256 | d346fb33260c8abb2cb5ad83c04ec211c3cafa0f3d7f927a4034ccc4078f0a1c |
Hashes for lagom-2.2.0b1-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d8aca7da9d3e71c92ab23c65150015b8a69ef3f43bfd8b3dba17c9d77d00d9e |
|
MD5 | 5edc574caae5ee32eadb327e49c595eb |
|
BLAKE2b-256 | 37cdb8d7ce71e253efd6f5e4cc0ae80eaa44c58c13d7b7c524f3b14c7f4e907e |
Hashes for lagom-2.2.0b1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0dc581500d4e0095df31b51fdf8b700de4384beb42877656c5fef3d41e7bac6 |
|
MD5 | 6cfa0b5d9fb66db8220e6c13eb508f44 |
|
BLAKE2b-256 | 8a95be6425756f2723fb3c09d645051b958d9575c7f3cc0c2eb3fb6dc3c4609f |
Hashes for lagom-2.2.0b1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e288d9d91f36cbba2363f354f3a847d538f5f84a388a9bc1a329f30d4fc7b29 |
|
MD5 | 59d0923e30dc577f00bfcfe8b4aa0e59 |
|
BLAKE2b-256 | 34ab816b47c7a274d1ee716fc083342e6c2fc663c36d4e0fb9e9e168f1190347 |
Hashes for lagom-2.2.0b1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7347937c1b40a120b67bc89a4ae69207db068f3652cae7f4ceb72ef9585a931 |
|
MD5 | 8bba2c038d5dcbf5232f1b94c80e1245 |
|
BLAKE2b-256 | 6985502df630e556cb5fef107f81acca994a4b10c07ca242c6efa06fdaceb28a |
Hashes for lagom-2.2.0b1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79b70666a473499dd467a6709058194e3d5b7bbb29527364533c397815fecb70 |
|
MD5 | e0e7fe5aaa07261548ab2bf378144248 |
|
BLAKE2b-256 | 71944a6221a0968d7ab5a36abb7a7cbc036c59a8ab4c3e89fb263f251fea957a |
Hashes for lagom-2.2.0b1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cad6fc4a2c4fecbeb43462d317a848089373b63c815ddf588fdb75a6726d2a8 |
|
MD5 | a7ab3a059c8c31ef175850886e301a5b |
|
BLAKE2b-256 | ad56373bf8c91e197a85b95feb4f72e59aaedf0a01b459ca0a89ff3137f8becf |
Hashes for lagom-2.2.0b1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c02ef459f759311ea8dde3d6d636d54b66b87b7294640967b3c297810ece21b1 |
|
MD5 | 8c8ab4bf8b39aaaa0311e28e220dff4b |
|
BLAKE2b-256 | 928a27b8e1fbe93a49874935930340b6775cd3278f3ebca099acbaab0680cda8 |
Hashes for lagom-2.2.0b1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf207dbae9e2b99c29ba037765b2e5252bb5986043ee6025ccc735421b46b5af |
|
MD5 | 5f3166054c54d6539df559dbaf426e64 |
|
BLAKE2b-256 | b9815f641658d6323edafe0f95e4f4eb35d2cdf7920d4b822d3d2f9aa04b2db1 |
Hashes for lagom-2.2.0b1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a49c00c48ce25290c6cfdf8f168c25297f584d17bde1ef0576fbe21de4f27d2 |
|
MD5 | 57a0269288ed7ce472b02ff914db402a |
|
BLAKE2b-256 | 5bd95da413ece1ce9081b4f9e96fce5eab9e0a4bc5350eee63f599000179e671 |
Hashes for lagom-2.2.0b1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7aeb93b744d23a890357162821051f00ddcb5805726724e9cce3b10377adf08 |
|
MD5 | 4950e31e0499b9c469ba61a954da6225 |
|
BLAKE2b-256 | 86098bf35dc43e1b6c6e71cf39fc967e3356dbaeeba9a12ecde03077e7cd970e |
Hashes for lagom-2.2.0b1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ee0c030e0a23f1fa5512af09ee75034a30a027ec433226b442fabf321952185 |
|
MD5 | 48afe6caa55cfc8e96589cc071a88dd3 |
|
BLAKE2b-256 | 3e8205c20bfcf91fc11a7123e2f5a652c940dfd0cb284f0ce3871b911f25dde5 |
Hashes for lagom-2.2.0b1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ec117b474569800292f7deb9df87c02b07a30ffb3f9235243ff1bff9c547ab3 |
|
MD5 | 0928391d640d770eff082f0abf54f804 |
|
BLAKE2b-256 | 068efacd29c83575e6086f4ce7b6c4cb373aa92edcad15e498c4ff5d66eac22e |
Hashes for lagom-2.2.0b1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c212a1b15694c5dcd284ce4dca053c534242080112d253fc6ac6c6828ae42958 |
|
MD5 | 41fa36af8bb99f19b1094c760523c0ac |
|
BLAKE2b-256 | 87761889d75b7329559d50f3920c05577e514190ac123287aeab49f515a2ae17 |
Hashes for lagom-2.2.0b1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c379eeb32f7bf3d17d75ab762543553a0b60b45e22d1ecbbd6d986a56f9f244a |
|
MD5 | 533724643a7e915b0e65bd00d94a0946 |
|
BLAKE2b-256 | a10303b048d53015051aed14384e8329df12e59bd40dc93f5428c595440829d2 |
Hashes for lagom-2.2.0b1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ab397258a604ddc4dd29501f3d6f1c0b25e22308cd09f45b72b2e89591c4589 |
|
MD5 | 274ab1f1366b7ae05f63aa6a92262d81 |
|
BLAKE2b-256 | 9dc11981c9fe144322f57fbf1a2825e3f7f864fcf23fba105f365607f2b79a99 |
Hashes for lagom-2.2.0b1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375d0911ec4ce7d6486a9660086f64798824e9fd56e2cde98fcb8cd3345d8c69 |
|
MD5 | d544c3762b2029fbe8fafbd8c7353853 |
|
BLAKE2b-256 | 32274487dfcc606c9b227e6a6539ca2ce018d09e7bf295699871bb9d946397dc |
Hashes for lagom-2.2.0b1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17f62dd5e1bfd1da7c830b00b4a2717720d2dcf080f40ef457a59eba9c8204f0 |
|
MD5 | 16d410d144804628690da072520171b1 |
|
BLAKE2b-256 | a70d8051ab7a5096cfa84ba22a5511f7c97b20b43ed522aea07f34dab80f2280 |
Hashes for lagom-2.2.0b1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c438ba1ddd902f11c964350dae92419faea683d295dc8af7c876e9a008c0f69 |
|
MD5 | 06b3afd9ad9f404c27c5524a38f5941b |
|
BLAKE2b-256 | c2fd94d7a3e6154d822ee3abafb3df9f375975155762bb047892e43245db4178 |
Hashes for lagom-2.2.0b1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c554d52728e141cab11101718373d09ea6f7170d96869c9e728e2bf5033958f |
|
MD5 | 19c5930c8477244d23ebde7f52afc094 |
|
BLAKE2b-256 | 491d7051e3725637ef8da39b6222b9b07f64da47ec5019107fb49cff099fe36d |