
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Lagom is a dependency injection container designed to give you 'just enough' help with building your dependencies.
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.
You can see a comparison to other frameworks here
For users of python 3.7 and above this should require no changes. Full details can be found in the release notes upgrade instructions.
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
Everything in Lagom is based on types. To create an object you pass the type to the container:
container = Container()
some_thing = container[SomeClass]
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
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()
(There's also a few common framework integrations provided here)
Contributions are very welcome. Please see instructions here
FAQs
Lagom is a dependency injection container designed to give you 'just enough' help with building your dependencies.
We found that lagom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.