taipan-di


Nametaipan-di JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/Billuc/Taipan-DI
SummaryTruly Amazing Inversion of control Python library Analogous to .Net's DI
upload_time2023-06-22 15:31:25
maintainer
docs_urlNone
authorBilluc
requires_python>=3.9,<4.0
licenseMIT
keywords taipan dependency injection dependency python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Taipan-DI

Truly Amazing Inversion of control Python library Analogous to .Net's DI

Taipan-DI is a [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library whose goal is to provide a behaviour similar to [.Net's DI system](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection).


## Features

 - Lightweight
 - No decorators
 - No hidden behaviour (what you write is what you get)
 - Automatic dependency injection on service resolving
 - Type hinting
 - No global container by default
 - Singleton and factory scopes
 - Register pipelines easily


## Constraints

 - Based purely on types (not on strings)
 - No automatic registration


## Installation

### Pip

> `pip install taipan-di`

### Poetry

[Poetry](https://python-poetry.org/) is a Python dependency management and packaging tool. I actually use it for this project.

> `poetry add taipan-di`


## Usage

First, you have to create a `ServiceCollection` in which you will register your services. Each `ServiceCollection` is independant and contain different services.

```python
services = ServiceCollection()
```

Then, register your services as you wish. You can initiate registrations processes via 2 ways :

```python
services.register(Type)
services.register_pipeline(Type)
```

For "standard" registration, you have to first choose the scope and then how you wish the instances to be created. Examples :

```python
services.register(Type).as_factory().with_implementation(ChildType)
services.register(Type).as_singleton().with_self()
services.register(Type).as_singleton().with_instance(instance)
services.register(Type).as_factory().with_creator(lambda provider: create(provider))
```

For pipeline registration, all you have to do is add the links that constitute the pipeline and register it as a singleton or a factory. Example :

```python
services.register_pipeline(Type).add(Link1).add(Link2).as_factory()
```

Once your services are registered, you have to build a service provider which will be used to resolve services : 

```python
provider = services.build()
resolved = provider.resolve(Type)
```

If `Type` has a constructor dependency, it will be automatically resolved, as long as the dependency has been registered in the `ServiceCollection`.


## Inspirations

This library is partially based on the [*kink*](https://pypi.org/project/kink/) dependency injection library. I was using kink on another project previously but it didn't fit all my requirements and wishes.

I also took inspiration from the [*injector*](https://pypi.org/project/injector/) library and .Net's dependency injection system.


## TODO

This library isn't stable yet and a lot of things can still be improved.
If there is something you want to see added or if something does not work as you want it to, feel free to open an issue.

Here is a list of features I have in mind and will be working on :

 - Create configuration from environment or configuration files


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Billuc/Taipan-DI",
    "name": "taipan-di",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "taipan,dependency injection,dependency,python",
    "author": "Billuc",
    "author_email": "billuc@hotmail.fr",
    "download_url": "https://files.pythonhosted.org/packages/c8/d0/22eec4d7cda55dfe224ee6d7e0a5aadf7302aa8e1e97f89b8a8854597266/taipan_di-0.0.7.tar.gz",
    "platform": null,
    "description": "# Taipan-DI\n\nTruly Amazing Inversion of control Python library Analogous to .Net's DI\n\nTaipan-DI is a [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library whose goal is to provide a behaviour similar to [.Net's DI system](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection).\n\n\n## Features\n\n - Lightweight\n - No decorators\n - No hidden behaviour (what you write is what you get)\n - Automatic dependency injection on service resolving\n - Type hinting\n - No global container by default\n - Singleton and factory scopes\n - Register pipelines easily\n\n\n## Constraints\n\n - Based purely on types (not on strings)\n - No automatic registration\n\n\n## Installation\n\n### Pip\n\n> `pip install taipan-di`\n\n### Poetry\n\n[Poetry](https://python-poetry.org/) is a Python dependency management and packaging tool. I actually use it for this project.\n\n> `poetry add taipan-di`\n\n\n## Usage\n\nFirst, you have to create a `ServiceCollection` in which you will register your services. Each `ServiceCollection` is independant and contain different services.\n\n```python\nservices = ServiceCollection()\n```\n\nThen, register your services as you wish. You can initiate registrations processes via 2 ways :\n\n```python\nservices.register(Type)\nservices.register_pipeline(Type)\n```\n\nFor \"standard\" registration, you have to first choose the scope and then how you wish the instances to be created. Examples :\n\n```python\nservices.register(Type).as_factory().with_implementation(ChildType)\nservices.register(Type).as_singleton().with_self()\nservices.register(Type).as_singleton().with_instance(instance)\nservices.register(Type).as_factory().with_creator(lambda provider: create(provider))\n```\n\nFor pipeline registration, all you have to do is add the links that constitute the pipeline and register it as a singleton or a factory. Example :\n\n```python\nservices.register_pipeline(Type).add(Link1).add(Link2).as_factory()\n```\n\nOnce your services are registered, you have to build a service provider which will be used to resolve services : \n\n```python\nprovider = services.build()\nresolved = provider.resolve(Type)\n```\n\nIf `Type` has a constructor dependency, it will be automatically resolved, as long as the dependency has been registered in the `ServiceCollection`.\n\n\n## Inspirations\n\nThis library is partially based on the [*kink*](https://pypi.org/project/kink/) dependency injection library. I was using kink on another project previously but it didn't fit all my requirements and wishes.\n\nI also took inspiration from the [*injector*](https://pypi.org/project/injector/) library and .Net's dependency injection system.\n\n\n## TODO\n\nThis library isn't stable yet and a lot of things can still be improved.\nIf there is something you want to see added or if something does not work as you want it to, feel free to open an issue.\n\nHere is a list of features I have in mind and will be working on :\n\n - Create configuration from environment or configuration files\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Truly Amazing Inversion of control Python library Analogous to .Net's DI",
    "version": "0.0.7",
    "project_urls": {
        "Documentation": "https://github.com/Billuc/Taipan-DI",
        "Homepage": "https://github.com/Billuc/Taipan-DI",
        "Repository": "https://github.com/Billuc/Taipan-DI"
    },
    "split_keywords": [
        "taipan",
        "dependency injection",
        "dependency",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c7f831b049b109d3dcfbd2d89fb58148ab674a01bf5d456eba07697b441a5669",
                "md5": "4274fbd5fe57d045bff61bd9d8437498",
                "sha256": "06b715d9c936cb5a9ca22a197d7bb1302afb7d8aed4f9e0672904be04fa9eadd"
            },
            "downloads": -1,
            "filename": "taipan_di-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4274fbd5fe57d045bff61bd9d8437498",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 17247,
            "upload_time": "2023-06-22T15:31:23",
            "upload_time_iso_8601": "2023-06-22T15:31:23.675257Z",
            "url": "https://files.pythonhosted.org/packages/c7/f8/31b049b109d3dcfbd2d89fb58148ab674a01bf5d456eba07697b441a5669/taipan_di-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8d022eec4d7cda55dfe224ee6d7e0a5aadf7302aa8e1e97f89b8a8854597266",
                "md5": "b2081bbfd275a3cf8f06723aeafa77d6",
                "sha256": "0903eeae6983cd2aab046f13fa7074f8478469614ca04beef89929e6d1ec165a"
            },
            "downloads": -1,
            "filename": "taipan_di-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "b2081bbfd275a3cf8f06723aeafa77d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 9547,
            "upload_time": "2023-06-22T15:31:25",
            "upload_time_iso_8601": "2023-06-22T15:31:25.191086Z",
            "url": "https://files.pythonhosted.org/packages/c8/d0/22eec4d7cda55dfe224ee6d7e0a5aadf7302aa8e1e97f89b8a8854597266/taipan_di-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-22 15:31:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Billuc",
    "github_project": "Taipan-DI",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "taipan-di"
}
        
Elapsed time: 0.07914s