lagom
Lagom is a dependency injection container designed to give you 'just enough' help with building your dependencies.
What it is and what it does
Lagom is a dependency injection container that uses Python type hints to automatically construct and wire dependencies with minimal configuration. Most of your application code remains unaware of the container; Lagom is invoked only at the top level to assemble the dependency graph. It supports type-based auto-wiring where the container inspects `__init__` method type annotations and recursively builds instances, explicit singleton registration, lambda-based factory functions, and decorators for integrating with web frameworks and async code.
The design philosophy emphasizes minimal intrusion into existing code—you don't need to modify your classes to use Lagom, only to add type hints if you want auto-wiring. It's thread-safe at runtime and fully integrated with mypy for static type checking, making it suitable for both small scripts and larger applications that need structured dependency management without heavyweight framework overhead.
Use it for:
- Auto-wire dependencies in a web application by registering handler functions with the container and letting it inject services based on type hints.
- Manage expensive-to-create singleton instances (database connections, caches) by registering them once and reusing across the application.
- Gradually introduce dependency injection into an existing codebase by adding type hints to constructors without refactoring the rest of the code.
- Build testable code by swapping real dependencies with mocks in test containers without modifying production classes.
- Structure async Python applications where coroutines need injected dependencies resolved at startup.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Lagom is a lightweight dependency injection container that auto-wires dependencies based on type hints, requiring zero configuration for most use cases.
Yes. Lagom is a solid choice for projects needing lightweight dependency injection without framework overhead. Zero runtime dependencies, active maintenance, broad Python version support, and a permissive MIT license make it low-risk. The type-hint-based design integrates well with modern Python tooling. Best suited for teams comfortable with type annotations and seeking minimal configuration; not necessary for very small scripts but valuable for any structured application.
Install
lagom on PyPI
pip
pip install lagomuv
uv add lagompoetry
poetry add lagomInstalling lagom
Before you install
Low install friction with no runtime dependencies. Actively maintained with a recent release (394 days ago) and ongoing commits; supports Python 3.7 through 3.13.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
Quickstart
pip install lagom
from lagom import Container
class MyDataSource:
pass
class SomeClass:
def __init__(self, datasource: MyDataSource):
self.datasource = datasource
container = Container()
instance = container[SomeClass]
Verify before relying
- Performance characteristics and overhead compared to manual dependency management or other DI frameworks.
- Scope of framework integrations beyond the mentioned web framework hooks.
- Thread-safety guarantees under concurrent container access patterns.
Package facts
| License | The MIT License (MIT) Copyright (c) 2019 Steve Brazier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 394 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 338,072/month — #7,439 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: lagom-2.7.7-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
dependency-injectorDependency Injector is a dependency injection…
permissive · top 5,000 on PyPI
wireupWireup is a type-driven dependency injection…
permissive · top 15,000 on PyPI
in-n-outLightweight dependency injection framework…
permissive · top 15,000 on PyPI
kinkKink is a lightweight dependency injection…
permissive · top 15,000 on PyPI
rodiRodi is a dependency injection container for…
permissive · top 15,000 on PyPI
simple-diA strictly typed dependency injection library…
permissive · top 15,000 on PyPI
injectorInjector is a Python dependency injection…
permissive · top 5,000 on PyPI
dependenciesImplements constructor injection for dependency…
permissive · top 15,000 on PyPI
slackA dependency injection container that registers…
permissive · top 15,000 on PyPI
allukaAlluka is a type-based dependency injection…
permissive · top 15,000 on PyPI