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

Uploaded Python 3

lagom-2.4.1-cp311-cp311-win_amd64.whl (143.3 kB view details)

Uploaded CPython 3.11Windows x86-64

lagom-2.4.1-cp311-cp311-win32.whl (126.9 kB view details)

Uploaded CPython 3.11Windows x86

lagom-2.4.1-cp311-cp311-musllinux_1_1_x86_64.whl (295.8 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

lagom-2.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (301.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lagom-2.4.1-cp310-cp310-win_amd64.whl (143.7 kB view details)

Uploaded CPython 3.10Windows x86-64

lagom-2.4.1-cp310-cp310-win32.whl (127.3 kB view details)

Uploaded CPython 3.10Windows x86

lagom-2.4.1-cp310-cp310-musllinux_1_1_x86_64.whl (300.2 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

lagom-2.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lagom-2.4.1-cp39-cp39-win_amd64.whl (143.6 kB view details)

Uploaded CPython 3.9Windows x86-64

lagom-2.4.1-cp39-cp39-win32.whl (127.2 kB view details)

Uploaded CPython 3.9Windows x86

lagom-2.4.1-cp39-cp39-musllinux_1_1_x86_64.whl (297.9 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

lagom-2.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (304.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lagom-2.4.1-cp39-cp39-macosx_10_9_x86_64.whl (181.8 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

lagom-2.4.1-cp38-cp38-win_amd64.whl (142.8 kB view details)

Uploaded CPython 3.8Windows x86-64

lagom-2.4.1-cp38-cp38-win32.whl (126.7 kB view details)

Uploaded CPython 3.8Windows x86

lagom-2.4.1-cp38-cp38-musllinux_1_1_x86_64.whl (296.9 kB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ x86-64

lagom-2.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (301.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lagom-2.4.1-cp38-cp38-macosx_10_9_x86_64.whl (179.2 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

lagom-2.4.1-cp37-cp37m-win_amd64.whl (138.3 kB view details)

Uploaded CPython 3.7mWindows x86-64

lagom-2.4.1-cp37-cp37m-win32.whl (124.1 kB view details)

Uploaded CPython 3.7mWindows x86

lagom-2.4.1-cp37-cp37m-musllinux_1_1_x86_64.whl (239.2 kB view details)

Uploaded CPython 3.7mmusllinux: musl 1.1+ x86-64

lagom-2.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (244.2 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

lagom-2.4.1-cp37-cp37m-macosx_10_9_x86_64.whl (171.9 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: lagom-2.4.1-py3-none-any.whl
  • Upload date:
  • Size: 36.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2553029f10f3f1b2baafdb706429ff1158d1fa62f9d0468c931320b2ee00bb3
MD5 02ec3560c0d895ba8d77778f39d4eafb
BLAKE2b-256 42c70df14b4a1e729654f93b96828a99f48092d9245e082cccabe30abf5063f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 143.3 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 73e06147c38d94bbb267c92aaecfa035808ec80277f497f7ec41a9f4c1c8fa2e
MD5 9b509c1a722f0fdbe06a925414bc48a3
BLAKE2b-256 622a7b654ce81741291a8b253381414bae1ecb41060fc2b035388b1f8420a92e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp311-cp311-win32.whl
  • Upload date:
  • Size: 126.9 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.1-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 2085ee3f764823ffaf55a20da594b798ae8d148e460f392e8f2f5ca21973ae16
MD5 385de960a8be9d2a61e1f4b63b824c01
BLAKE2b-256 c74c17ccda66974d28d1f94305d77b18927781e4f23e1d4000a1187d1b6fdcd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 48234f48829969f5f0c254ebbf4c62b3ecb7851afd2a1e0b552f174ec9c06048
MD5 05edcd72beb25f030dc462a175482dfd
BLAKE2b-256 7896df09a46b2ac9e9936febb5a5fa775e496e6d33072336ab4ace87131530fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1264b97e503cda00c3c5afe8e214fc37bb5e7ed65167df6aab2b920ee7e2aca7
MD5 fb07f2e80ec22ffc2573101bf59cf36c
BLAKE2b-256 4776aa9a003c1c8741391c5ab2b358b820472f9293c712d0db3f44907916d8dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 143.7 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2d3658fbe63f307d5f4a1f74b7ac6ba4a3c6c8eedd89e83cdff54a7b0748c151
MD5 df08140fdac8629fd4931854ef37fbd7
BLAKE2b-256 f37aad31006215200ae6d8eef8da1017fce7b8d58055fc7ab60581f063743d36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp310-cp310-win32.whl
  • Upload date:
  • Size: 127.3 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.1-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 752cab3bdce90da77597dec9ec7b9dfb8bc3b82bef03479a513aae27e23e9576
MD5 edd87b740030784bc353cedba05453a8
BLAKE2b-256 915d230a926c5a6f31332010da5de0ede2fe566aeaad1286a69a74ae14c9a14e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 01b82415eaca5514faa904fdf2011aa01b660622ff51ff22ec1a517aafca3eb9
MD5 2cec4ff5d0a8f0ecaa710de6660496fa
BLAKE2b-256 b8cc78ba331ece4ed5e86491be89d95a69eb01d1be55791d826f0eae38839b18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de4b7240cb37b406e891c1d481efafb83998b847982fd6c73446e98600ed032c
MD5 2428505625f3f402299501959fc82d23
BLAKE2b-256 dbb5eaac4b4eeb47f387261823e3dcc6e0923330af080a88b76ce255483d6072

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 143.6 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9b2167e4d96af5356de758c6e8d70c915e119a283357d216da49d08e4af7d17b
MD5 ce2e630141c61853ffe77db4fc8acd45
BLAKE2b-256 5f81732834f605ce647d773bff1bef4eedd716bdc650dc501a9a92c182c339a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp39-cp39-win32.whl
  • Upload date:
  • Size: 127.2 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.1-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 41120a472917b2e8965dfc04648b96a524d94f5632b22582b9c7e4c5e1caf3a2
MD5 10dd08b80779f078b10425dfe903bb4a
BLAKE2b-256 ac750027e75a9274e3028d4ed09ac8858322d580cbe590df438e2b8ce76023e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e7bd9ec259168e5561a968baf8c2e35e7aee78a92e12243adb62a423e33490a0
MD5 933cb74a678846a3f5d4a13faef3dee1
BLAKE2b-256 e131745ad9e156b5379ed3bb43dfd5e7a6a4e5bab08c3911510c45d6374abb4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01294cf357accd35a1e4c0209892bd287269fa6d8e724a48695a0dc8b41b2c83
MD5 05365435ee40050b406abf9debafdd02
BLAKE2b-256 2269ea9a6d47e5610bb17582e161cc4cb0abcc20af215ed88299f15a6154726c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 80c712b0519e17a6608dbf5b8ea61e1f1a3815fdc69c8162a3872a1ac4a6b2ee
MD5 7a5a1905652ba99b60545c8e899240b1
BLAKE2b-256 b222bf4228e9939c90f48924f921431058fb5bb95b3679ff53cdbad0d6b7f55d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 142.8 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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b5223a5886f463f8e5f28ea3a6e863976bd3947951b184f2d096768928b69e2f
MD5 001534bc40b843578da4995788fa0dd5
BLAKE2b-256 a7c4089a9e58bf974ec47ad2ee80c2fb8f43fd13b6b5f53f62f667708826527e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp38-cp38-win32.whl
  • Upload date:
  • Size: 126.7 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.1-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 c0a5fa72256faba4cfa5df831874593178a5db128af093cbc8af149538b62757
MD5 2291a4ebba968fa43a24c6f088d983a0
BLAKE2b-256 721f668c94a634620c4bda9112c1ebfe1df7b2d7d7505bd57a47a914247fce0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 863ad16cb02d608ef8b42014742bc4778b87a5b535222299bbc969fe0b55005d
MD5 267bc74ac3681696864dcf13e36ff838
BLAKE2b-256 c6636bfaffc4a37e2eeeda4977e210b3e179e427388abab3ecc62e82bae295fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 22c8aa53c3afa0b87cb5eea20bb23c20fdb8748ebcaf7684971efe6b31981bc5
MD5 aa636992289322ff2e4208008ee9299e
BLAKE2b-256 32b14686c2a5623ba255a2b4c6f28915656ce3d967217bf00cb9915ea435eae1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f5b08c16769c99de02a92ad37dcb73a4e60401d8084f823de3e26325ef4c2049
MD5 352cd3b5095324c9cbf4ca6d41685c3e
BLAKE2b-256 5c369a63c608ca3df40bc587f2036d20c966736307083a65a94e47614da5221b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 138.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.4.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 1a6203b1c66d3247b83b2c086a87bc1a8dc095d2017dc65517ea6ac675739ea5
MD5 7310e9e2b8ef0ad54b51f5a6c3553c66
BLAKE2b-256 182235c2c91155ad5b83f09f92fb2ac4e5489d692347fadbbbb8d5613b6aeab8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.1-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 124.1 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.1-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 6f0c31369c3791184dd008545fadba9fa7a6fa6b82775f01f56da602bc124115
MD5 3e84c84cce0a0faea71063ce93d33b3a
BLAKE2b-256 85208eadcae0cde6f3df56c8a32aa2a2470e68c20dea1f995437c37e68508c58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d693edcf29e32a1d4e6b2605c5e469eeeafca45668d1f4aeaf513ad52524ae77
MD5 910d24aa4dfd13584f34a8f95f4e7dfd
BLAKE2b-256 042032524f71690dd98909817f5338183ada4bbdf890c7a361560593e60a86d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 292d30a0c193de05020850558a4d2e612be1f3a6d20d53a1ad03bed43dccff5c
MD5 aaa31aa931585fbe2c92dfc1e3a96156
BLAKE2b-256 53367481a0f93224e1d6e790bfed42241fdf27b4056051e91875bb664df6a188

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1a4f4ce2109e2a45d00e6a8f77365923a2a370f8035a8a96d749e9c92ba9678b
MD5 62208ce229b32ef9eafa6c44a889449b
BLAKE2b-256 7031239568eee850c6e4fb28f5c7e076df9d5558c3d260640356bbff9136ad89

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