stepit
Yet another python decorator for persistent caching. stepit caches function results based on their source code and arguments, automatically invalidating the cache when either changes.
Key Features
- Smart Cache Invalidation: Cache is updated when function source code changes
- Recursive Awareness: Tracks changes in nested function calls
- Informative Logging: Color-coded progress and status messages
- Zero Configuration: Works out of the box with sensible defaults
- Customizable: Supports custom cache keys, directories, and serialization
Installation
pip install stepit
Quick Start
from stepit import stepit
@stepit
def expensive_calculation(x):
# ... complex computation ...
return result
# First call: computes and caches
result = expensive_calculation(42)
# Second call: uses cache
result = expensive_calculation(42)
Advanced Usage
Recursive Functions with Automatic Cache Invalidation
@stepit
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2)
# First run: calculates and caches all intermediate results
fibonacci(100)
# Change the function
@stepit
def fibonacci(n): # Different implementation
if n <= 0: return 0
if n == 1: return 1
return fibonacci(n-1) + fibonacci(n-2)
# Cache is automatically invalidated due to source code change
fibonacci(100)
Custom Cache Configuration
@stepit(
key="my_special_function",
cache_dir="custom_cache"
)
def process_data(x):
return x * 2
Informative Logging
import logging
logging.getLogger("stepit").setLevel(logging.DEBUG)
@stepit
def add(a, b):
return a + b
add(1, 2) # Outputs:
# ⏩ stepit 'add': Starting execution of `__main__.add()`
# ✅ stepit 'add': Successfully completed and cached [exec time 0 seconds, size 37 bytes]
# ♻️ stepit 'add': is up-to-date. Using cached result
Use Cases
- Data processing pipelines
- Scientific computations
- Machine learning model training
- Any expensive computations that may be repeated
How It Works
- Creates a unique key based on:
- Function's source code
- Arguments
- Any nested
@stepit-decorated function calls
- Checks if result exists in cache
- Executes function if:
- No cached result exists
- Source code has changed
- Arguments are different
- Stores result in cache for future use
License
MIT License
Contributing
Contributions welcome! Please check our GitHub repository for guidelines.
Release files for stepit 0.5.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stepit-0.5.4.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stepit-0.5.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / stepit-0.5.4.tar.gz
| Download URL | stepit-0.5.4.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ba946bf54dfc9eb266cfd2e724a1c1d5ba36c4e0d10a4219ca6ad0c45fd4732
|
|
BLAKE2b-256 checksum How to use checksums |
f77c55fa7880516810b50307e599a27f0991f64916d46dbe6247104a2435ba28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 26, 2025.
Transparency logRelease files / stepit-0.5.4-py3-none-any.whl
| Download URL | stepit-0.5.4-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7878990f1e175718737d06b94fb1d7410d2fa5e4a42641c282adb94f88236cd4
|
|
BLAKE2b-256 checksum How to use checksums |
1d2a40f15ba358d6f1d4e24df1209159a399962f3f860c02979b82e3aa376f98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 26, 2025.
Transparency log