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

lagom-2.6.0-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

lagom-2.6.0-cp311-cp311-win_amd64.whl (145.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

lagom-2.6.0-cp311-cp311-win32.whl (128.6 kB view details)

Uploaded CPython 3.11 Windows x86

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

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

lagom-2.6.0-cp310-cp310-win_amd64.whl (145.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 Windows x86

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

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 Windows x86

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

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9 macOS 10.9+ x86-64

lagom-2.6.0-cp38-cp38-win_amd64.whl (145.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

lagom-2.6.0-cp38-cp38-win32.whl (128.6 kB view details)

Uploaded CPython 3.8 Windows x86

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

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

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

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: lagom-2.6.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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59899f29319bfb9f3fa96f1834ae8ed2e25345e697bfff5a3da7aa0b84348978
MD5 04cfe9b39e239f55989070bb36913258
BLAKE2b-256 b7a50dcb62944d9b5b8399c4e3aa9b47f70391d25249fb64ae46731e87d9d9de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 145.6 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.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5f1409fa623a1b382fcbefe3067dbe6a569dc01ee59a1519f21bb107db08ce2f
MD5 7a31e74386b7cd5eb25e2c296aff9f6a
BLAKE2b-256 85d2e428478e2163651b22f66681bde2f8435f9a2f8861bc79d555be52126047

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 128.6 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.6.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 e8f635798cc8d5034c0ca2a8b7adf22a5f06de8e47067ba0f291c19e864e6beb
MD5 ebd4939cf0e1f96e8be0f1c57b84d6fd
BLAKE2b-256 a96d06cb649440501d393bfc11c9a6639bf5ec293cd1f4935e69e6d6fb104c89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 59c13d338982461dca7cf299e334d6d8e173dfa35c0e768b5c2267292456f067
MD5 4a16f51e5b4350281841a4d3052c61a6
BLAKE2b-256 b0c7605e7c87e8ca4d0bd93eb183d1267ed70d77e0010e946aba440054d8b79c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13fb5300823da3e46573b843729496760799d0d8ab1f1d26b06df15c0b1c0e38
MD5 f70afca8f6e297cfa3b8094c2a1ce1fb
BLAKE2b-256 631afe65e104cd620b36c5a9cca67fa804ac80897a4f2f4d8db1bdd582309e8e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 145.9 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.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 740c9189cdca713d61a94a33f0996f74e1920c2a66e4b215658c6001df1202f2
MD5 7226a79845d089ebb0788296c67a24b4
BLAKE2b-256 006c66a83779771a6ed88229e88ffff140e82a224e46f347c6b0f60fd314f50d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.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.6.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 add42bb4073b316f5106b0b2a658e59018cb336a97d1423bcd8275eb75d9a4f2
MD5 263b34da215c2ee6d7aa856e94367225
BLAKE2b-256 cf46e623362c0685cbe8d4572ee42330f78ee473e53b44373dcdccb69a1d5538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e80904469b2e7e34b5f7b62bdb149fc7ab3a7c725c3f8395be00e8b117907cea
MD5 b15e91df4f9d9373fb8e6a48d2fe5385
BLAKE2b-256 a7d9278f2c5bc625aecbee6b3a50448f1580866c65a51675df97cf2b6d24ac60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 39e715e316115d0873258de21ff30d456dcc5b1aad2b7f4c6b70a3b4830013c3
MD5 e00d2e9d0948fab5597f58079c21dc8d
BLAKE2b-256 5018f879f7340ace5160d747baa3130a7c2a39b2c5a05fbcc935bcd5c31aa6c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.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.6.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 649e45a9a852bb33e442c937e7caee81bf12393a5f1de508a9c78ef0adcec8a3
MD5 7e692714783c71c34f0c5ec57fda2244
BLAKE2b-256 bd90ba0668e320d5d61683c9a1b9d674a8a559bb4793d64f086b7563178c9529

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.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.6.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 715e87a4631a5a4b33f249a6734947391f4dfcb33e1256436c51f88045440bf1
MD5 cf0dab593ddf861f538d47243fd7e24e
BLAKE2b-256 4125d7e1466b23cb4155197f3f40d5e57d7593daa231cac5ca5cd9c71b557e03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0dc403d10a6689137de851a84e49ec0476b6cc6d04899e9d414e92dc9d9cd4cb
MD5 bbf0cd235711c9d6755a8db673496c68
BLAKE2b-256 e2ea448931ce6f30a81348d1a86b9262d6484d45059035da37888d8e5b9398fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e1643782bf5538a71b7e17cf8eca8164ca20af32e4aba49680532405448b24b
MD5 981a86bc0f2906f5958dd95744fda587
BLAKE2b-256 6897d03402698ef4840a7f1f960688d0c74afa0b53f0dcb300ffe20b45bb1d4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 77849fde197ec4dbc3d68487a9b0c9c1d6344eb405da4e65b365d35a508211ea
MD5 2d3fe914f075d2601406a4904d61feec
BLAKE2b-256 1f93f2c312db31df1a07d4becefe69581e41ab3047d0a0e2a11b5c60402ff89d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 145.2 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.6.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a51dbf7ce1f68bc175fcf87c82bf87b09db65c5ca37ab1d7447320019436a64a
MD5 7efeb1596c488153f2fefbe63cd91e52
BLAKE2b-256 dc8014af2f6e059883ffac2fb8441848943b28e948236922e465e206cb1df804

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-2.6.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 128.6 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.6.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 13f8b556ea43076f1851a6a58a12699c47d7b296d877c34a66ccd788e7ee75ea
MD5 3943cfb980d11058a9ebcdf4bf92a648
BLAKE2b-256 3ad450a65253254a078420566cd10ac116654e1a0a58ace8d607cfc7e9ebcbb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 363c16dc38fd94ab914b0daad6ad1096ea684d2f987417228c84de6caf49d3a6
MD5 adfbf50553abbd2122b2a260fd15f28c
BLAKE2b-256 082c3c7c0b42f0a1433803ed817256f957bb42f19ce753643f52c366e1b16437

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3fb07af7923b01aaed899b5cedcaf70ba6ddda0379387596b6f1f79b263bfbe0
MD5 3e1d6dc5fc08a97c9e8332834cf285af
BLAKE2b-256 ca8c8ce2028dbdab7cf7a8061619a360615da35e6414332d514cac3ec767f1a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lagom-2.6.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cd8e724f17bbdffb927fd551600a5d05e9e0ad738536101826b8f271c438ef81
MD5 42d1d33c1c4399f6ad2d98d09992b6c9
BLAKE2b-256 464d95550c15de674acaf3d5c2aa97e11c8987326af5b8a12ce44dc69dcb51e6

See more details on using hashes here.

Supported by

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