Skip to content

szapp/joblib-typed-cache

Repository files navigation

Joblib Typed Cache

CI PyPI Python Versions Support on Ko-fi

Joblib's cache functionality in joblib.Memory does not preserve type annotations of the underlying function. That poses obstacles for pydantic validation and for modern type checkers and autocompletion in IDEs.

This package simply defines an incomplete adapter for the cache functionality.

Installation

uv add joblib-typed-cache

Usage

The package offers a drop-in replacement for joblib.Memory.cache.

from typed_joblib_cache import Memory

cache = Memory(location="~/.cache", verbose=0)


@cache(ignore=["db_connection"])
def get_user(user_id: str, db_connection: str) -> dict[str, str]:
    # Simulate data retrieval
    return {"user_id": user_id, "email": "john@example.com", "transaction_id": 42}

In this example, the function get_user will retain helpful tooltips in IDE and can also be used in conjunction with pydantic type validation.

import pydantic

get_user_validated = validate_call(get_user)

About

Typed version of joblib's cache to work with pydantic validation and type checkers

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors