mo-streams


Namemo-streams JSON
Version 1.680.25062 PyPI version JSON
download
home_pagehttps://github.com/klahnakoski/mo-streams
SummaryMore Streams! Chained function calls
upload_time2025-03-03 00:10:06
maintainerNone
docs_urlNone
authorKyle Lahnakoski
requires_pythonNone
licenseMPL 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # More Streams!!

[![PyPI Latest Release](https://img.shields.io/pypi/v/mo-streams.svg)](https://pypi.org/project/mo-streams/)
 [![Build Status](https://github.com/klahnakoski/mo-streams/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/klahnakoski/mo-streams/actions/workflows/build.yml)
 [![Coverage Status](https://coveralls.io/repos/github/klahnakoski/mo-streams/badge.svg?branch=dev)](https://coveralls.io/github/klahnakoski/mo-streams?branch=dev)
[![Downloads](https://static.pepy.tech/badge/mo-streams/month)](https://pepy.tech/project/mo-streams)


Python code is more elegant with method chaining!


## Overview

There are two families of "streams" in this library, both are lazy:

1. `ByteStream` - a traditional stream of bytes intended to pipe bytes through various byte transformers, like compression, encoding and encyrption.  
2. `ObjectStream`: An iterator/generator with a number of useful methods.

### Example

In this case I am iterating through all files in a tar and parsing them:

    results = (
        File("tests/so_queries/so_queries.tar.zst")
        .content()
        .content()
        .exists()
        .utf8()
        .to_str()
        .map(parse)
        .to_list()
    )
    
 Each of the steps constructs a generator, and no work is done until the last step
 
 
 * `File().content()` - will unzst and untar the file content to an `ObjectStream` of file-like objects.  It is short form for `stream(File().read_bytes()).from_zst().from_tar()`
 * The second `.content()` is applied to each of the file-like objects, returning `ByteStream` of the content for each
 * `.exists()` - some of the files (aka directories) in the tar file do not have content, we only include content that exists.
 * `.utf8` - convert to a `StringStream`
 * `.to_str` - convert to a Python `str`, we trust the content is not too large
 * `.map(parse)` - run the parser on each string
 * `.to_list()` - a "terminator", which executes the chain and returns a Python `list` with the results
 
## Project Status

Alive and in use, but 

* basic functions missing
* inefficient - written using generators
* generators not properly closed


## Optional Reading

The method chaining style has two distinct benefits

* functions are in the order they are applied 
* intermediate values need no temporary variables

The detriments are the same that we find in any declarative language: Incorrect code can be difficult to debug because you can not step through it to isolate the problem.  For this reason, the majority of the code in this library is dedicated to validating the links in the function chain before they are run.

### Lessons

The function chaining style, called "streams" in Java or "linq" in C#, leans heavly on the strict typed nature of those langauges.  This is missing in Python, but type annotations help support this style of programming.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klahnakoski/mo-streams",
    "name": "mo-streams",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Kyle Lahnakoski",
    "author_email": "kyle@lahnakoski.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/cf/533f29855813eb006467de21890d37adfb11b9329faa7a065e7f559391fd/mo_streams-1.680.25062.tar.gz",
    "platform": null,
    "description": "# More Streams!!\r\n\r\n[![PyPI Latest Release](https://img.shields.io/pypi/v/mo-streams.svg)](https://pypi.org/project/mo-streams/)\r\n [![Build Status](https://github.com/klahnakoski/mo-streams/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/klahnakoski/mo-streams/actions/workflows/build.yml)\r\n [![Coverage Status](https://coveralls.io/repos/github/klahnakoski/mo-streams/badge.svg?branch=dev)](https://coveralls.io/github/klahnakoski/mo-streams?branch=dev)\r\n[![Downloads](https://static.pepy.tech/badge/mo-streams/month)](https://pepy.tech/project/mo-streams)\r\n\r\n\r\nPython code is more elegant with method chaining!\r\n\r\n\r\n## Overview\r\n\r\nThere are two families of \"streams\" in this library, both are lazy:\r\n\r\n1. `ByteStream` - a traditional stream of bytes intended to pipe bytes through various byte transformers, like compression, encoding and encyrption.  \r\n2. `ObjectStream`: An iterator/generator with a number of useful methods.\r\n\r\n### Example\r\n\r\nIn this case I am iterating through all files in a tar and parsing them:\r\n\r\n    results = (\r\n        File(\"tests/so_queries/so_queries.tar.zst\")\r\n        .content()\r\n        .content()\r\n        .exists()\r\n        .utf8()\r\n        .to_str()\r\n        .map(parse)\r\n        .to_list()\r\n    )\r\n    \r\n Each of the steps constructs a generator, and no work is done until the last step\r\n \r\n \r\n * `File().content()` - will unzst and untar the file content to an `ObjectStream` of file-like objects.  It is short form for `stream(File().read_bytes()).from_zst().from_tar()`\r\n * The second `.content()` is applied to each of the file-like objects, returning `ByteStream` of the content for each\r\n * `.exists()` - some of the files (aka directories) in the tar file do not have content, we only include content that exists.\r\n * `.utf8` - convert to a `StringStream`\r\n * `.to_str` - convert to a Python `str`, we trust the content is not too large\r\n * `.map(parse)` - run the parser on each string\r\n * `.to_list()` - a \"terminator\", which executes the chain and returns a Python `list` with the results\r\n \r\n## Project Status\r\n\r\nAlive and in use, but \r\n\r\n* basic functions missing\r\n* inefficient - written using generators\r\n* generators not properly closed\r\n\r\n\r\n## Optional Reading\r\n\r\nThe method chaining style has two distinct benefits\r\n\r\n* functions are in the order they are applied \r\n* intermediate values need no temporary variables\r\n\r\nThe detriments are the same that we find in any declarative language: Incorrect code can be difficult to debug because you can not step through it to isolate the problem.  For this reason, the majority of the code in this library is dedicated to validating the links in the function chain before they are run.\r\n\r\n### Lessons\r\n\r\nThe function chaining style, called \"streams\" in Java or \"linq\" in C#, leans heavly on the strict typed nature of those langauges.  This is missing in Python, but type annotations help support this style of programming.\r\n\r\n",
    "bugtrack_url": null,
    "license": "MPL 2.0",
    "summary": "More Streams! Chained function calls",
    "version": "1.680.25062",
    "project_urls": {
        "Homepage": "https://github.com/klahnakoski/mo-streams"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6bcf676a79a3d16e0a6abb636df545b79dae1d32a40e66e2ef5ba68c6dcad41",
                "md5": "bf7dc1f60781a160c860071fafd34524",
                "sha256": "edc67cf52ff23fbfd956dbbe826db94d6469fa90fe099a79b9ce4528599a47ec"
            },
            "downloads": -1,
            "filename": "mo_streams-1.680.25062-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bf7dc1f60781a160c860071fafd34524",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 25003,
            "upload_time": "2025-03-03T00:10:04",
            "upload_time_iso_8601": "2025-03-03T00:10:04.568326Z",
            "url": "https://files.pythonhosted.org/packages/a6/bc/f676a79a3d16e0a6abb636df545b79dae1d32a40e66e2ef5ba68c6dcad41/mo_streams-1.680.25062-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bcf533f29855813eb006467de21890d37adfb11b9329faa7a065e7f559391fd",
                "md5": "fec27d21b2b7d81093aceeeb470d02d7",
                "sha256": "e6c5213afe155f793d7658017b15ed39683db7a657b4f68aa5ffee37734d64b5"
            },
            "downloads": -1,
            "filename": "mo_streams-1.680.25062.tar.gz",
            "has_sig": false,
            "md5_digest": "fec27d21b2b7d81093aceeeb470d02d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22043,
            "upload_time": "2025-03-03T00:10:06",
            "upload_time_iso_8601": "2025-03-03T00:10:06.254339Z",
            "url": "https://files.pythonhosted.org/packages/5b/cf/533f29855813eb006467de21890d37adfb11b9329faa7a065e7f559391fd/mo_streams-1.680.25062.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-03 00:10:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "klahnakoski",
    "github_project": "mo-streams",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mo-streams"
}
        
Elapsed time: 1.05481s