Skip to main content

Lagom is a dependency injection container designed to give you 'just enough' help with building your dependencies.

Project description

Lagom

Scrutinizer Code Quality Code Coverage PyPI

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)

Full docs here 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lagom-2.4.0b3-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

lagom-2.4.0b3-cp311-cp311-win_amd64.whl (142.5 kB view details)

Uploaded CPython 3.11Windows x86-64

lagom-2.4.0b3-cp311-cp311-win32.whl (126.3 kB view details)

Uploaded CPython 3.11Windows x86

lagom-2.4.0b3-cp311-cp311-musllinux_1_1_x86_64.whl (295.1 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

lagom-2.4.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (300.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lagom-2.4.0b3-cp310-cp310-win_amd64.whl (143.0 kB view details)

Uploaded CPython 3.10Windows x86-64

lagom-2.4.0b3-cp310-cp310-win32.whl (126.7 kB view details)

Uploaded CPython 3.10Windows x86

lagom-2.4.0b3-cp310-cp310-musllinux_1_1_x86_64.whl (299.3 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

lagom-2.4.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lagom-2.4.0b3-cp39-cp39-win_amd64.whl (142.9 kB view details)

Uploaded CPython 3.9Windows x86-64

lagom-2.4.0b3-cp39-cp39-win32.whl (126.7 kB view details)

Uploaded CPython 3.9Windows x86

lagom-2.4.0b3-cp39-cp39-musllinux_1_1_x86_64.whl (297.0 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

lagom-2.4.0b3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (303.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lagom-2.4.0b3-cp38-cp38-win_amd64.whl (142.1 kB view details)

Uploaded CPython 3.8Windows x86-64

lagom-2.4.0b3-cp38-cp38-win32.whl (126.1 kB view details)

Uploaded CPython 3.8Windows x86

lagom-2.4.0b3-cp38-cp38-musllinux_1_1_x86_64.whl (295.9 kB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ x86-64

lagom-2.4.0b3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (300.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lagom-2.4.0b3-cp37-cp37m-win_amd64.whl (137.8 kB view details)

Uploaded CPython 3.7mWindows x86-64

lagom-2.4.0b3-cp37-cp37m-win32.whl (123.6 kB view details)

Uploaded CPython 3.7mWindows x86

lagom-2.4.0b3-cp37-cp37m-musllinux_1_1_x86_64.whl (238.5 kB view details)

Uploaded CPython 3.7mmusllinux: musl 1.1+ x86-64

lagom-2.4.0b3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (243.4 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

File details

Details for the file lagom-2.4.0b3-py3-none-any.whl.

File metadata

  • Download URL: lagom-2.4.0b3-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for lagom-2.4.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 76c7c6117f90ad2f878927103b0e74342d1ed9baef48606b4116c4e44e5b583b
MD5 8876d857aa21c8463e44d3c68eb8331e
BLAKE2b-256 c8d2b71f4b40e863568bf7c0cee93a303c71064d4112cf56bc34eb122394d61d

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 142.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e8381cb601ca82c97de8bef47367d5cdf66636ef0d91fe7f94fd711e0f4d3196
MD5 219a8d644784370214bba5f7732022b3
BLAKE2b-256 883a27a679dc9153ec2ee1471e663caa546da60844847e88220263ab9ea65039

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp311-cp311-win32.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp311-cp311-win32.whl
  • Upload date:
  • Size: 126.3 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 697d1c45a6200f58539da493dcc7076f2840a304006713d25b101e8e96b015e4
MD5 f1c5fcedc414463858f9a6c462c40a15
BLAKE2b-256 4a9afa9170f6034893583c82da139f742fe56c1ee117e987789e6da1837a9436

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 30b98b2e9bd6a7614199e4927913769231c32cb7fc3af748d3d9252dda3e4645
MD5 f078d7e3bacbf9a29c3805ca69ffd950
BLAKE2b-256 1355604a351fa127e8f060435e9b9784a643830e3cc0405922181d48bd0c490e

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3e09915e060c05830cc57744cb5f233ce884efaa6c3d385c6893d044560fbcc
MD5 6c988693dd8330b34a916ab7b173c0a5
BLAKE2b-256 cac856b25653b587f5edb1709731f2134c4e00f9c443b1b9623f05284ef8c8d9

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 143.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c9d75925ebf1b8dd2cd3dc3bb5b9dca2690888f23805d8632cccdd3854e06d34
MD5 9a9caa78a6d1093b83cd8bc720ed1243
BLAKE2b-256 a73f8615a8bc161fc99f69bf782e4c164da5da88d8dbcc2e7b9bbcad6e39b907

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp310-cp310-win32.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp310-cp310-win32.whl
  • Upload date:
  • Size: 126.7 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 f2bec0f079ea9fc21bb9786386e95221d963dd26fc290c420ff695aad00dc4c0
MD5 16f78a034ecd214b181e914b2207e105
BLAKE2b-256 3b3bfe54a54dd174299777eb87699428de0137282188ddfe179306484bb915af

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 625b04f18b76984a6cce8bb7de5f7a646cd73f14e5cbcfe6c3b3e482246842d9
MD5 c9431b4968a5054f36213d432acf5733
BLAKE2b-256 52cf8ff2b14b68e6ea121932f4514653b7030529d8b05c338849ace745952b1d

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4cf2855def8bae777fc21b187044a6d3aad481a8b26ed2706a868c988118c1bf
MD5 1d0db9ed3d0c3a8b8a7ccd19f671ce6b
BLAKE2b-256 a073ab6f236e52e54d9d3d81ab94a3bfeec93474684167e7b0adab129486d7f9

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 142.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8320d0249478ad68ef1be6919ce459786e900157b41a12bea6f794ceeaf2cce7
MD5 d7fc21e064d723dcbf9feb2458f3c679
BLAKE2b-256 ea56eb4593792a8995de76e8337cf2a538d1f77223fb81cdfff5b28d91d2ea93

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp39-cp39-win32.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp39-cp39-win32.whl
  • Upload date:
  • Size: 126.7 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 a2eb2ec9c5103df3033688afb3f5891a9058d36d16f4f8d9c5736878e1f3aaf2
MD5 105e3f923e380c3da7128cd4fab73a56
BLAKE2b-256 cfcc3e924ea43c48df6d4c6f38118d3b1a370dc233876577c076a8f7e0592ae1

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 178deb3a4342e66111c2174e64756282078f08bcc0554b53f7d71af4b65e36f8
MD5 d175c76adb395d70c3aef93c8e143141
BLAKE2b-256 03923409bf12ec292fcbe15420fbb27148bce1476021b22e841f12626764c606

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa11a159f99077ab3e0374f1891ce36975cdccbc90bfe2ace2285a68ee330287
MD5 b5d10e45fb060a57ee7e8adbb4020431
BLAKE2b-256 54831809b5ef87d79ee47a93c5542203d08abcbfa4f953de81333aa4fde54645

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 142.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

Hashes for lagom-2.4.0b3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 72e83d71be009f7b11578ddb16548e926534ad99663895ed49b01c693828563b
MD5 28ce3f9c2ae83e73ab9740f583263202
BLAKE2b-256 8b03e90d82545d02723cf3b4772de6ddbb9e5415f29d848561161c5c946837b8

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp38-cp38-win32.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp38-cp38-win32.whl
  • Upload date:
  • Size: 126.1 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 8748b20b3b48fb575115c25f8f245b4114d75c8929dc38d6ab1ed79d485be21c
MD5 b9cc866ac983eff2cb2ead5cd9b6875e
BLAKE2b-256 98ba1ca43d8bc65bd839b7a889374116df5373600e662d8bb42240033822f1e1

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d8a2476e870f92248ad04a789fe9850dbbc0724bf46fe34ac9effff0f89dc800
MD5 adba47725bc70d8637cf694ddbce5f61
BLAKE2b-256 4d34fac5b59f1153b2f695e926d3a4ba4981c2a1b2ac343de4905320574fe59a

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0c66b367976fce60ced2d157255a2b1dab08fed69c4c8ab3023885bf08b2bd27
MD5 5d416a736ebdaede57e8e7bb6f8e160f
BLAKE2b-256 c897672764c75973c067c8a74d300d44f1d44c8c9c06fe2681a5ff280d104ecd

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 137.8 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fd37d53f98b859c3a6b8bfa7997d6ee260ee29c3589c17e99381b000050ef89d
MD5 7d83df557b0788e806759e41732a35c9
BLAKE2b-256 959ebd3cf4947d238e3f9840958fbdd8a3faab74f0c5e46796fc41c6a811a714

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp37-cp37m-win32.whl.

File metadata

  • Download URL: lagom-2.4.0b3-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 123.6 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for lagom-2.4.0b3-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 dcc6e416caa4d58854664567df0c4dc33afdbce1482ed24b46bac5c189127d48
MD5 55a0fa9a686117c5614308c651eff721
BLAKE2b-256 cdd669e4a10ff6b0187a143b8ec60e10a312dfe75ac4ab1752f0cc3abf24a031

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c1a7163ae54b2c22760da8fb28d635a839e06e078247995298c2346e31285f53
MD5 b3ca55ae8bfc41f3133ddb30dd01a954
BLAKE2b-256 eaa2ecf610fd86d1f452e727232922ffbac7244b21e7deeba5555e734a16e8f9

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90e54ad4dfe846f6213915da098f4c5ab23b41c7bb45aaa4c52598b41762360d
MD5 5262632b4df1e2f5d760825e0412bc86
BLAKE2b-256 622b65920203eaa43a13ccf925817da68ba6f8d77dae17bad73ea5dea5b2396e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page