Python Dependency Injection Library
Project description
Wireup
Dependency Injection Container with a focus on developer experience, type safety and ease of use.
[!TIP] Simplify Dependency injection for Flask using the new Flask integration!
- Automatically inject dependencies without having to manually call autowire.
- Expose flask application configuration in the container.
⚡ Key Features
- Inject Services and Configuration
- Interfaces / Abstract classes
- Multiple Containers
- Static factories
- Singleton/Transient dependencies
- Framework Agnostic
- Simplified usage in Flask and FastAPI using the first-party integrations.
📋 Quickstart
Example showing a Database service, a repository and a web view which uses the repository to fetch all posts from a fictional blog db.
1. Register dependencies
from wireup import container
# Optionally wire parameters, they serve as configuration for services.
# Think of a database url or environment name.
container.params.update(existing_dict_config)
# Register a class as a service in the container.
@container.register
class DatabaseService:
# connection_url will contain the value of the parameter
# with the given name in the annotation.
def __init__(self, connection_url: Annotated[str, Wire(param="db_connection_url")]):
self.engine = create_engine(connection_url)
# Initializer injection is supported for regular classes as well as dataclasses.
@container.register
@dataclass
class PostRepository:
db: DatabaseService
def find_all(self) -> list[Post]:
return self.db.query...
2. Inject
@app.get("/posts")
@container.autowire
# Decorate all targets where the library must perform injection, such as views in an Api.
# Services are automatically injected based on annotated type.
# Optional for views when using flask or fastapi integration.
def get_posts(post_repository: PostRepository):
return post_repository.find_all()
Installation
# Install using poetry:
poetry add wireup
# Install using pip:
pip install wireup
📑 Documentation
For more information check out the documentation
🎮 Demo application
A demo flask application is available at maldoinc/wireup-demo
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wireup-0.7.0.tar.gz.
File metadata
- Download URL: wireup-0.7.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.10 Linux/5.4.0-125-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1934fdafb0acff400b2ed48f05627f75b0abd05c0bab316f3a12abd807f60de6
|
|
| MD5 |
d81ec3fa4418cf04ee32cc6c01d6a693
|
|
| BLAKE2b-256 |
fea6ee66e400e2cb08b1559e585c74a11ff5b7662137d89df3c8517e6c4b177b
|
File details
Details for the file wireup-0.7.0-py3-none-any.whl.
File metadata
- Download URL: wireup-0.7.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.10 Linux/5.4.0-125-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83ea127746c5783437f3146ff735302f500af8a402a701f5ddc15a558b7bcc5c
|
|
| MD5 |
d012e470e8d7e4933a39020c7a99d2fb
|
|
| BLAKE2b-256 |
7c8cfbd879670b14f20594e7bd46d1aec1b8ee29ffb30a6a74970580ef98b1d8
|