{"id":1439,"library":"cytoolz","title":"cytoolz Library","description":"cytoolz provides a high-performance, Cython-implemented version of the functional utilities found in the toolz library. It offers drop-in replacements for many common `toolz` functions, primarily focusing on iteration and composition for speed improvements. The current version is 1.1.0. Release cadence generally follows significant updates or releases of the upstream `toolz` library.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/pytoolz/cytoolz","tags":["functional programming","performance","utilities","Cython","toolz"],"install":[{"cmd":"pip install cytoolz","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"cytoolz is a Cythonized implementation of toolz primitives and explicitly lists toolz as a runtime dependency. Some utilities are still provided by the toolz library.","package":"toolz","optional":false}],"imports":[{"symbol":"compose","correct":"from cytoolz.functoolz import compose"},{"symbol":"pipe","correct":"from cytoolz.functoolz import pipe"},{"symbol":"map","correct":"from cytoolz.itertoolz import map"},{"symbol":"groupby","correct":"from cytoolz.itertoolz import groupby"},{"note":"Functions are typically exposed via submodules like `functoolz`, `itertoolz`, `dicttoolz`.","wrong":"import cytoolz.get_in","symbol":"get_in","correct":"from cytoolz.dicttoolz import get_in"}],"quickstart":{"code":"from cytoolz.functoolz import compose, pipe\nfrom cytoolz.itertoolz import map, filter\n\ndef add_one(x):\n    return x + 1\n\ndef multiply_by_two(x):\n    return x * 2\n\ndef is_even(x):\n    return x % 2 == 0\n\n# Example 1: Compose functions\nprocess = compose(multiply_by_two, add_one)\nresult_compose = process(5) # (5 + 1) * 2 = 12\nprint(f\"Compose result: {result_compose}\")\n\n# Example 2: Pipe data through functions\nresult_pipe = pipe(5, add_one, multiply_by_two)\nprint(f\"Pipe result: {result_pipe}\")\n\n# Example 3: Map and filter with cytoolz iterators\nnumbers = [1, 2, 3, 4, 5, 6]\nprocessed_numbers = list(filter(is_even, map(add_one, numbers)))\nprint(f\"Processed numbers (map/filter): {processed_numbers}\") # [4, 6, 8]\n","lang":"python","description":"This quickstart demonstrates basic usage of `compose`, `pipe`, `map`, and `filter` from `cytoolz.functoolz` and `cytoolz.itertoolz`. These functions provide a functional programming style with potential performance benefits over their pure Python equivalents, especially for iterable operations."},"warnings":[{"fix":"Profile your application to determine if `cytoolz` provides a meaningful performance improvement for your specific bottlenecks. Don't assume all functions will be faster.","message":"Performance benefits are not universal. While `cytoolz` offers significant speedups for many iterative and compositional operations, particularly those involving loops, simple function calls or operations already highly optimized in CPython might not see major gains, and could even incur minor overhead due to C-Python bridge calls. Measure performance in your specific use case.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to the official `toolz` documentation for the primary source of API information. Monitor `toolz` release notes for breaking changes when upgrading.","message":"`cytoolz`'s API mirrors `toolz`. `cytoolz` aims to be a drop-in replacement for `toolz` primitives. Therefore, users should consult the `toolz` documentation for specific API details (function signatures, available utilities). Changes in `toolz`'s API (e.g., removals, argument changes) will generally apply to `cytoolz` as well.","severity":"gotcha","affected_versions":"All"},{"fix":"Always ensure `pip install cytoolz` is sufficient, as it should pull in `toolz` automatically. If issues arise, explicitly install `toolz` (`pip install toolz`).","message":"`toolz` is a required runtime dependency. Despite `cytoolz` providing Cythonized versions of many `toolz` functions, the `toolz` library itself is an explicit and necessary dependency. Ensure both `cytoolz` and `toolz` are installed in your environment.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}