Add your description here
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stepit-0.5.3.tar.gz.
File metadata
- Download URL: stepit-0.5.3.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2217a49f68325c9e345ac4336b8d078a1dd3fbb2af9e1988e99907f223d3ecf5
|
|
| MD5 |
dab47130bb485d54e53a4744becc1d46
|
|
| BLAKE2b-256 |
9815f97607dced5215743809cf891cd1a3befa17038e4641fd3147f466bbe23c
|
Provenance
The following attestation bundles were made for stepit-0.5.3.tar.gz:
Publisher:
release.yml on edalfon/stepit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stepit-0.5.3.tar.gz -
Subject digest:
2217a49f68325c9e345ac4336b8d078a1dd3fbb2af9e1988e99907f223d3ecf5 - Sigstore transparency entry: 174200740
- Sigstore integration time:
-
Permalink:
edalfon/stepit@545e452ff33e6184d8f2734fabdd5e538697ea33 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/edalfon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@545e452ff33e6184d8f2734fabdd5e538697ea33 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stepit-0.5.3-py3-none-any.whl.
File metadata
- Download URL: stepit-0.5.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05ad5f7b31c04ba1096988f927fe52f3646611b8f1d8606b88bfdbd969f973e9
|
|
| MD5 |
0c38de1fc86734523b7f7173469d6986
|
|
| BLAKE2b-256 |
4a7a81ce9440f5ab6d49a5cbd56ead75c89d3d9a8ce64ebb39a9fd4e409b32ba
|
Provenance
The following attestation bundles were made for stepit-0.5.3-py3-none-any.whl:
Publisher:
release.yml on edalfon/stepit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stepit-0.5.3-py3-none-any.whl -
Subject digest:
05ad5f7b31c04ba1096988f927fe52f3646611b8f1d8606b88bfdbd969f973e9 - Sigstore transparency entry: 174200742
- Sigstore integration time:
-
Permalink:
edalfon/stepit@545e452ff33e6184d8f2734fabdd5e538697ea33 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/edalfon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@545e452ff33e6184d8f2734fabdd5e538697ea33 -
Trigger Event:
push
-
Statement type: