pyioc3


Namepyioc3 JSON
Version 1.6.1 PyPI version JSON
download
home_pagehttps://github.com/en0/pyioc
SummaryPython IOC Container
upload_time2023-09-29 04:19:30
maintainer
docs_urlNone
authorIan Laird
requires_python
license
keywords oop ioc dependency injection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyioc3

Python Inversion of Control (IoC) Container

# About

pyioc3 is a lightweight and versatile Inversion of Control (IoC) container for
Python. It simplifies the management of dependencies and enables cleaner, more
modular code by promoting the use of Dependency Injection (DI) patterns. With
pyioc3, you can effortlessly wire up your application's components, specify
their lifecycles, and inject dependencies without the hassle of manual
instantiation.

# Key Features

## Multiple APIs

pyioc3 offers multiple configuration interfaces including two manual
configuration APIs and a decorator-based autowiring API. These APIs are
flexible, yet simple to use.

## Fluent Interface

pyioc3 manual APIs support method chaining to minimize boiler-plate code and
intermediate variables.

## Scoped Lifecycles

pyioc3 supports various scopes, including Singleton, Transient, and Requested.
This provides fine-grained control of the lifecycle of your objects.

## Predictability

pyioc3 is an immutable ioc container that guarentees predictability of the
dependency tree.

## Constuctor Based DI

pyioc3 implements constructor based dependency injection making it easy to drop
into existing applications.

## Performance

pyioc3 pre-computes the dependency tree, resulting in fast instantiations to
keep your code fast.

## OOP Principles

pyioc3 is designed to improve the maintainability, testability, and flexibility
of your Python applications.

# Quick Start

Install the package

```bash
pip install --user pyioc3
```

## StaticContainerBuilder API

```python
from pyioc3 import StaticContainerBuilder

container = (
    StaticContainerBuilder()
    .bind(Duck)
    .bind(QuackProvider, Squeak)
    .build()
)

duck = container.get(Duck)
duck.quack()
```

## BuilderBase API

```python
from pyioc3.builder import BuilderBase, ProviderBinding

class DuckBuilder(Duck):
    def __init__(self):
        super().__init__(target_t=Duck)

    def with_quack_noise(self, noise: str) -> "DuckBuilder":
        self.using_provider(
            annotation=QuackProvider,
            implementation=DynamicQuackProvider,
            on_activate=lambda x: x.set_quack_noise(noise)
        )
        return self

rubber_duck = (
    DuckBuilder()
    .with_quack_noise("Squeak")
    .build()
)

rubber_duck.quack()
```

## Annotation API

