Tuyau
Tuyau is a library that allows you to process values through a sequence of steps, similar to a pipe.
# Before
for name in names:
len(hash(upper_case(decode(name))))
# After
tube = Tube(decode, upper_case, hash, len)
for name in names:
tube(name)
# or alternative
tube.send(name)
Installation
You can install Tuyau using pip:
pip install tuyau
Usage
Creating a Tuyau
To create a Tuyau, you can pass a sequence of callable steps to the constructor. Each step should be a callable that takes one argument and returns a value of any type.
from tuyau import Tube
def add_one(number: int) -> int:
"""Simple step: add one to the number."""
return number + 1
def multiply_by_two(number: int) -> int:
"""Simple step: multiply the number by two."""
return number * 2
tube = Tube(add_one, multiply_by_two)
print(tube.send(1)) # 4
Processing Values
You can process values through the Tuyau by calling it as if it were a function. The value will go through each step in the sequence and get transformed accordingly.
result = tube(5)
print(result) # Output: 12 (5 + 1 = 6, 6 * 2 = 12)
You can also use the send() method, which is an alias for calling the Tuyau directly.
result = tube.send(5)
print(result) # Output: 12
Example
Here's an example using lambda functions as steps:
tube = Tube(lambda x: x + 1, lambda x: x * 2)
result = tube(3)
print(result) # Output: 8 (3 + 1 = 4, 4 * 2 = 8)
Typing
Typing
The Tube class is designed to support typing for both input and output.
from tuyau import Tube
def add_one(num: int) -> int:
return num + 1
def multiply_by_two(num: int) -> int:
return num * 2
# Create Tube with multiple callables that take and return int
tube: Tube[int, int] = Tube(add_one, multiply_by_two)
tube: Tube[int, str] = Tube(add_one, multiply_by_two, str)
# Process integers through the tubes
result: int = tube(3)# Output: 6 (3 + 1 * 2)
result2: str = tube(3)# Output: "6" str(3 + 1 * 2)
Contributing
Contributions are welcome! If you find a bug or have a suggestion for improvement, please create an issue or a pull request on GitHub.
Local dev
install .venv with all dev dep
make dev-install
launch tests
make test
launch linters
make lint
License
This library is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for tuyau 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tuyau-1.2.tar.gz | 4.4 kB | Without provenance | Details for tuyau-1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tuyau-1.2-py3-none-any.whl | Python 3 | none | any | Details for tuyau-1.2-py3-none-any.whl |
Total release size: 9.0 kB
Release files / tuyau-1.2.tar.gz
| Download URL | tuyau-1.2.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b1ba39cd8dee1d5687c80a4e74c1b5b36388e5ad0e44c9bd01e6bd982b600bb
|
|
BLAKE2b-256 checksum How to use checksums |
b64d22d9edc683253f0631d71ecba1dc3be4241a6482a4c343d9a8dd94c81adf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / tuyau-1.2-py3-none-any.whl
| Download URL | tuyau-1.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0de76a83f7ec57d3fe6ee572da464ee8260523e9855793d9abf02a8976e39cc5
|
|
BLAKE2b-256 checksum How to use checksums |
48241805386374f188b2a71d50aee79763739a71453c588de2b9bdbb88bcb914
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for tuyau 1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.