Registry / data / pyfunctional

pyfunctional

JSON →
library1.5.0pypypi✓ verified 88d ago

PyFunctional is a Python package designed for creating data pipelines using a functional programming paradigm, inspired by Scala and Spark. It provides tools for chaining operations on sequences, supporting lazy evaluation, parallel processing, and various data transformations. The current version is 1.5.0, and the project generally focuses on API stability since its 1.0.0 release.

pip install pyfunctional
INSTALL
IMPORT
SIG · PYFUNCTIONAL
P
pyfunctional
datapythonv1.5.0
Install
1.7s avg
Import
283ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.292s · 19.4MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.7s · import 0.273s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

seq
✓ from functional import seq
Use `seq` for standard, lazy functional pipelines.
pseq
✓ from functional import pseq
Use `pseq` for pipelines that automatically leverage parallel processing for performance.

This example demonstrates creating a sequence, applying common functional transformations like `map` and `filter`, and finally aggregating results with `reduce`.

from functional import seq # Create a sequence from a range of numbers result = seq(range(10)) .map(lambda x: x * x) # Square each number .filter(lambda x: x > 10) # Keep numbers greater than 10 .reduce(lambda x, y: x + y, 0) # Sum the remaining numbers, starting with 0 print(result) # Expected output: 285
Debug
Known issues
breakingThe library was renamed from `ScalaFunctional` to `PyFunctional` in version 0.6.0. Projects using the old package name will need to update their `install_requires` and import paths.
fix
Update `pip install scalafunctional` to `pip install pyfunctional` and change `from scalafunctional import ...` to `from functional import ...`.
affects: <0.6.0
breakingThe behavior of `Sequence.zip_with_index` was modified in version 0.5.0. It no longer behaves as expected in previous versions and should be replaced.
fix
Replace calls to `Sequence.zip_with_index()` with Python's built-in `enumerate()` for equivalent functionality.
affects: <0.5.0
gotchaStarting from version 0.3.0, all operations in PyFunctional are lazy by default. This means transformations are not executed until an action (like `reduce`, `to_list`, `to_dict`, or iteration) consumes the sequence. This can lead to unexpected behavior if intermediate results are expected to be immediately available or if debugging relies on immediate evaluation.
fix
To force immediate evaluation for debugging or specific needs, append an action like `.to_list()` or `.to_dict()` at the point where you need the results.
affects: >=0.3.0
gotchaFor automatic parallelization of pipeline operations (e.g., `map`, `filter`), you must explicitly import and use `pseq` instead of `seq`. `seq` does not use parallel processing.
fix
If your pipeline operations are CPU-bound and you want to leverage multiple cores, ensure your pipeline starts with `from functional import pseq` and use `pseq(...)`.
affects: >=0.7.0
Errors
Common errors & fixes
NameError: name 'my_function' is not defined (when using pseq on Windows)
When using `pseq` (parallel sequence) with Python's `multiprocessing` module on Windows, functions (especially `lambda` functions or module-level functions not protected by `if __name__ == '__main__':`) are not correctly serialized and made available to child processes, leading to a `NameError` in the worker processes.
fix
Ensure that any functions used with `pseq` are defined within the `if __name__ == '__main__':` block in your main script, or are imported from a separate module that can be safely imported by worker processes. For `lambda` functions, consider defining them as top-level `def` functions if they need to be serialized across processes.
My PyFunctional chain isn't executing/producing output (lazy evaluation)
PyFunctional operations are designed to be lazy by default, meaning transformations like `map` and `filter` are not executed immediately. They only run when an 'action' (like `to_list()`, `reduce()`, `first()`, `all()`, or iterating over the sequence) is called to consume the results.
fix
To force the execution of the pipeline and get the results, append an action method to the end of your functional chain, such as `.to_list()`, `.to_dict()`, `.reduce()`, or iterate over the `seq` object.
TypeError: '...' object is not callable
This common Python error occurs when you try to call a variable or an object as if it were a function, but its type does not support being called. This can happen in PyFunctional if a chained operation returns a non-callable object (e.g., a simple data type) and the next operation in the chain implicitly tries to call it, or if `seq` is initialized with a non-iterable type.
fix
Review the type of the object at the point the `TypeError` is raised. Ensure that functions passed to `map`, `filter`, or other transformation methods are indeed callable, and that the arguments they receive are of the expected type. Also, ensure the input to `seq()` is an iterable.
ModuleNotFoundError: No module named 'functional' or AttributeError: module 'functional' has no attribute 'seq'
The `ModuleNotFoundError` indicates that the `pyfunctional` package is not installed or not accessible in your Python environment. The `AttributeError` typically means that while the `functional` module might be found, the specific `seq` object (or `pseq`) is not being imported correctly or is not directly exposed as an attribute of the top-level `functional` module if a different import style is used.
fix
To fix `ModuleNotFoundError`, install the package using `pip install pyfunctional`. To fix `AttributeError` for `seq` or `pseq`, ensure you are using the correct import statement: `from functional import seq` for standard pipelines or `from functional import pseq` for parallel processing.
Upgrade
Version history
1.5.0latest on PyPI · released Mar 13, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
16
OpenAI (training)
1
Resources
pyfunctional — pip install pyfunctional · libregistry