Skip to main content

A simple Python library for processing data through a stream

Project description

py_simpledataflow

A simple Pyhton library for processing stream data using a logical sequence of functions.

Use cases

Transform, select, remove... data from a generator by a sequence of functions.

Installation

poetry add py_simpledataflow
# or
pip install py_simpledataflow
# or
pipenv install py_simpledataflow

Quick start

Example:

During run, the steps are in this order:

  1. Initialization
    • This part is used to initialize the flow context.
      • This part is useful to open database connexion, files or something like that.
    • Only one time
    • Flow parameter: "fct_init"
      • Signature: "Optional[Union[Callable, List[Callable]]]"
    • If you use a list of functions, the functions are called in the list order
  2. Data loading
    • This part is used to return data, one by one
      • This function return one data by "yield" instruction
    • Only one time but return a generator
    • Flow parameter: "fct_load"
      • Signature: "Optional[Callable]"
  3. Filtering
    • This part is used to modify data
      • This is usefull to change the data value
      • By default, if a filter function return "None" value, the filter sequence is stopped for the data. This behavior could be change by init "continue_if_none" parameter.
    • One time per data
    • Flow parameter: "fct_filter"
      • Signature: "Optional[Union[Callable, List[Callable]]]"
    • If you use a list of functions, the functions are called in the list order
  4. Finalization
    • This part us used to finalize the flow context
      • This part is useful to close database connexion, files or something like that.
      • Usefull also to print report.
    • Only one time
    • Flow parameter: "fct_finalyze"
      • Signature: "Optional[Union[Callable, List[Callable]]]"
    • If you use a list of functions, the functions are called in the list order

Notes:

  • All parameters are optional;
  • All functions in parameters accept the "context: Dict". It's essential for initialization and finalization parts;
  • You could init context outside the flow and pass it to init class method by "context" parameter.

Code:

import json
from typing import Any, Dict, Generator

from pysimpledataflow.flow import Flow


def __init(context: Dict) -> None:
    context['mult'] = 2
    context['result'] = []


def __read_data_one_by_one(context: Dict) -> Generator[Dict[str, int], Any, None]:
    mult: int = context['mult']
    for i in range(10):
        yield {
            'num': i * mult,
        }


def __filter(data: Dict, context: Dict) -> None:
    context['result'].append(data['num'])


def __finalyze(context: Dict) -> None:
    print("final context:%s" % json.dumps(context, indent=2))


def test_flow_base() -> None:
    Flow(
        fct_init=__init,
        fct_load=__read_data_one_by_one,
        fct_filter=__filter,
        fct_finalyze=__finalyze,
    ).run()

Output:

final context:{
  "mult": 2,
  "result": [
    0,
    2,
    4,
    6,
    8,
    10,
    12,
    14,
    16,
    18
  ]
}

Examples

See tests for variants:

  • Without init function
  • Multiple init functions
  • Without filter function
  • With a context initialized before run flow
  • Multiple filter functions
  • With modulo functions
  • Without load function

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

py_simpledataflow-0.1.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_simpledataflow-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file py_simpledataflow-0.1.3.tar.gz.

File metadata

  • Download URL: py_simpledataflow-0.1.3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.7 Linux/6.16.7-100.fc41.x86_64

File hashes

Hashes for py_simpledataflow-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6417f407bd4b6e46a27fe726b7931e1c4c93ee82c37b4f0bbaaaed5623daaab4
MD5 ca39051374ad37fc1240e152715ec13a
BLAKE2b-256 ba982adf82dfd4d6b2ba7146b11edc385aafd357be344762d6312faca5c0eeb3

See more details on using hashes here.

File details

Details for the file py_simpledataflow-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: py_simpledataflow-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.7 Linux/6.16.7-100.fc41.x86_64

File hashes

Hashes for py_simpledataflow-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7f4718d9693e722e6aaf1c1e09fa5027e81aa603209f4d2cd24ecc4bc6464f30
MD5 80302b97d5a1dc70ea15e0a4953f96ee
BLAKE2b-256 cf3842c297b5b97aaf605965410975a5399b13515df040af49e1c28ba10ad422

See more details on using hashes here.

Supported by

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