https://github.com/chriso345/pipette
Functional programming for Python
https://github.com/chriso345/pipette
currying functional-programming monads pipeline pipette pipette-fp python
Last synced: about 1 month ago
JSON representation
Functional programming for Python
- Host: GitHub
- URL: https://github.com/chriso345/pipette
- Owner: ChrisO345
- License: mit
- Created: 2025-08-06T10:40:37.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2025-08-09T10:08:34.000Z (about 2 months ago)
- Last Synced: 2025-08-09T12:09:52.762Z (about 2 months ago)
- Topics: currying, functional-programming, monads, pipeline, pipette, pipette-fp, python
- Language: Python
- Homepage: https://pypi.org/project/pipette-fp/
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# pipette
`pipette` is a lightweight, expressive Python library designed to enable clean, functional-style data processing pipelines with intuitive syntax and powerful composition.
Note that due to the limitations of Python's static typing, some features may not provide type hints as expected. However, the library is designed to be flexible and easy to use, even without strict type enforcement.
---
## Features
`pipette` is currently in early development, but it already includes:
- Lazy evaluation for efficient data processing.
- Support for custom transformations using the `@pipette` decorator.
- Core functional utilities like `select`, `where`, `reduce`, `sort_by`, and more.
- Currying support for partial function application.
- Basic monad implementation for chaining operations with error handling.---
## Installation
`pipette` can be installed via pip from the Python Package Index (PyPI):
```bash
pip install pipette-fp
```Alternatively, you can install the latest development version of `pipette` directly from GitHub:
```bash
pip install git+https://github.com/chriso345/pipette
```## Usage
`pipette` aims to make functional pipelines clear and concise.
```python
from pipette import where, select, intodata = [
{"active": True, "value": 10},
{"active": False, "value": 5},
{"active": True, "value": 7},
]result = (
data
| where(lambda x: x["active"])
| select(lambda x: x["value"])
| into(list)
)print(result) # Output: [10, 7]
```Custom transformations can easily be added to extend functionality:
```python
from pipette import pipette@pipette
def double(x):
return builtins.map(lambda n: n * 2, x)result = (
[1, 2, 3, 4]
| double
| into(list)
)print(result) # Output: [2, 4, 6, 8]
```### Curry
`pipette` provides a submodule for easy currying of functions:
```python
from pipette.curry import curry@curry
def add(x: int, y: int) -> int:
return x + yresult = add(2)(3)
print(result) # Output: 5result = add(2)
print(result(3)) # Output: 5
```Note, however, that python's static typing does not support currying and the type hints will error.
### Monads
`pipette` also includes a simple monad implementation for chaining operations:
```python
from pipette.monad import Maybe, Some, Nothingdef safe_divide(x, y) -> Maybe[float]:
if y == 0:
return Nothing()
else:
return Some(x / y)s = Some(10) >> (lambda x: safe_divide(x, 2)) | (lambda x: x + 1)
print(s) # Output: Some(6.0)n = Some(10) >> (lambda x: safe_divide(x, 0)) | (lambda x: x + 1)
print(n) # Output: Nothing
```Here `>>` binds the monad value to the function, and `|` provides a simple way to map the result to another function.
---
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.