Pytools

2026.1 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

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.

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"))

view raw JSON →