Skip to main content

A Python library that captures and replays function results to save time, boost performance.

Project description

resnap logo

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.


Lint Tests

🚀 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) and csv
    • For other objects: pkl (default), json, and txt.
      (Note that for the "json" format, the object type must be compatible with the json.dump method.)
  • 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

resnap-0.2.0.tar.gz (639.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resnap-0.2.0-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file resnap-0.2.0.tar.gz.

File metadata

  • Download URL: resnap-0.2.0.tar.gz
  • Upload date:
  • Size: 639.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for resnap-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4f5157ad8a9e9409c72785050470b9b220f6900f224d80ca6c5eb6353bd026b7
MD5 7a92b50b8ec635a7050eac72d72ff44a
BLAKE2b-256 272b3d93becde0cef062a774f6cf814e442536c5ae798927c3ab0de0090c2292

See more details on using hashes here.

File details

Details for the file resnap-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: resnap-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for resnap-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7f26134e0edc8f1630a320685b650f9c327a7c8692f83527341d057b48cdbd7
MD5 442a5298ffb402ee156bce0c9cb3ce88
BLAKE2b-256 7b9f365edfbe95ac90f96b76cdab1f9d6a1009d1deeaf464500e96ef0f09584b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page