python-injection


Namepython-injection JSON
Version 0.14.0.post0 PyPI version JSON
download
home_pageNone
SummaryFast and easy dependency injection framework.
upload_time2025-02-23 11:23:03
maintainerNone
docs_urlNone
authorremimd
requires_python<4,>=3.12
licenseMIT
keywords dependencies dependency inject injection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python-injection

[![CI](https://github.com/100nm/python-injection/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/python-injection)
[![PyPI](https://img.shields.io/pypi/v/python-injection.svg?color=blue)](https://pypi.org/project/python-injection)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Fast and easy dependency injection framework.

## Installation

⚠️ _Requires Python 3.12 or higher_

```bash
pip install python-injection
```

## Motivations

1. Easy to use
2. No impact on class and function definitions
3. Easily interchangeable dependencies _(depending on the runtime environment, for example)_
4. No prerequisites

## Quick start

Simply apply the decorators and the package takes care of the rest.

```python
from injection import injectable, inject, singleton

@singleton
class Printer:
    def __init__(self):
        self.history = []

    def print(self, message: str):
        self.history.append(message)
        print(message)

@injectable
class Service:
    def __init__(self, printer: Printer):
        self.printer = printer

    def hello(self):
        self.printer.print("Hello world!")

@inject
def main(service: Service):
    service.hello()

if __name__ == "__main__":
    main()
```

## Resources

> ⚠️ The package isn't threadsafe, for better performance in single-threaded applications and those using `asyncio`.
> So remember to use `threading.Lock` if you're writing a multithreaded program.

* [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)
* [**Scoped dependencies**](https://github.com/100nm/python-injection/tree/prod/documentation/scoped-dependencies.md)
* [**Testing**](https://github.com/100nm/python-injection/tree/prod/documentation/testing.md)
* [**Advanced usage**](https://github.com/100nm/python-injection/tree/prod/documentation/advanced-usage.md)
* [**Utils**](https://github.com/100nm/python-injection/tree/prod/documentation/utils.md)
* [**Integrations**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations.md)
* [**Concrete example**](https://github.com/100nm/python-injection-example)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-injection",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.12",
    "maintainer_email": null,
    "keywords": "dependencies, dependency, inject, injection",
    "author": "remimd",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/96/36/3aeec661556ba9f15323f2315091329b5f2f873a64203a8cc11f8aece1b0/python_injection-0.14.0.post0.tar.gz",
    "platform": null,
    "description": "# python-injection\n\n[![CI](https://github.com/100nm/python-injection/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/python-injection)\n[![PyPI](https://img.shields.io/pypi/v/python-injection.svg?color=blue)](https://pypi.org/project/python-injection)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\nFast and easy dependency injection framework.\n\n## Installation\n\n\u26a0\ufe0f _Requires Python 3.12 or higher_\n\n```bash\npip install python-injection\n```\n\n## Motivations\n\n1. Easy to use\n2. No impact on class and function definitions\n3. Easily interchangeable dependencies _(depending on the runtime environment, for example)_\n4. No prerequisites\n\n## Quick start\n\nSimply apply the decorators and the package takes care of the rest.\n\n```python\nfrom injection import injectable, inject, singleton\n\n@singleton\nclass Printer:\n    def __init__(self):\n        self.history = []\n\n    def print(self, message: str):\n        self.history.append(message)\n        print(message)\n\n@injectable\nclass Service:\n    def __init__(self, printer: Printer):\n        self.printer = printer\n\n    def hello(self):\n        self.printer.print(\"Hello world!\")\n\n@inject\ndef main(service: Service):\n    service.hello()\n\nif __name__ == \"__main__\":\n    main()\n```\n\n## Resources\n\n> \u26a0\ufe0f The package isn't threadsafe, for better performance in single-threaded applications and those using `asyncio`.\n> So remember to use `threading.Lock` if you're writing a multithreaded program.\n\n* [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)\n* [**Scoped dependencies**](https://github.com/100nm/python-injection/tree/prod/documentation/scoped-dependencies.md)\n* [**Testing**](https://github.com/100nm/python-injection/tree/prod/documentation/testing.md)\n* [**Advanced usage**](https://github.com/100nm/python-injection/tree/prod/documentation/advanced-usage.md)\n* [**Utils**](https://github.com/100nm/python-injection/tree/prod/documentation/utils.md)\n* [**Integrations**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations.md)\n* [**Concrete example**](https://github.com/100nm/python-injection-example)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fast and easy dependency injection framework.",
    "version": "0.14.0.post0",
    "project_urls": {
        "Repository": "https://github.com/100nm/python-injection"
    },
    "split_keywords": [
        "dependencies",
        " dependency",
        " inject",
        " injection"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3c609ec38bee149dad780e441315c298b3573ce334dfbf0da616480928d4861d",
                "md5": "05fd5113f703010c8c68e523202fd462",
                "sha256": "f9099f7452076b334136b33d8a9c8bf11f9b01ddf7ad7c41363d3620b5ea08f5"
            },
            "downloads": -1,
            "filename": "python_injection-0.14.0.post0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "05fd5113f703010c8c68e523202fd462",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.12",
            "size": 23287,
            "upload_time": "2025-02-23T11:23:02",
            "upload_time_iso_8601": "2025-02-23T11:23:02.248420Z",
            "url": "https://files.pythonhosted.org/packages/3c/60/9ec38bee149dad780e441315c298b3573ce334dfbf0da616480928d4861d/python_injection-0.14.0.post0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "96363aeec661556ba9f15323f2315091329b5f2f873a64203a8cc11f8aece1b0",
                "md5": "f7e87b9bfc9a057b25a14597bb83af83",
                "sha256": "562f173280e37d97580233021cf42381f1d107fbc078f2c0633079a8b0523937"
            },
            "downloads": -1,
            "filename": "python_injection-0.14.0.post0.tar.gz",
            "has_sig": false,
            "md5_digest": "f7e87b9bfc9a057b25a14597bb83af83",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.12",
            "size": 19233,
            "upload_time": "2025-02-23T11:23:03",
            "upload_time_iso_8601": "2025-02-23T11:23:03.932306Z",
            "url": "https://files.pythonhosted.org/packages/96/36/3aeec661556ba9f15323f2315091329b5f2f873a64203a8cc11f8aece1b0/python_injection-0.14.0.post0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-23 11:23:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "100nm",
    "github_project": "python-injection",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-injection"
}
        
Elapsed time: 6.56651s