Skip to main content

Lagom, a type based dependency injection container

Project description

Lagom - Dependency injection container

Build Status Scrutinizer Code Quality Code Coverage PyPI Downloads

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

  • Typed 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

Installation

pip install lagom
# or: 
# pipenv install lagom
# poetry add 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]

You can tell the container that something should be a singleton:

container[SomeExpensiveToCreateClass] = SomeExpensiveToCreateClass("up", "left")

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.

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()

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 Distribution

lagom-1.0.0b4.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

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

lagom-1.0.0b4-py2.py3-none-any.whl (22.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lagom-1.0.0b4.tar.gz.

File metadata

  • Download URL: lagom-1.0.0b4.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.0

File hashes

Hashes for lagom-1.0.0b4.tar.gz
Algorithm Hash digest
SHA256 75c28cf93d90f38bff85c785763119223ea44034f0bbc3e745e801bf91759da7
MD5 bedb3a94361894edff562986bc9d48e4
BLAKE2b-256 62defff5bebdfa49db43bd59108b211cf2b9c9fb6236c254ff797fa388fe4a50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lagom-1.0.0b4-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.0

File hashes

Hashes for lagom-1.0.0b4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cf51a1f165d5372ed4644f1d13898418d0261803dca5d87354cd710fae272b71
MD5 edaddb90e9be976007b83e43fd7c5fef
BLAKE2b-256 642ac7fd82c29042f8eb80338da15d0cd822a8d409367f5553debb7bbc98d8cd

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