A Python library that captures and replays function results to save time, boost performance.
Project description
resnap
Smart function output snapshots and caching for Python
resnap snapshots and reuses function outputs based on their inputs, saving time with smart caching and metadata tracking.
🚀 Features
- Snapshot and cache function/method outputs on disk
- Avoid re-executing code when inputs haven’t changed
- Supports multiple formats:
- For pd.DataFrame objects:
parquet(default) andcsv - For other objects:
pkl(default),json, andtxt.
(Note that for the "json" format, the object type must be compatible with the json.dump method.)
- For pd.DataFrame objects:
- Stores metadata automatically
- Add custom metadata
- Minimal setup, flexible usage
📦 Installation
To test in local mode
pip install resnap
If you want to use a S3 solution
pip install resnap[boto]
🛠️ Configuration
To use this library, you need to configure it using a pyproject.toml file. Add the following section under [tool.resnap]:
[tool.resnap]
enabled = true # Enable or disable the library functionality
save_to = "local" # Choose the storage backend (e.g., 'local')
output_base_path = "results" # Directory where output files will be saved
secrets_file_name = "" # Optional: path to a secrets file (leave empty if unused (e.g, 'local'))
enable_remove_old_files = true # Automatically delete old files based on retention policy
max_history_files_length = 3 # Duration value for file retention, used with max_history_files_time_unit
max_history_files_time_unit = "day" # Time unit used for history retention (e.g., 'second', 'minute', 'hour', 'day')
🧪 Quick Example
from resnap import resnap
@resnap
def expensive_computation(x, y):
print("Running the actual computation...")
return x * y + 42
result = expensive_computation(10, 2)
Second call with same arguments:
# Output is retrieved from cache — no print, no computation
result = expensive_computation(10, 2)
📁 Output Structure
Each snapshot includes:
- A result file (in the format of your choice)
- A metadata file (e.g., timestamp, arguments, execution time, etc.)
📚 Documentation
The documentation is available on ReadTheDocs.
🛡️ License
This project is licensed under the MIT License. See the LICENSE file for details.
🤝 Contributing
Contributions, issues and feature requests are welcome! Feel free to open a PR or start a discussion.
⭐️ Show your support If you find this project useful, give it a ⭐️ on GitHub!
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 resnap-0.4.0.tar.gz.
File metadata
- Download URL: resnap-0.4.0.tar.gz
- Upload date:
- Size: 641.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1398e544c4389e2320f5f867c6ba811f1a2606fcb8897cc052d256288ae1aea7
|
|
| MD5 |
4edadc203b4f462f6ef2e8bb821b782c
|
|
| BLAKE2b-256 |
114f585b69b9de88e00948b320c638ec739c4cdf83cc88e1d1df3a1f5a76d4bf
|
File details
Details for the file resnap-0.4.0-py3-none-any.whl.
File metadata
- Download URL: resnap-0.4.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11d294d910ae9ded3765242c04523bfe20586e59f55a64706fb6f84595e24fe6
|
|
| MD5 |
308d8be7e83ad0fa50c2d0435d0b22fa
|
|
| BLAKE2b-256 |
b3ec1a467edb483bbe98d1ee4df7dcfe7b7b44ca9cf2f09f4a21a4976220bd34
|