Introductionο
resnap is a lightweight Python library that lets you cache and recover the output of function calls based on their input arguments β without changing their logic.
It works by decorating a function with @resnap or @async_resnap. When the function is called for the first time
with a specific set of arguments, the result is saved to disk (or another backend).
On subsequent calls with the same inputs, resnap will reuse the saved result instead of recomputing it β
making your workflows faster and more deterministic.
Why use resnap?ο
π Replay cached results for identical inputs
πΎ Multiple serialization formats:
pickle,json,csv,parquet, andtxtπ§± Customizable backends: Local or remote storage via pluggable services (e.g., AWS S3)
βοΈ Minimal code changes: Add a single decorator to any function
π§ͺ Helpful in testing and iterative development to skip slow steps
π Metadata tracking: Records call time, argument hashes, errors, and return types
π¦ Installationο
To test or use in local mode
pip install resnap
If you want to use a S3 solution
pip install resnap[boto]
β±οΈ Quick Exampleο
from resnap import resnap
@resnap
def expensive_op(x, y):
print("Running expensive computation...")
return x * y + 42
# First call: function runs and result is saved
expensive_op(10, 5)
# Second call with same arguments: result is loaded from cache
expensive_op(10, 5)
π οΈ How it worksο
@resnap wraps your function with logic that:
Computes a unique hash of the input arguments (and optionally instance attributes)
Checks if a previous result exists for that hash
If yes, returns the saved result
Otherwise, runs the function, saves the result, and returns it
Metadata (function name, type of result, call timestamp, success/failure status) is stored separately from the result.
π Configuration Optionsο
You can customize how resnap behaves using keyword arguments on the decorator:
Option |
Type |
Default |
Description |
|---|---|---|---|
output_format |
str |
backend default |
Format used to save result (json, pickle, csv, parquet, txt) |
output_folder |
str |
backend default |
Subfolder where to save result files |
enable_recovery |
bool |
True |
Whether to try reusing existing results |
consider_args |
bool |
True |
Whether to include input arguments in hash |
considered_attributes |
list[str] |
[] |
Attributes of class instances to include in the hash |
π§© Use Casesο
Caching slow or deterministic computations
Skipping costly steps in data pipelines or experiments
Replaying function results in tests or reproducible builds
Persisting results between sessions or across environments
Want more? Check out the Usage Guide or dive into the API Reference.