{"id":6213,"library":"pytools","title":"Pytools","description":"Pytools is a comprehensive collection of utilities designed to augment the Python standard library, offering a diverse set of tools for various programming needs. It includes functionalities for mathematical operations, persistent key-value stores, graph algorithms, and object array handling. Maintained by Andreas Kloeckner, it serves primarily as a dependency for his other software packages but provides valuable utilities for direct use. The library is actively developed, with frequent releases, currently at version 2026.1.","status":"active","version":"2026.1","language":"en","source_language":"en","source_url":"https://github.com/inducer/pytools/","tags":["utility","tools","development","math","data-structures","algorithms"],"install":[{"cmd":"pip install pytools","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for functionalities interacting with NumPy object arrays.","package":"numpy","optional":true}],"imports":[{"note":"For various memoization strategies like memoize_method.","symbol":"memoize","correct":"from pytools import memoize"},{"note":"To use the persistent key-value store.","symbol":"PersistentDict","correct":"from pytools.persistent_dict import PersistentDict"},{"note":"For in-memory relational database table functionality.","symbol":"DataTable","correct":"from pytools.datatable import DataTable"},{"note":"For the lexer functionality.","symbol":"lex","correct":"from pytools import lex"}],"quickstart":{"code":"import time\nfrom pytools import memoize\n\nclass MyService:\n    def __init__(self):\n        self.compute_calls = 0\n\n    @memoize.memoize_method\n    def expensive_computation(self, data_id):\n        self.compute_calls += 1\n        time.sleep(0.1) # Simulate a time-consuming operation\n        return f\"Result for {data_id} (computed on call {self.compute_calls})\"\n\nservice = MyService()\nprint(service.expensive_computation(\"user_profile_123\"))\nprint(service.expensive_computation(\"user_profile_123\")) # This call will use the cached result\nprint(service.expensive_computation(\"product_data_abc\"))\n","lang":"python","description":"This example demonstrates how to use `pytools.memoize.memoize_method` to cache the results of an expensive method, preventing redundant computations for the same inputs. Subsequent calls with identical arguments will return the cached value instantly."},"warnings":[{"fix":"Review release notes for specific migration paths or alternatives if using older versions of the `Tag` system.","message":"The `Tag` constructor was removed around `v2024.1.8`, breaking compatibility for code relying on it. Some releases were yanked due to this change.","severity":"breaking","affected_versions":"<2024.1.8"},{"fix":"Migrate logging-related imports and usage to `logpyle` by installing it separately (`pip install logpyle`) and updating import paths.","message":"The logging functionality previously under `pytools.log` has been spun out into a separate, dedicated project called `logpyle`.","severity":"deprecated","affected_versions":">=2024.1.x"},{"fix":"Consult the official documentation (e.g., for specific submodule APIs) rather than expecting intuitive top-level functions for all tasks.","message":"Pytools primarily serves as an internal dependency for the author's other scientific computing projects. While it offers useful general-purpose utilities, its design and sometimes opaque naming conventions might require users to delve into its documentation to find specific tools.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project's environment uses Python 3.10 or a more recent compatible version.","message":"Pytools requires Python 3.10 or higher. Older Python versions are not supported.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}