Registry / data / pytools

pytools

JSON →
library2026.1.1pypypi✓ verified 87d ago

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.

pip install pytools
INSTALL
IMPORT
SIG · PYTOOLS
P
pytools
datapythonv2026.1.1
Install
1.8s avg
Import
173ms
Disk
18MB
Pass rate
6/ 10
Env Coverage6 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2026.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 1.73s
py 3.11
✕ build_error
✓ 1.8s
py 3.12
✕ build_error
✓ 1.7s
py 3.13
✕ build_error
✓ 1.73s
py 3.9
✓ —
✓ 1.98s
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

memoize
from pytools import memoize
For various memoization strategies like memoize_method.
PersistentDict
from pytools.persistent_dict import PersistentDict
To use the persistent key-value store.
DataTable
from pytools.datatable import DataTable
For in-memory relational database table functionality.
lex
from pytools import lex
For the lexer functionality.

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"))
Debug
Known issues
breakingThe `Tag` constructor was removed around `v2024.1.8`, breaking compatibility for code relying on it. Some releases were yanked due to this change.
fix
Review release notes for specific migration paths or alternatives if using older versions of the `Tag` system.
affects: <2024.1.8
deprecatedThe logging functionality previously under `pytools.log` has been spun out into a separate, dedicated project called `logpyle`.
fix
Migrate logging-related imports and usage to `logpyle` by installing it separately (`pip install logpyle`) and updating import paths.
affects: >=2024.1.x
gotchaPytools 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.
fix
Consult the official documentation (e.g., for specific submodule APIs) rather than expecting intuitive top-level functions for all tasks.
affects: All versions
gotchaPytools requires Python 3.10 or higher. Older Python versions are not supported.
fix
Ensure your project's environment uses Python 3.10 or a more recent compatible version.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytools'
The `pytools` library is not installed in the Python environment where the code is being executed.
fix
Install the library using pip:
```bash
pip install pytools
```
AttributeError: module 'pytools' has no attribute 'gcd'
The `gcd` function is located within the `pytools.arithmetic` submodule, not directly exposed at the top level of the `pytools` package.
fix
Import `gcd` from `pytools.arithmetic` or access it as `pytools.arithmetic.gcd`:
```python
import pytools.arithmetic
result = pytools.arithmetic.gcd(10, 15)
# Or
from pytools.arithmetic import gcd
result = gcd(10, 15)
```
TypeError: 'frozendict' object does not support item assignment
`frozendict` from `pytools.immutable_collection` is an immutable dictionary, meaning its contents cannot be modified after creation.
fix
To 'modify' a `frozendict`, create a new one with the desired changes, typically by merging it with another dictionary or reconstructing it:
```python
from pytools.immutable_collection import frozendict
d = frozendict({"a": 1, "b": 2})

# To add/change an item (returns a new frozendict)
new_d = d.update({"c": 3})
print(new_d) # frozendict({'a': 1, 'b': 2, 'c': 3})

# To 'remove' an item (construct a new frozendict)
new_d_without_b = frozendict({k: v for k, v in d.items() if k != 'b'})
print(new_d_without_b) # frozendict({'a': 1})
```
IOError: [Errno 13] Permission denied: '/path/to/your/pytools-persistent.dat'
The Python process lacks the necessary write permissions for the directory where `pytools.persistent_dict` attempts to create or access its data file.
fix
Ensure the directory where the persistent dictionary file is stored has appropriate write permissions for the executing user, or choose a different, writable path for the data file:
```python
from pytools import persistent_dict
# Option 1: Ensure '/tmp/' is writable
d = persistent_dict("/tmp/mypersistentdict.dat")

# Option 2: Use a user-specific writable directory
import os
user_data_dir = os.path.join(os.path.expanduser('~'), '.pytools_data')
os.makedirs(user_data_dir, exist_ok=True)
d = persistent_dict(os.path.join(user_data_dir, "mypersistentdict.dat"))
```
Upgrade
Version history
2026.1.1latest on PyPI · released Jun 3, 2026
Audit
Dependencies
numpyoptionalRequired for functionalities interacting with NumPy object arrays.
Agent activity
10 hits · last 30 days
node
10
Resources
pytools — pip install pytools · libregistry