A simple Python library for processing data through a stream
Reason this release was yanked:
Bug in chained data flow. Use 0.1.3 instead
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:
- 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]]]"
- Signature: "
- If you use a list of functions, the functions are called in the list order
- This part is used to initialize the flow context.
- Data loading
- This part is used to return data, one by one
- This function return one data by "
yield" instruction
- This function return one data by "
- Only one time but return a generator
- Flow parameter: "
fct_load"- Signature: "
Optional[Callable]"
- Signature: "
- This part is used to return data, one by one
- 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]]]"
- Signature: "
- If you use a list of functions, the functions are called in the list order
- This part is used to modify data
- 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]]]"
- Signature: "
- If you use a list of functions, the functions are called in the list order
- This part us used to finalize the flow context
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_simpledataflow-0.1.2.tar.gz.
File metadata
- Download URL: py_simpledataflow-0.1.2.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Linux/6.14.9-200.fc41.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be5805da4dcf2f10484c0044f1732c759b6ccc4968bbb1bc75cf208d9d1e0cdf
|
|
| MD5 |
56a03d6ac394744744be9cf3ea0e2d73
|
|
| BLAKE2b-256 |
ec197027e2c2a981e311bc3298291f998ed6ecdd5bfc05b8c3a5490c00a8f276
|
File details
Details for the file py_simpledataflow-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py_simpledataflow-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Linux/6.14.9-200.fc41.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37a50601ad287642144e8acd8e1f629c1cfdc28a971d69612bd0b811561eff64
|
|
| MD5 |
0911f113dfc2cbf616e1d0f0d0dc7c98
|
|
| BLAKE2b-256 |
8cccb84a17b6b9966145bb640b0f639ba3c34bd96fd65bb24186d678774b79ba
|