--- id: lagom version: "2.7.7" 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) license_treatment: permissive maintenance: active --- # lagom — Lagom is a dependency injection container designed to give you 'just enough' help with building your dependencies. License: permissive · Maintenance: active · Downloads: 338.1K/mo ## 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 above — 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 pip install lagom uv add lagom poetry add lagom ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 338.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags dependency injection container, type-based dependency injection, python di framework, auto-wiring dependencies, inversion of control container, lightweight ioc, type hints dependency resolver, dependency-injection, type-hints, ioc-container [View on SkillFed](https://skillfed.io/packages/lagom) · [View on PyPI](https://pypi.org/project/lagom/)