Picodi Documentation¶
Picodi is a straightforward and powerful Dependency Injection (DI) library for Python, designed to simplify managing dependencies in both synchronous and asynchronous applications.
Dependency Injection is a design pattern where an object receives its dependencies from an external source rather than creating them itself. Picodi helps you implement this pattern effectively, making your code more modular, testable, and maintainable.
Inspired by FastAPI’s DI system but usable in any Python project (framework-agnostic), Picodi offers:
Simplicity: Easy-to-understand API.
Flexibility: Works seamlessly in sync and async code.
Zero Dependencies: Lightweight and requires only Python.
Lifecycle Management: Control over dependency creation and cleanup using scopes and lifespans.
Testability: Built-in support for overriding dependencies in tests.
Whether you’re building a web application with FastAPI, a CLI tool, or any other Python project, Picodi can help you manage your dependencies cleanly.
Documentation¶
Getting Started
User Guide
Help & Info
- Frequently Asked Questions
- Q: I’m injecting an
async defdependency into adeffunction, but I get a coroutine object instead of the value. Why? - Q: When should I use
SingletonScopevs.NullScope? - Q: Why do I need
registry.shutdown()? When should I call it? - Q: Can I use Picodi without type hints?
- Q: How does Picodi compare to FastAPI’s built-in DI?
- Q: My tests are failing because of state leaking between them. What’s wrong?
- Q: flake8-bugbear complains about
B008 Do not perform function calls in argument defaultswhen usingProvide. How to fix it?
- Q: I’m injecting an