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.0b4-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11Windows x86

lagom-2.4.0b4-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.0b4-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.0b4-cp310-cp310-win_amd64.whl (143.0 kB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10Windows x86

lagom-2.4.0b4-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.0b4-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.0b4-cp39-cp39-win_amd64.whl (142.9 kB view details)

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9Windows x86

lagom-2.4.0b4-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.0b4-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.0b4-cp39-cp39-macosx_10_9_x86_64.whl (181.1 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8Windows x86

lagom-2.4.0b4-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.0b4-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.0b4-cp38-cp38-macosx_10_9_x86_64.whl (178.5 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.7mWindows x86

lagom-2.4.0b4-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.0b4-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

lagom-2.4.0b4-cp37-cp37m-macosx_10_9_x86_64.whl (171.4 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 e16e247eb7c42346ce82305f8140e32099a722a014532786266edd5e68d207b2
MD5 78e72ec2360a86e2b03780e7afd5ed40
BLAKE2b-256 d1ada4c624471228694eac39d603bc1056482bc712411fc840037da0727d1f82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fe7eaac5b5cabf52f5d861461914fef256c2bd62f41c7e5bb8221b10fa8cbc86
MD5 bf8d6e01534e9658aa1b9a661d38b7b3
BLAKE2b-256 44e181d0357ef4cf4f836c89b2a32291ed60a93bbc295d62591d582648a1b2f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 07c51e45ff372caf1a8feaf2c6daec863aa61b2ac6805cbd4e66c63fb7958ce9
MD5 b82b4921bb5dc33e1f5d0887338cc788
BLAKE2b-256 43fe69ed9b6c5e963ed04bbf4d03f4fb9fe9187d9d791e086064abdcb44ee1b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c9ffff8720c75d6157e675d3fcac2ae4c8d5e8c48a78e6c92975549948b15e5c
MD5 cae8080a4ec3e146ccd52a90e263053a
BLAKE2b-256 cfcea9eefb6044b358b74616ad08a88797ebdf38feee0cca51a5e26c44674ee2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b383ff952067a3996f0949b7288bd5e8363b182bfd05c204111311e2f55aeb03
MD5 beb69ed3fb7b0d569a6be285a9799920
BLAKE2b-256 bffa303b536e7a60c0c3a83a3ff227edb29b14c2031337fb64038cb334a8ec04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6fc097999d8df61197604be8b63e257d6241f80e20ec74bc9944b33afb98feff
MD5 1590ddfa103dd4050d678fc80788cb6b
BLAKE2b-256 59ae022c0b720f7078df906c98c37ad2d1b640764fda3d9398e1ec5f396ba0e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 1fb6155f42b3b38c87662ea77cc7d9b3873fd52d6aa8694b5ebc42472f995cc1
MD5 18fcf6ba20eba6767a0fb448b0d3018b
BLAKE2b-256 3e3c98fdd3e97b7df2c3df65c702f4fb729ad131152c1ad849a11fbc3a3f6e2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e49d39e22b8a69b796c6f9f5ff931568436e371d9097489276d5df2d36818d9c
MD5 1d3d9b72faa8f80c82edbd9bb28b3313
BLAKE2b-256 305b7fc21a547c6540eec63d2fded1da96aaefaa7063fba09fc87ef742fd1ef8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e802c8baf19896c43eb783ce55e7a45d04e6182b1a7881b103a1caec54d8c37
MD5 ce5bc685d7a7a584790157599111367c
BLAKE2b-256 56cd870a5e6625082f99276ff61f4907bab7ec5d8823495e9b6fa1009661d5a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8b2a999a8025094e35b8f28e8c97b7ef62ce12cd593da2a40e27313c1a8e6794
MD5 a89dc9aaf71046d49a06eb14625d53e3
BLAKE2b-256 423c8f57211a87af220bcfbdfe3d5bda19846e27b20ae81f2545394bb2096553

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 8565d7423ae34f2589efc26d9f81da808164e0aca157e463ddaed10e4ae53108
MD5 1372b980d0a0a905a8e49f1c9ec3d6f8
BLAKE2b-256 b466ab36bea1c6c0e430190138da9d76908524e58bdc68030d783902f9130097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e39b785c66e0903cfe7a18d9147add7b4a29b452a76c1d21a75bcbc3fdc54c0f
MD5 05aca736cfcb12cd65d697c581d6d0ff
BLAKE2b-256 2bcb6476a3e12ff928a0eebd1ba85e607a5efe111fa07659b7cd800d4be52bc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 badece2d26876b616977a84fe26aa9453ecd969f4e1697f18f08b399c1c5bdfd
MD5 0ba5f29b194e36fd852de6adc1589092
BLAKE2b-256 4406485901137615cbc6a296c16d84c27d651d59ca85804451f7be48d91212e0

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b4-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e7e6e60526f72d0dbe213facde05983fd549040f4a5bb4e1124feed5b73c3814
MD5 69b38b91b13f30ec6bd9049e662f8286
BLAKE2b-256 1dbe8897611d03d28a36756f79620ea76221be2cda5bfcc87d344b1820d219e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 bca09c4a244c3b1c66b0cf08c36c4eeb8f8d9e45a150c31ffd7ff20e7d12dea5
MD5 6ed156d2985c3268b26d01e4fff23f03
BLAKE2b-256 5f75dc4b550542fa25481223916095b979abdf09e58494f4765b44937d5c0ac6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 a422379877ecf20301bdea44f10e52171605e43f2bbef51c5aacfdb288cc926a
MD5 253e8f4f7474cafd0aab75199bfcd23b
BLAKE2b-256 5276b7a8b9bb27fb534eb785b59d178edc99ac107ba301a0c838c1e35100cc4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c0267f2b1aec08b4cff92e7687c742f66a7d3c8eb2d1a1a47d8387884f9560e1
MD5 6e9ce44a3fd6b89e0a05766da618a793
BLAKE2b-256 1bff214f6f1353a088fc08074f2bfab632c5e5350327889a6119372985855b2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 272c2f302bfb2ffdac3ff5ee66ecdcbb34ed9ebd038f26a707e1fea9650aa458
MD5 61911ff61ad32a388a51f80cce8c4bd0
BLAKE2b-256 1e4c3c040c092284fb15dea8ad6594e56aa63a362fd8ef17ccde2c500612a822

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b4-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a692bcba775e5c69d83c3264b7d1b4df708bce9152aa17cf71d4a35a6d9fd2fb
MD5 541b78631fa083c2d1bb0f59f69c5531
BLAKE2b-256 4ad5c2ce97a0df0d31560aa1883ff6468c19bd091c6e4111ce638a8d0265abdb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 bc3cd44d90a699205888533d99a2aafaff2039449e6e0c3851bdbed32070249a
MD5 5e80b25d33a64fa8d2c4de683661e7d9
BLAKE2b-256 467a13fb1ce7031fb8aea933bcad0bf657ce48648a928a30d191967d7c315f1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.4.0b4-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.0b4-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 2d1df7e3f25ce1a756ada8e9a22786359b878dc8623919439cb563cb408ec77a
MD5 beb6fca0c97167b1ecd49ba03b189f11
BLAKE2b-256 0d57de0247d1611aa2e35429ed5a821523246f8ff6f0977af3c78effc2af84d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 665c7c289b7abfdbcdfd927d346c5b4bca1bb258cfc0ac3cb8f01860f5e44827
MD5 f509fba02d8404886c5dc6d7e61b65d5
BLAKE2b-256 f91abebf76cb4a28f77fd324bd26e3a86b6986c691e530917541334931d3af77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e1ce137a50ddaca6e3a3b3eb95fb0df1806903f131b3fda5d9cbcd39057561da
MD5 7c77eede4a2b24abe384d0930e843718
BLAKE2b-256 dfe1a938699830ded55cceef573d4b3f72c828e0400fcdea1f1bfef274a6afb3

See more details on using hashes here.

File details

Details for the file lagom-2.4.0b4-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lagom-2.4.0b4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 404de22b3f26916eca30ed45070baae9f0460a120b5b17e0801b7bea6488928c
MD5 f97e74f0c2fc06f4cfbb31db776542d1
BLAKE2b-256 04d34535245c2f560650e52de927b633842e2b6201111b2264bc6bbccb545db5

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