Skip to main content

service object flow orchestrator

Project description

service-flow

A small, simple, and elegant component/function orchestration framework for Python, service-flow enables separation of a functionality into single-responsibility and bite-size functions/service objects, which are testable and reuseable. It further helps with readability and maintainability of the embedding application.

Implementation

service-flow has two parts -- a flow and multiple services (Note: the word service here refers to a function, not RESTful services):

flow

a flow is the definition of processing procedure. It is defined as the following:

simple example

stack = Service1() >> \ 
        Service2(*args) >> \ 
        ... 
        ServiceN(**kwargs) 
        
output = stack(input) ## input is a dictionary with all the input parameters as attributes

Python >> operator is overloaded to define the sequeunce of the processing. Service1(), ..., ServiceN() are instances of the services, or functions.

for each processing of the input, service-flow creates a context, a dictionary-like object that serves as input and gather outputs from all the services.

fork example

stack = Service1() >> \ 
        Service2(*args) < \ 
        ('context_var_name', {
            'var_value1': (Service3() >> Service4(**kwargs)),
            'var_value2': (Service5() >> Service4(**kwargs)),
          }
        ) 
        
output = stack(input) ## input is a dictionary with all the input parameters as attributes

Python < operator is overloaded to define a fork in processing. In this example, context_var_name is the name of context key, and var_value1, var_value2 are potential values for forking.

services

A service is the equivalent of a Python function.

example

class InplaceModification(Middleware):
    def __init__(self, increment): # initialization
        self.increment = 1

    def __call__(self, bar: list): # service call 
        return {'bar': [i + self.increment for i in bar]}

conventions

It needs to follow the convention below:

initializaition parameters

parameters that initializes the service and is shared for all the calls to the service.

function parameters

these are used to call a service and have to be existing attributes in the context object.

return value

the return value of a service is optional. If a service does return values:

  1. if it is a dictionary, it will add/update the aforementioned processing context.
  2. otherwise, the return value is ignored and a warning message is logged.

inspiration

service-flow draws inspiration from the following Ruby projects:

  1. Rack
  2. Light Service
  3. Ruby Middleware

TODOs

install

pip install service-flow

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

service_flow-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

service_flow-0.1.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file service_flow-0.1.2.tar.gz.

File metadata

  • Download URL: service_flow-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.0

File hashes

Hashes for service_flow-0.1.2.tar.gz
Algorithm Hash digest
SHA256 06ca80fa90f20a51a340f1ae04966cec91b6794358a93d0a24d6e62974b07464
MD5 1d5abeb865c57e8b2acc9c62e0bcb88a
BLAKE2b-256 f225c9d1a4e4e65c9f7cca8b69b1b67087cfbb7c8c828d0611fcaa38fe1b0cd4

See more details on using hashes here.

File details

Details for the file service_flow-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: service_flow-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.0

File hashes

Hashes for service_flow-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b963c82a3484aa7b3ba4ee72583f93e22168e1af1c78fb58624e90dea12d3eb9
MD5 ff7b4c996b2c58c1960adc2cd3773cff
BLAKE2b-256 9cb9a8f2f3bf3aa29a4d97d7ba671fca807f34d133a4191b260a2c7305d69d9a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page