```python
from pyioc3.autowire import bind, AutoWireContainerBuilder


class QuackProvider:
    def quack(self):
        raise NotImplementedError()


@bind()
class Duck:
    def __init__(self, quack: QuackProvider):
        self._quack = quack

    def quack(self):
        self._quack.quack()


@bind(QuackProvider)
class Squeak(QuackProvider):

    def quack(self):
        print("Squeak")


duck = AutoWireContainerBuilder("my_package").build().get(Duck)
duck.quack()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/en0/pyioc",
    "name": "pyioc3",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "OOP IoC Dependency Injection",
    "author": "Ian Laird",
    "author_email": "irlaird@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/32/d1/bf50544f5466e47bda0f2b5018a51138e2837390ffa07d35b8ac85a9874c/pyioc3-1.6.1.tar.gz",
    "platform": null,
    "description": "# pyioc3\n\nPython Inversion of Control (IoC) Container\n\n# About\n\npyioc3 is a lightweight and versatile Inversion of Control (IoC) container for\nPython. It simplifies the management of dependencies and enables cleaner, more\nmodular code by promoting the use of Dependency Injection (DI) patterns. With\npyioc3, you can effortlessly wire up your application's components, specify\ntheir lifecycles, and inject dependencies without the hassle of manual\ninstantiation.\n\n# Key Features\n\n## Multiple APIs\n\npyioc3 offers multiple configuration interfaces including two manual\nconfiguration APIs and a decorator-based autowiring API. These APIs are\nflexible, yet simple to use.\n\n## Fluent Interface\n\npyioc3 manual APIs support method chaining to minimize boiler-plate code and\nintermediate variables.\n\n## Scoped Lifecycles\n\npyioc3 supports various scopes, including Singleton, Transient, and Requested.\nThis provides fine-grained control of the lifecycle of your objects.\n\n## Predictability\n\npyioc3 is an immutable ioc container that guarentees predictability of the\ndependency tree.\n\n## Constuctor Based DI\n\npyioc3 implements constructor based dependency injection making it easy to drop\ninto existing applications.\n\n## Performance\n\npyioc3 pre-computes the dependency tree, resulting in fast instantiations to\nkeep your code fast.\n\n## OOP Principles\n\npyioc3 is designed to improve the maintainability, testability, and flexibility\nof your Python applications.\n\n# Quick Start\n\nInstall the package\n\n```bash\npip install --user pyioc3\n```\n\n## StaticContainerBuilder API\n\n```python\nfrom pyioc3 import StaticContainerBuilder\n\ncontainer = (\n    StaticContainerBuilder()\n    .bind(Duck)\n    .bind(QuackProvider, Squeak)\n    .build()\n)\n\nduck = container.get(Duck)\nduck.quack()\n```\n\n## BuilderBase API\n\n```python\nfrom pyioc3.builder import BuilderBase, ProviderBinding\n\nclass DuckBuilder(Duck):\n    def __init__(self):\n        super().__init__(target_t=Duck)\n\n    def with_quack_noise(self, noise: str) -> \"DuckBuilder\":\n        self.using_provider(\n            annotation=QuackProvider,\n            implementation=DynamicQuackProvider,\n            on_activate=lambda x: x.set_quack_noise(noise)\n        )\n        return self\n\nrubber_duck = (\n    DuckBuilder()\n    .with_quack_noise(\"Squeak\")\n    .build()\n)\n\nrubber_duck.quack()\n```\n\n## Annotation API\n\n```python\nfrom pyioc3.autowire import bind, AutoWireContainerBuilder\n\n\nclass QuackProvider:\n    def quack(self):\n        raise NotImplementedError()\n\n\n@bind()\nclass Duck:\n    def __init__(self, quack: QuackProvider):\n        self._quack = quack\n\n    def quack(self):\n        self._quack.quack()\n\n\n@bind(QuackProvider)\nclass Squeak(QuackProvider):\n\n    def quack(self):\n        print(\"Squeak\")\n\n\nduck = AutoWireContainerBuilder(\"my_package\").build().get(Duck)\nduck.quack()\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python IOC Container",
    "version": "1.6.1",
    "project_urls": {
        "Homepage": "https://github.com/en0/pyioc"
    },
    "split_keywords": [
        "oop",
        "ioc",
        "dependency",
        "injection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f129037a8b325c0d01405aa99cfe4d1d400ac98f14fd330fccb4db7a117880fc",
                "md5": "f3ceba50c8608d0aaeaab0a38052d168",
                "sha256": "820fa6f951383ab90372fa32d387f3a471d03eb23caa89501f3b058f65b3bd00"
            },
            "downloads": -1,
            "filename": "pyioc3-1.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f3ceba50c8608d0aaeaab0a38052d168",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 20321,
            "upload_time": "2023-09-29T04:19:29",
            "upload_time_iso_8601": "2023-09-29T04:19:29.141512Z",
            "url": "https://files.pythonhosted.org/packages/f1/29/037a8b325c0d01405aa99cfe4d1d400ac98f14fd330fccb4db7a117880fc/pyioc3-1.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "32d1bf50544f5466e47bda0f2b5018a51138e2837390ffa07d35b8ac85a9874c",
                "md5": "7fd8be4dedc5a73911f746055084bbe1",
                "sha256": "8067651f3830caf930303381e3606b96d346632a3ec821b03e21850e34e9e5e1"
            },
            "downloads": -1,
            "filename": "pyioc3-1.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7fd8be4dedc5a73911f746055084bbe1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19876,
            "upload_time": "2023-09-29T04:19:30",
            "upload_time_iso_8601": "2023-09-29T04:19:30.682406Z",
            "url": "https://files.pythonhosted.org/packages/32/d1/bf50544f5466e47bda0f2b5018a51138e2837390ffa07d35b8ac85a9874c/pyioc3-1.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-29 04:19:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "en0",
    "github_project": "pyioc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyioc3"
}
        
Elapsed time: 2.13645s