conveyr


Nameconveyr JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/megafetis/mediatr_py
SummaryConveyor pipline handling library for python 3.5 and later
upload_time2020-12-14 14:58:11
maintainer
docs_urlNone
authorEvgeniy Fetisov
requires_python>=3.5
licenseMIT -or- Apache License 2.0
keywords conveyor conveyr chain handling mediator pipline behaviors saga chain pattern builder async conveyor architecture pattern
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # conveyr_py

[![PyPI](https://img.shields.io/pypi/v/conveyr)](https://pypi.org/project/mediatr)
[![Python](https://img.shields.io/pypi/pyversions/conveyr)](https://pypi.org/project/mediatr) 
[![Downloads](https://img.shields.io/pypi/dm/conveyr)](https://pypi.org/project/mediatr) 

Conveyor pipline handling library for python 3.5 and later

## Automatic implementation of pattern "Builder"

Requirements:
* Python >= 3.5

## Usage:
install [conveyr](https://pypi.org/project/conveyr/):

`pip install conveyr`

### Define common interfaces:

```py
from conveyr import Conveyor


#### define interfaces

```py
class IEntity():
    id=None

class IHasNameEntity():
    name = None

class IHasSurnameEntity():
    surname = None

class IHasDesctiptionEntity():
    description = None

class IHasAgeEntity():
    age=0
```

### Define payloads:

```py
class INamePayload:
    pass

class ISurnamePayload:
    pass

class IDescriptionPayload:
    pass

class IHasAgePayload():
    age=0
```

### Define concrete entity class an dpayload class:
```py
class Entity(IEntity,IHasNameEntity,IHasSurnameEntity,IHasDesctiptionEntity,IHasAgeEntity):
   pass

class Payload(INamePayload,ISurnamePayload,IDescriptionPayload,IHasAgePayload):
    def __init__(self,name,surname,description,age=0):
        self.name = name
        self.surname = surname
        self.description = description
        self.age = age
        
```
### Define handlers per interface:

```py
@Conveyor.handler(order=5)
async def entity_name_handler(entity:IHasNameEntity,payload:INamePayload):
    entity.name = payload.name

@Conveyor.handler(order=4)
def entity_surname_handler(entity:IHasSurnameEntity,payload:ISurnamePayload):
    entity.surname = payload.surname

@Conveyor.handler(order=3)
def entity_id_handler(entity:IEntity):
    entity.id = uuid.uuid4().hex

@Conveyor.handler(order=2)
def entity_description_handler(entity:IHasDesctiptionEntity,payload:IDescriptionPayload):
    entity.description = payload.description

#you can define class handler, wich contains `process` method
@Conveyor.handler(order=1)
class PersonAgeHandler:
    def process(self,entity:IHasAgeEntity,payload:IHasAgePayload):
        entity.age = payload.age

```
#### Run conveyor

simple mode:

```py 

conveyor = Conveyor()
entity = Entity()
payload = Payload('evgeniy','fetisov','some description',30)
results = conveyor.process(entity,payload)

```

>  `Conveyor.process_async` method supports to define `async` `await` handlers. In async mode you can define simple synchronous handlers too.

async mode:

```py 
import asyncio

conveyor = Conveyor()
loop = asyncio.get_event_loop()

entity = Entity()

payload = Payload('evgeniy','fetisov','some description',30)

results = loop.run_until_complete(conveyor.process_async(entity,payload)) 
loop.close()

#in python 3.6 and later: results = asyncio.run(conveyor.process_async(entity,payload))

```

```py
print(results) # dict of results if handlers returns anything
print(entity.id) # some guid id
print(entity.name) # 'evgeniy'
print(entity.surname) # 'fetisov'
print(entity.description) #'some description'
print(entity.age) # 30
```

### Static usage without Conveyor instance:

```py 

from conveyr import Conveyor

entity = Entity()
payload = Payload('evgeniy','fetisov','some description',30)
results = Conveyor.process(entity,payload)

```

### Advanced:

You can group handlers to several 'layers'

and manage handling orders
```py
@Conveyor.handler(order=5,group="aftercommit")
async def some_handler(entity:IHasNameEntity,payload:INamePayload):
    entity.name = payload.name
#...
results = loop.run_until_complete(conveyor.process(entity,payload,"aftercommit")) # handlers with such group only executed

```
If you are using class handlers, its possible to set custom class handler initializer (or dependency injector)

```py
def some_class_handler_manager(cls):
  return cls()

conveyr = Conveyor(class_handler_manager = some_class_handler_manager)

#...
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/megafetis/mediatr_py",
    "name": "conveyr",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "Conveyor,Conveyr,chain handling,Mediator,pipline,behaviors,saga,Chain,pattern builder,async conveyor,architecture pattern",
    "author": "Evgeniy Fetisov",
    "author_email": "me@efetisov.ru",
    "download_url": "https://files.pythonhosted.org/packages/2b/94/73d1f2fc6647c0170913b30e10f4ef41a57e64f1a20de70aaf54aa830e49/conveyr-1.1.0.tar.gz",
    "platform": "",
    "description": "# conveyr_py\n\n[![PyPI](https://img.shields.io/pypi/v/conveyr)](https://pypi.org/project/mediatr)\n[![Python](https://img.shields.io/pypi/pyversions/conveyr)](https://pypi.org/project/mediatr) \n[![Downloads](https://img.shields.io/pypi/dm/conveyr)](https://pypi.org/project/mediatr) \n\nConveyor pipline handling library for python 3.5 and later\n\n## Automatic implementation of pattern \"Builder\"\n\nRequirements:\n* Python >= 3.5\n\n## Usage:\ninstall [conveyr](https://pypi.org/project/conveyr/):\n\n`pip install conveyr`\n\n### Define common interfaces:\n\n```py\nfrom conveyr import Conveyor\n\n\n#### define interfaces\n\n```py\nclass IEntity():\n    id=None\n\nclass IHasNameEntity():\n    name = None\n\nclass IHasSurnameEntity():\n    surname = None\n\nclass IHasDesctiptionEntity():\n    description = None\n\nclass IHasAgeEntity():\n    age=0\n```\n\n### Define payloads:\n\n```py\nclass INamePayload:\n    pass\n\nclass ISurnamePayload:\n    pass\n\nclass IDescriptionPayload:\n    pass\n\nclass IHasAgePayload():\n    age=0\n```\n\n### Define concrete entity class an dpayload class:\n```py\nclass Entity(IEntity,IHasNameEntity,IHasSurnameEntity,IHasDesctiptionEntity,IHasAgeEntity):\n   pass\n\nclass Payload(INamePayload,ISurnamePayload,IDescriptionPayload,IHasAgePayload):\n    def __init__(self,name,surname,description,age=0):\n        self.name = name\n        self.surname = surname\n        self.description = description\n        self.age = age\n        \n```\n### Define handlers per interface:\n\n```py\n@Conveyor.handler(order=5)\nasync def entity_name_handler(entity:IHasNameEntity,payload:INamePayload):\n    entity.name = payload.name\n\n@Conveyor.handler(order=4)\ndef entity_surname_handler(entity:IHasSurnameEntity,payload:ISurnamePayload):\n    entity.surname = payload.surname\n\n@Conveyor.handler(order=3)\ndef entity_id_handler(entity:IEntity):\n    entity.id = uuid.uuid4().hex\n\n@Conveyor.handler(order=2)\ndef entity_description_handler(entity:IHasDesctiptionEntity,payload:IDescriptionPayload):\n    entity.description = payload.description\n\n#you can define class handler, wich contains `process` method\n@Conveyor.handler(order=1)\nclass PersonAgeHandler:\n    def process(self,entity:IHasAgeEntity,payload:IHasAgePayload):\n        entity.age = payload.age\n\n```\n#### Run conveyor\n\nsimple mode:\n\n```py \n\nconveyor = Conveyor()\nentity = Entity()\npayload = Payload('evgeniy','fetisov','some description',30)\nresults = conveyor.process(entity,payload)\n\n```\n\n>  `Conveyor.process_async` method supports to define `async` `await` handlers. In async mode you can define simple synchronous handlers too.\n\nasync mode:\n\n```py \nimport asyncio\n\nconveyor = Conveyor()\nloop = asyncio.get_event_loop()\n\nentity = Entity()\n\npayload = Payload('evgeniy','fetisov','some description',30)\n\nresults = loop.run_until_complete(conveyor.process_async(entity,payload)) \nloop.close()\n\n#in python 3.6 and later: results = asyncio.run(conveyor.process_async(entity,payload))\n\n```\n\n```py\nprint(results) # dict of results if handlers returns anything\nprint(entity.id) # some guid id\nprint(entity.name) # 'evgeniy'\nprint(entity.surname) # 'fetisov'\nprint(entity.description) #'some description'\nprint(entity.age) # 30\n```\n\n### Static usage without Conveyor instance:\n\n```py \n\nfrom conveyr import Conveyor\n\nentity = Entity()\npayload = Payload('evgeniy','fetisov','some description',30)\nresults = Conveyor.process(entity,payload)\n\n```\n\n### Advanced:\n\nYou can group handlers to several 'layers'\n\nand manage handling orders\n```py\n@Conveyor.handler(order=5,group=\"aftercommit\")\nasync def some_handler(entity:IHasNameEntity,payload:INamePayload):\n    entity.name = payload.name\n#...\nresults = loop.run_until_complete(conveyor.process(entity,payload,\"aftercommit\")) # handlers with such group only executed\n\n```\nIf you are using class handlers, its possible to set custom class handler initializer (or dependency injector)\n\n```py\ndef some_class_handler_manager(cls):\n  return cls()\n\nconveyr = Conveyor(class_handler_manager = some_class_handler_manager)\n\n#...\n```",
    "bugtrack_url": null,
    "license": "MIT -or- Apache License 2.0",
    "summary": "Conveyor pipline handling library for python 3.5 and later",
    "version": "1.1.0",
    "split_keywords": [
        "conveyor",
        "conveyr",
        "chain handling",
        "mediator",
        "pipline",
        "behaviors",
        "saga",
        "chain",
        "pattern builder",
        "async conveyor",
        "architecture pattern"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "a0ddd37f8be4cc3670c6e3aae9c36485",
                "sha256": "64ee20f1fdb2697b1906e8baaa2792b2504f507f93d96acc95a727ccadc05497"
            },
            "downloads": -1,
            "filename": "conveyr-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a0ddd37f8be4cc3670c6e3aae9c36485",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 5104,
            "upload_time": "2020-12-14T14:58:11",
            "upload_time_iso_8601": "2020-12-14T14:58:11.584615Z",
            "url": "https://files.pythonhosted.org/packages/2b/94/73d1f2fc6647c0170913b30e10f4ef41a57e64f1a20de70aaf54aa830e49/conveyr-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-12-14 14:58:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "megafetis",
    "error": "Could not fetch GitHub repository",
    "lcname": "conveyr"
}
        
Elapsed time: 0.15493s