Skip to main content

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

  1. Creates a unique key based on:
    • Function's source code
    • Arguments
    • Any nested @stepit-decorated function calls
  2. Checks if result exists in cache
  3. Executes function if:
    • No cached result exists
    • Source code has changed
    • Arguments are different
  4. 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

stepit-0.3.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

stepit-0.3.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file stepit-0.3.1.tar.gz.

File metadata

  • Download URL: stepit-0.3.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for stepit-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b0ca580a2e0e5b8f5e11b4d62b991af1228573eb3ac430bbf001b18209fbeade
MD5 be1c95a617f5801b55b0cfd3dc382897
BLAKE2b-256 6707b203782e10d48310a8265f3bb02d0c222f87a45e0de63b1b54abc7213239

See more details on using hashes here.

Provenance

The following attestation bundles were made for stepit-0.3.1.tar.gz:

Publisher: release.yml on edalfon/stepit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stepit-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: stepit-0.3.1-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.8

File hashes

Hashes for stepit-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12249237b726cdf430fc0ac72e22bd64e31b2fd936e541e2043d199dd6a076a2
MD5 48f4cbd307dd1729e9a5f4a219d1629e
BLAKE2b-256 310b8117f2dd8b2af4053c2e800c236b12a8e6b0f2a5aeb45a0ce281e9f629fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for stepit-0.3.1-py3-none-any.whl:

Publisher: release.yml on edalfon/stepit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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