Pytools
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.
Warnings
- breaking The `Tag` constructor was removed around `v2024.1.8`, breaking compatibility for code relying on it. Some releases were yanked due to this change.
- deprecated The logging functionality previously under `pytools.log` has been spun out into a separate, dedicated project called `logpyle`.
- gotcha 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.
- gotcha Pytools requires Python 3.10 or higher. Older Python versions are not supported.
Install
-
pip install pytools
Imports
- memoize
from pytools import memoize
- PersistentDict
from pytools.persistent_dict import PersistentDict
- DataTable
from pytools.datatable import DataTable
- lex
from pytools import lex
Quickstart
import time
from pytools import memoize
class MyService:
def __init__(self):
self.compute_calls = 0
@memoize.memoize_method
def expensive_computation(self, data_id):
self.compute_calls += 1
time.sleep(0.1) # Simulate a time-consuming operation
return f"Result for {data_id} (computed on call {self.compute_calls})"
service = MyService()
print(service.expensive_computation("user_profile_123"))
print(service.expensive_computation("user_profile_123")) # This call will use the cached result
print(service.expensive_computation("product_data_abc"))