tuyau


Nametuyau JSON
Version 1.2 PyPI version JSON
download
home_page
SummaryTuyau is a library that allows you to process values through a sequence of steps, similar to a pipe.
upload_time2023-08-03 15:44:45
maintainer
docs_urlNone
author
requires_python>=3.10
licenseMIT License Copyright (c) 2023 Guillaume Pouyat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords pipe tube tuyau
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Tuyau

[![Version](https://img.shields.io/badge/version-1.2-blue.svg)](https://github.com/guiforge/tuyau)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Tuyau is a library that allows you to process values through a sequence of steps, similar to a pipe.

```python
# 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:

```bash
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.

```python
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.

```python
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.

```python
result = tube.send(5)
print(result)  # Output: 12
```

### Example

Here's an example using lambda functions as steps:

```python
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. 

```python
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](https://github.com/guiforge/tuyau).

### 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](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "tuyau",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "pipe,tube,tuyau",
    "author": "",
    "author_email": "Guillaume Pouyat <guillaume.pouyat@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b6/4d/22d9edc683253f0631d71ecba1dc3be4241a6482a4c343d9a8dd94c81adf/tuyau-1.2.tar.gz",
    "platform": null,
    "description": "# Tuyau\n\n[![Version](https://img.shields.io/badge/version-1.2-blue.svg)](https://github.com/guiforge/tuyau)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nTuyau is a library that allows you to process values through a sequence of steps, similar to a pipe.\n\n```python\n# Before \nfor name in names:\n    len(hash(upper_case(decode(name))))\n\n# After\ntube = Tube(decode, upper_case, hash, len)\n\nfor name in names:\n    tube(name)\n\n# or alternative\ntube.send(name)\n```\n\n## Installation\n\nYou can install Tuyau using pip:\n\n```bash\npip install tuyau\n```\n\n## Usage\n\n### Creating a Tuyau\n\nTo 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.\n\n```python\nfrom tuyau import Tube\n\ndef add_one(number: int) -> int:\n    \"\"\"Simple step: add one to the number.\"\"\"\n    return number + 1\n\ndef multiply_by_two(number: int) -> int:\n    \"\"\"Simple step: multiply the number by two.\"\"\"\n    return number * 2\n\ntube = Tube(add_one, multiply_by_two)\nprint(tube.send(1)) # 4\n```\n\n### Processing Values\n\nYou 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.\n\n```python\nresult = tube(5)\nprint(result)  # Output: 12 (5 + 1 = 6, 6 * 2 = 12)\n```\n\nYou can also use the `send()` method, which is an alias for calling the Tuyau directly.\n\n```python\nresult = tube.send(5)\nprint(result)  # Output: 12\n```\n\n### Example\n\nHere's an example using lambda functions as steps:\n\n```python\ntube = Tube(lambda x: x + 1, lambda x: x * 2)\n\nresult = tube(3)\nprint(result)  # Output: 8 (3 + 1 = 4, 4 * 2 = 8)\n```\n## Typing\n## Typing\n\nThe `Tube` class is designed to support typing for both input and output. \n\n```python\nfrom tuyau import Tube\n\ndef add_one(num: int) -> int:\n    return num + 1\n\ndef multiply_by_two(num: int) -> int:\n    return num * 2\n\n# Create Tube with multiple callables that take and return int\ntube: Tube[int, int] = Tube(add_one, multiply_by_two)\ntube: Tube[int, str] = Tube(add_one, multiply_by_two, str)\n\n# Process integers through the tubes\nresult: int = tube(3)# Output: 6 (3 + 1 * 2) \nresult2: str = tube(3)# Output: \"6\" str(3 + 1 * 2) \n```\n\n## Contributing\n\nContributions are welcome! If you find a bug or have a suggestion for improvement, please create an issue or a pull request on [GitHub](https://github.com/guiforge/tuyau).\n\n### Local dev\ninstall .venv with all dev dep  \n`make dev-install`  \n\nlaunch tests  \n`make test`\n\nlaunch linters  \n`make lint`\n\n## License\n\nThis library is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Guillaume Pouyat  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Tuyau is a library that allows you to process values through a sequence of steps, similar to a pipe.",
    "version": "1.2",
    "project_urls": {
        "Homepage": "https://github.com/Guiforge/tuyau"
    },
    "split_keywords": [
        "pipe",
        "tube",
        "tuyau"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "48241805386374f188b2a71d50aee79763739a71453c588de2b9bdbb88bcb914",
                "md5": "21587a8551d1b403e3ac11b5e238d6a1",
                "sha256": "0de76a83f7ec57d3fe6ee572da464ee8260523e9855793d9abf02a8976e39cc5"
            },
            "downloads": -1,
            "filename": "tuyau-1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "21587a8551d1b403e3ac11b5e238d6a1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 4530,
            "upload_time": "2023-08-03T15:44:43",
            "upload_time_iso_8601": "2023-08-03T15:44:43.269939Z",
            "url": "https://files.pythonhosted.org/packages/48/24/1805386374f188b2a71d50aee79763739a71453c588de2b9bdbb88bcb914/tuyau-1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b64d22d9edc683253f0631d71ecba1dc3be4241a6482a4c343d9a8dd94c81adf",
                "md5": "25efa3fcb22532d38dca9625d39b6415",
                "sha256": "7b1ba39cd8dee1d5687c80a4e74c1b5b36388e5ad0e44c9bd01e6bd982b600bb"
            },
            "downloads": -1,
            "filename": "tuyau-1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "25efa3fcb22532d38dca9625d39b6415",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 4429,
            "upload_time": "2023-08-03T15:44:45",
            "upload_time_iso_8601": "2023-08-03T15:44:45.029378Z",
            "url": "https://files.pythonhosted.org/packages/b6/4d/22d9edc683253f0631d71ecba1dc3be4241a6482a4c343d9a8dd94c81adf/tuyau-1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-03 15:44:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Guiforge",
    "github_project": "tuyau",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "tuyau"
}
        
Elapsed time: 0.12254s