{"id":36964464,"url":"https://github.com/steventimes/fpstreams","last_synced_at":"2026-02-08T23:16:54.913Z","repository":{"id":328556716,"uuid":"1115958082","full_name":"steventimes/fpstreams","owner":"steventimes","description":"functional programming library for Python","archived":false,"fork":false,"pushed_at":"2025-12-29T03:17:59.000Z","size":749,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-05T02:50:40.614Z","etag":null,"topics":["functional-programming","python"],"latest_commit_sha":null,"homepage":"https://steventimes.github.io/fpstreams/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steventimes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-13T22:38:39.000Z","updated_at":"2025-12-29T03:16:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/steventimes/fpstreams","commit_stats":null,"previous_names":["steventimes/fpstreams"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/steventimes/fpstreams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steventimes%2Ffpstreams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steventimes%2Ffpstreams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steventimes%2Ffpstreams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steventimes%2Ffpstreams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steventimes","download_url":"https://codeload.github.com/steventimes/fpstreams/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steventimes%2Ffpstreams/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28397826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","python"],"created_at":"2026-01-13T19:35:00.632Z","updated_at":"2026-01-13T19:35:01.338Z","avatar_url":"https://github.com/steventimes.png","language":"Python","readme":"# fpstreams\n\n[![Build Status](https://github.com/steventimes/fpstreams/actions/workflows/test.yml/badge.svg)](https://github.com/steventimes/fpstreams/actions)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPI version](https://badge.fury.io/py/fpstreams.svg)](https://badge.fury.io/py/fpstreams)\n\n**A robust, type-safe functional programming library for Python.**\n\n`fpstreams` brings the power of **Java Streams**, **Rust Results**, and **JavaScript Array methods** to Python. It provides a fluent interface for data processing, null safety, and error handling without the boilerplate, all while remaining fully typed for IDE autocompletion.\n\n## Features\n\n* **Fluent Streams:** Lazy evaluation chains (`map`, `filter`, `reduce`, `zip`).\n* **Structure Operations:** Powerful chunking with `.batch()`, `.window()`, and `.zip_longest()`.\n* **Parallel Processing:** Memory-safe multi-core distribution with `.parallel()` and auto-batching.\n* **Advanced Statistics:** One-pass summary stats (`.summarizing()`) and SQL-like grouping (`.grouping_by(..., downstream=...)`).\n* **Clean Code Syntax:** Syntactic sugar like `.pick()` and `.filter_none()` to replace lambdas.\n* **Data Science Ready:** Convert streams directly to Pandas DataFrames, NumPy arrays, or CSV/JSON files.\n* **Null Safety:** `Option` to eliminate `None` checks.\n* **Error Handling:** `Result` (Success/Failure) to replace ugly `try/except` blocks.\n\n## Installation\n\n```bash\npip install fpstreams\n```\n\n## Quick Start\n\n### 1. Stream Factories\n\nCreate streams directly from values, functions, or algorithmic sequences.\n\n```python\nfrom fpstreams import Stream\n\nStream.of(1, 2, 3, 4, 5)\n\n# seed 1, Function: x * 2 -\u003e 1, 2, 4, 8, 16...\nStream.iterate(1, lambda x: x * 2).limit(10)\n\n# Infinite polling (e.g., API)\nStream.generate(lambda: random.random()).limit(5)\n```\n\n### 2. Basic Processing\n\nReplace messy loops with clean, readable pipelines.\n\n```python\nfrom fpstreams import Stream, Collectors\n\ndata = [\"apple\", \"banana\", \"cherry\", \"apricot\", \"blueberry\"]\n\n# Filter, transform, and group in one\nresult = (\n    Stream(data)\n    .filter(lambda s: s.startswith(\"a\") or s.startswith(\"b\"))\n    .map(str.upper)\n    .collect(Collectors.grouping_by(lambda s: s[0]))\n)\n# Output: {'A': ['APPLE', 'APRICOT'], 'B': ['BANANA', 'BLUEBERRY']}\n```\n\n### 3. Structure \u0026 Windowing\n\nProcess data in chunks or sliding windows—essential for time-series analysis or bulk API processing.\n\n```python\ndata = range(10)\n\n# Batching: Process 3 items at a time\n# Result: [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]\nStream(data).batch(3).to_list()\n\n# Sliding Window: View of size 3, sliding by 1\n# Result: [[0, 1, 2], [1, 2, 3], [2, 3, 4]...]\nStream(data).window(size=3, step=1).to_list()\n```\n\n### 4. Clean Code Shortcuts\n\nStop writing repetitive lambdas for dictionaries.\n\n```python\nusers = [\n    {\"id\": 1, \"name\": \"Alice\", \"role\": \"admin\"},\n    {\"id\": 2, \"name\": \"Bob\", \"role\": None},\n    {\"id\": 3, \"name\": None, \"role\": \"user\"},\n]\n\nnames = (\n    Stream(users)\n    .pick(\"name\")      # Extract \"name\" key\n    .filter_none()     # Remove None values\n    .to_list()\n)\n# Output: [\"Alice\", \"Bob\"]\n```\n\n### 5. Parallel Processing\n\n`fpstreams` can automatically distribute heavy workloads across all CPU cores using the `.parallel()` method. It uses an optimized Map-Reduce architecture to minimize memory usage.\n\n```python\nimport math\nfrom fpstreams import Stream\n\ndef heavy_task_batch(numbers):\n    # Process a whole list of numbers at once (Vectorization or bulk API)\n    return [math.factorial(n) for n in numbers]\n\n# Memory Efficient: \"batch(100)\" sends chunks to workers\n# instead of pickling 10,000 individual tasks.\nresults = (\n    Stream(range(10000))\n    .parallel()\n    .batch(100) \n    .map(heavy_task_batch)\n    .to_list()\n)\n```\n\n### 4. Data Science \u0026 I/O\n\nSeamlessly integrate with the scientific stack.\n\n```python\n# 1. One-pass Statistics (Count, Sum, Min, Max, Avg)\nstats = Stream(users).collect(Collectors.summarizing(lambda u: u['age']))\nprint(f\"Average Age: {stats.average}, Max: {stats.max}\")\n\n# 2. Advanced Grouping (SQL-style)\n# Group by Dept, then Avg Salary\navg_salaries = Stream(employees).collect(\n    Collectors.grouping_by(\n        lambda e: e['dept'],\n        downstream=Collectors.averaging(lambda e: e['salary'])\n    )\n)\n\n# 3. Export\nStream(users).to_df()\nStream(users).to_csv(\"output.csv\")\n```\n\n## Infinite Streams \u0026 Lazy Evaluation\n\nProcess massive datasets efficiently. Operations are only executed when needed.\n\n```python\n# Infinite stream of even numbers using .iterate()\nevens = (\n    Stream.iterate(0, lambda n: n + 1)\n    .filter(lambda x: x % 2 == 0)\n    .limit(10)\n    .to_list()\n)\n```\n\n## Benchmark\n\nComparison between standard streams and `fpstreams.parallel()` on a 4-core machine:\n\n| Task | Sequential(s) | Parallel(s) | Speedup |\n| :--- | :--- | :--- | :--- |\n| **Heavy Calculation** (Factorials) | 24.8358 | 9.5575 | **2.60x** |\n| **I/O Simulation** (Sleep) | 2.1053 | 0.8101 | **2.60x** |\n| **Light Calculation** (Multiplication) | 0.0135 | 0.3109 | 0.04x |\n\n*Note: Parallel streams have overhead. Use them for CPU-intensive tasks or slow I/O, not simple arithmetic.*\n\n## Project Structure\n\n* **`Stream`**: The core wrapper for sequential data processing.\n* **`ParallelStream`**: A multi-core wrapper for heavy parallel processing.\n* **`Option`**: Null-safe container.\n* **`Result`**: Error-handling container.\n* **`Collectors`**: Accumulation utilities (grouping, joining, summary stats).\n\n## Licence\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteventimes%2Ffpstreams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteventimes%2Ffpstreams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteventimes%2Ffpstreams/lists"}