<div align="center">
<h1>Wireup</h1>
<p>Dependency Injection Container with a focus on developer experience, type safety and ease of use.</p>
[![GitHub](https://img.shields.io/github/license/maldoinc/wireup)](https://github.com/maldoinc/wireup)
[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/maldoinc/wireup/run_all.yml)](https://github.com/maldoinc/wireup)
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/maldoinc/wireup?label=Code+Climate)](https://codeclimate.com/github/maldoinc/wireup)
[![Coverage](https://img.shields.io/codeclimate/coverage/maldoinc/wireup?label=Coverage)](https://codeclimate.com/github/maldoinc/wireup)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/wireup)](https://pypi.org/project/wireup/)
[![PyPI - Version](https://img.shields.io/pypi/v/wireup)](https://pypi.org/project/wireup/)
</div>
> [!TIP]
> Simplify Dependency injection for Flask using the new
[Flask integration](https://maldoinc.github.io/wireup/latest/integrations/flask)!
>
> * 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](https://maldoinc.github.io/wireup/latest/integrations/flask/)
and [FastApi](https://maldoinc.github.io/wireup/latest/integrations/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**
```python
from wireup import container
# Optionally wire parameters, they serve as configuration for services.
# Think of a database url or environment name.
container.params.update(app.config.items())
# 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**
```python
@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**
```bash
# Install using poetry:
poetry add wireup
# Install using pip:
pip install wireup
```
## 📑 Documentation
For more information [check out the documentation](https://maldoinc.github.io/wireup)
## 🎮 Demo application
A demo flask application is available at [maldoinc/wireup-demo](https://github.com/maldoinc/wireup-demo)
Raw data
{
"_id": null,
"home_page": "https://github.com/maldoinc/wireup",
"name": "wireup",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "flask, django, injector, dependency injection, dependency injection container, dependency injector",
"author": "Aldo Mateli",
"author_email": "aldo.mateli@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/66/11/53f4ef166727a1dd439528c3ad9e83ab4d9329db6b5f66db4018ebe0ec3f/wireup-0.7.2.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n<h1>Wireup</h1>\n<p>Dependency Injection Container with a focus on developer experience, type safety and ease of use.</p>\n\n[![GitHub](https://img.shields.io/github/license/maldoinc/wireup)](https://github.com/maldoinc/wireup)\n[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/maldoinc/wireup/run_all.yml)](https://github.com/maldoinc/wireup)\n[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/maldoinc/wireup?label=Code+Climate)](https://codeclimate.com/github/maldoinc/wireup)\n[![Coverage](https://img.shields.io/codeclimate/coverage/maldoinc/wireup?label=Coverage)](https://codeclimate.com/github/maldoinc/wireup)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/wireup)](https://pypi.org/project/wireup/)\n[![PyPI - Version](https://img.shields.io/pypi/v/wireup)](https://pypi.org/project/wireup/)\n</div>\n\n> [!TIP]\n> Simplify Dependency injection for Flask using the new\n[Flask integration](https://maldoinc.github.io/wireup/latest/integrations/flask)!\n>\n> * Automatically inject dependencies without having to manually call autowire.\n> * Expose flask application configuration in the container.\n\n---\n\n## \u26a1 Key Features\n* Inject Services and Configuration\n* Interfaces / Abstract classes\n* Multiple Containers \n* Static factories\n* Singleton/Transient dependencies\n* Framework Agnostic\n* Simplified usage in \n[Flask](https://maldoinc.github.io/wireup/latest/integrations/flask/) \nand [FastApi](https://maldoinc.github.io/wireup/latest/integrations/fastapi/) using the first-party integrations.\n\n## \ud83d\udccb Quickstart\n\nExample showing a Database service, a repository and a web view which uses the repository to fetch all posts \nfrom a fictional blog db.\n\n**1. Register dependencies**\n\n```python\nfrom wireup import container\n\n# Optionally wire parameters, they serve as configuration for services. \n# Think of a database url or environment name.\ncontainer.params.update(app.config.items())\n\n\n# Register a class as a service in the container.\n@container.register \nclass DatabaseService:\n # connection_url will contain the value of the parameter \n # with the given name in the annotation.\n def __init__(self, connection_url: Annotated[str, Wire(param=\"db_connection_url\")]):\n self.engine = create_engine(connection_url)\n\n \n# Initializer injection is supported for regular classes as well as dataclasses.\n@container.register\n@dataclass\nclass PostRepository:\n db: DatabaseService \n\n def find_all(self) -> list[Post]:\n return self.db.query...\n```\n\n**2. Inject**\n\n```python\n@app.get(\"/posts\")\n@container.autowire \n# Decorate all targets where the library must perform injection, such as views in an Api.\n# Services are automatically injected based on annotated type.\n# Optional for views when using flask or fastapi integration.\ndef get_posts(post_repository: PostRepository):\n return post_repository.find_all()\n```\n\n**Installation**\n\n```bash\n# Install using poetry:\npoetry add wireup\n\n# Install using pip:\npip install wireup\n```\n\n## \ud83d\udcd1 Documentation\n\nFor more information [check out the documentation](https://maldoinc.github.io/wireup)\n\n## \ud83c\udfae Demo application\n\nA demo flask application is available at [maldoinc/wireup-demo](https://github.com/maldoinc/wireup-demo)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python Dependency Injection Library",
"version": "0.7.2",
"project_urls": {
"Homepage": "https://github.com/maldoinc/wireup"
},
"split_keywords": [
"flask",
" django",
" injector",
" dependency injection",
" dependency injection container",
" dependency injector"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "83b71a8dfd666661699f559eadfcf0e9c8d7eb3e48084baae0514a15f5dddab1",
"md5": "5ea131218e479131254f61d7c818f57c",
"sha256": "5bb989895e41d80aa3aba1197d31ff253c7a61d1b74d230763761b0228a0fce8"
},
"downloads": -1,
"filename": "wireup-0.7.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5ea131218e479131254f61d7c818f57c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 22663,
"upload_time": "2024-04-07T19:52:09",
"upload_time_iso_8601": "2024-04-07T19:52:09.488480Z",
"url": "https://files.pythonhosted.org/packages/83/b7/1a8dfd666661699f559eadfcf0e9c8d7eb3e48084baae0514a15f5dddab1/wireup-0.7.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "661153f4ef166727a1dd439528c3ad9e83ab4d9329db6b5f66db4018ebe0ec3f",
"md5": "fdd2160323201ec6442fc13d28d3aba5",
"sha256": "1732c3e6e3fb1c81b5df79d93062f9ab7b22a0c6219c2c213c92201f5eb564a6"
},
"downloads": -1,
"filename": "wireup-0.7.2.tar.gz",
"has_sig": false,
"md5_digest": "fdd2160323201ec6442fc13d28d3aba5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 18598,
"upload_time": "2024-04-07T19:52:11",
"upload_time_iso_8601": "2024-04-07T19:52:11.536045Z",
"url": "https://files.pythonhosted.org/packages/66/11/53f4ef166727a1dd439528c3ad9e83ab4d9329db6b5f66db4018ebe0ec3f/wireup-0.7.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-07 19:52:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "maldoinc",
"github_project": "wireup",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "wireup"
}