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.5.0-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

lagom-2.5.0-cp311-cp311-win_amd64.whl (145.5 kB view details)

Uploaded CPython 3.11Windows x86-64

lagom-2.5.0-cp311-cp311-win32.whl (128.7 kB view details)

Uploaded CPython 3.11Windows x86

lagom-2.5.0-cp311-cp311-musllinux_1_1_x86_64.whl (304.3 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

lagom-2.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (311.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lagom-2.5.0-cp310-cp310-win_amd64.whl (145.8 kB view details)

Uploaded CPython 3.10Windows x86-64

lagom-2.5.0-cp310-cp310-win32.whl (128.9 kB view details)

Uploaded CPython 3.10Windows x86

lagom-2.5.0-cp310-cp310-musllinux_1_1_x86_64.whl (309.1 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

lagom-2.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (316.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lagom-2.5.0-cp39-cp39-win_amd64.whl (145.7 kB view details)

Uploaded CPython 3.9Windows x86-64

lagom-2.5.0-cp39-cp39-win32.whl (128.9 kB view details)

Uploaded CPython 3.9Windows x86

lagom-2.5.0-cp39-cp39-musllinux_1_1_x86_64.whl (306.7 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

lagom-2.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (315.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lagom-2.5.0-cp39-cp39-macosx_10_9_x86_64.whl (185.7 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

lagom-2.5.0-cp38-cp38-win_amd64.whl (145.3 kB view details)

Uploaded CPython 3.8Windows x86-64

lagom-2.5.0-cp38-cp38-win32.whl (128.5 kB view details)

Uploaded CPython 3.8Windows x86

lagom-2.5.0-cp38-cp38-musllinux_1_1_x86_64.whl (305.6 kB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ x86-64

lagom-2.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (311.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lagom-2.5.0-cp38-cp38-macosx_10_9_x86_64.whl (183.1 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

lagom-2.5.0-cp37-cp37m-win_amd64.whl (140.3 kB view details)

Uploaded CPython 3.7mWindows x86-64

lagom-2.5.0-cp37-cp37m-win32.whl (125.8 kB view details)

Uploaded CPython 3.7mWindows x86

lagom-2.5.0-cp37-cp37m-musllinux_1_1_x86_64.whl (245.0 kB view details)

Uploaded CPython 3.7mmusllinux: musl 1.1+ x86-64

lagom-2.5.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (250.4 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

lagom-2.5.0-cp37-cp37m-macosx_10_9_x86_64.whl (175.5 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file lagom-2.5.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for lagom-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64d25db5df407b77b76b169ead465c678927a1a47d79ad4a0424059b343312cb
MD5 00e95d6a66dd15aa30ce6290492daa08
BLAKE2b-256 6b370e504bb7b98cddfc522e1539c32d3dfd300a6b8f2096df6189d86da8f3d2

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: lagom-2.5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 145.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.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7e495d4263e36acb4dc9a08fa812194807afe12a6fd31ae90b7344301de63f04
MD5 6b809c8462c58c7fc0ddf9680aae1e83
BLAKE2b-256 f705c3ee01e0ef7758109ab931c0a0c1926f3a65e1a553dc1042604a4ed05e1b

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: lagom-2.5.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 128.7 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.5.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 646916f3afe508685fd1ef9659264c44f12622e6739ab0e35020f0f400235b1b
MD5 e575f49f5c20f8ce9649935f35261b48
BLAKE2b-256 52c889906759ac61415013283ed6896b0ed9328a74d74028db24288b7db2e71e

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 dbc24c08be222e204c513a194e3dac3e209601065bee96d00ec33eee16378403
MD5 7d8ff2b690583d0b9d061fc3c8fca9e0
BLAKE2b-256 fe888f677e146035d35f6f78bf2257590def710d8942a2e4b662963bc804500d

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f49e9d1ad4da5ba96b4602403bf5ab80ce4a3b907143e7edf75ffa7d3fd1b7a
MD5 2b526558afcce3a0524a3968559162a9
BLAKE2b-256 4fceef99fdcefe90b48b45ddc06be844e5062948db8355ff3a91db366f779208

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: lagom-2.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 145.8 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.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2d7c50622610c70a69daf83f99c40678e3505dbe8b99774ea03fc3ccb8d437fb
MD5 2bdc882447ac959dd8d6d61a9b08406a
BLAKE2b-256 8d7eeefcb8a601a4b173ff0ed416ba671785887db4077667df4fd09b8b36b543

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: lagom-2.5.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 128.9 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.5.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 725e9f9313bb72200539e7314973f1b64cb95f595c315ad3c7146f5aaae934dd
MD5 7bb317d08cb949ae1af62b5617558882
BLAKE2b-256 8f678702fec751cc66a01d621cb5efb906c319576ca9626b9fa7a515a1010922

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f09f5a7c1b328ebafc534bb3910793652a24a36eadee872bbaea42904bcbc5af
MD5 f7573e437f9231fe715ece9575ab3789
BLAKE2b-256 f892349b40896d2603f9b6e310bd6796003baf9dfbcc1919346a489e7aea04e9

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b608bfa5855d6f0f898f3d2801417229557730620d9bc7cc035dc508eb272c27
MD5 6d10ee9417432b3557b5282a99699521
BLAKE2b-256 4a638572c21169d9c1ce5538eb7cc17757ad20b4e96323b5f1108b0073b7d0f1

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: lagom-2.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 145.7 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.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cc426370a8f663ca15105c60ef3d5b2bc3f974b18d138755eedbf2a786011909
MD5 18658005062eba50cdadd417eb275a80
BLAKE2b-256 1f3c3f134712729470153ce97e428c3b00bd47ba0e1a7e66f7d4858b8e2af091

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: lagom-2.5.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 128.9 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.5.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 5594a6a158dc2cdda88e85ba40dab109914422e0d3c08753c7a8fd0d994fd201
MD5 8b922e9f11054ff925123d3cf3edc4bf
BLAKE2b-256 ad73b3dbbd05305659d6dccfef2c631279a7dcaae7d273fda1cb557cd14ed7fa

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3b915af0ab1e58cd38ca8c7841ec2fae35cd5ffef157d11df908e400e7f934c9
MD5 69b4e0893beb7da6d7801b1317fd66ed
BLAKE2b-256 3f44c9f8d2a81f20329975e28250ee1b4c6937d06b1530924971d2d8e5ffd7e9

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 469787a78c3e24d9ca042080dbb0e0808618f18946628c71f7f38ad616eb8764
MD5 f72e5f4e2d40ae720913319d5f2952d6
BLAKE2b-256 2cab1e440d6dbd7c15f87f12013d6313574d9f283ef5941c43419fea4b53fbd9

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7a9b2da5737e0df4684a785507a23cb5cd8f818da57494da11793698e8b3a1ed
MD5 6b8ffe5577a9f4d24e00f332de24ad10
BLAKE2b-256 76d9ce7f936e4de4e972589d58a35b4aa07527bf026419aca5f48f3be4f7fdc5

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: lagom-2.5.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 145.3 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.5.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 31ee67b2ad70dd24cf9539cd4d889abf8006d7314632eccda186a5bbc5a69cf5
MD5 ff4c8645705f3fc7eadab7273b631893
BLAKE2b-256 f34fcfabedf7552080cbe942eeccd3cba5d2604ecfb9b67367c651bc16802e54

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp38-cp38-win32.whl.

File metadata

  • Download URL: lagom-2.5.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 128.5 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.5.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 ee5a431c42f4a54f3f7a27440fc07511ff3e975b8d0063ec32f2e97743235a37
MD5 69303f5ff6f589f1254a93b966e13681
BLAKE2b-256 65b70c0f411718e393bd5c321ba41399dedb7b10e6c3dcd04ae95f2dfd8a8ec1

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4556fabb05bf1408383fca759dd612679b8b49287a4b5ef319c4c7cdb7ce7b92
MD5 e42b3d2e9da8da47da7fa4803af9e623
BLAKE2b-256 f2ebcc76c4c1806292a4b06332c85ae8e0c73d5153f32c494a54b2acd241fad8

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5dc703d0ba72d04887767ca7d0350c2217bb9efb96f2b4d979aa5ee13089f68
MD5 2ca08eb36a283552a488c0c8efa42324
BLAKE2b-256 adb91c4c2d77560b1f9495f1486c602c1b6dee8917d532e4dabfc3277cc959ea

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 eee5764b241c778b36a5e22a21cb03837b001fdd6daa9568ab327b1d8be94c6d
MD5 53e96b017cf2f05c822f84d8f77fa77c
BLAKE2b-256 e06dc15857121613b4fc9f2b7b1178310c3a849504573144c0cb7a04e528fbf2

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: lagom-2.5.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 140.3 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.5.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 bb4d5de02f59fcc8b16412443e4bc9c8a694fbffd200dbc6ead6c965cc7f18ff
MD5 fac4011d58da94b3ee1ae5ad45911307
BLAKE2b-256 ef970cf08ab50b9380afab47bb38c4f61d277725e0afbc2b81e8cb4a8742f167

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: lagom-2.5.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 125.8 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.5.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 452bf42acff6d9de25ebf7325a1d25ca991d40f0ebfdda2be4058a7e3f525656
MD5 00021972257e296b803a4e1bd5aa1f8d
BLAKE2b-256 9aa3edf5a07c71142786212b2bc7360744ab064144606d78e4599a4c9e885ad0

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c2894a65dc4c2a2a83615d37df3285852e409819f90ed3fda3a33b6a271bc8b2
MD5 fa076d3e44140e6d11ff7125d5e54c94
BLAKE2b-256 00c4490b78f636d40b19b3cf276481986af0421f2d517b8edaf855da82297c4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.5.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c93688caca0f7be456441860f797995f9c74d7761a96082ce01fa92191947b85
MD5 d6aa6504f5111628e2180343083e5ad5
BLAKE2b-256 1bcac6324d6dc3ac509dd91a6d6713b6fed91531b3dfd8c16721794031d55009

See more details on using hashes here.

File details

Details for the file lagom-2.5.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.5.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 db341d662afb3a925d2172fb54e3751faf4cad9f6afd3c2cf5fc4cfda3fbae91
MD5 f67bb42216fb5ae4bd2934c39b1db9ad
BLAKE2b-256 45046a401fa4a85e0044b8033f7d1b295ca17080c8b47db90c7ca2816ecb32f1

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