Skip to main content

llm-cache-lite

PyPI version Python 3.8+ License: MIT

A lightweight, decorator-based caching library for LLM (Large Language Model) API calls. Save money, reduce API latency, and speed up your AI development cycle instantly.

Why use llm-cache-lite?

When developing AI applications, you often send the same prompts over and over again. This wastes API credits and slows down your testing. llm-cache-lite solves this by intercepting your AI functions and caching the responses in a local SQLite database.

  • Universal: Works seamlessly with OpenAI, Anthropic, Gemini, local models, or any custom function.
  • Async Ready: Native support for async/await functions
  • Zero Boilerplate: Just add the @llm_cache decorator. No complex clients to initialize.
  • Smart TTL: Automatically expire and invalidate old cached responses.
  • Developer Friendly: Type-hinted and strictly validated with Pydantic.

Installation

pip install llm-cache-lite

Quick Start

Standard (Sync) Usage

import time
from llm_cache_lite import llm_cache, CacheSettings

# Optional: Configure database path and TTL (Time-To-Live in seconds)
# Here, the cache will expire after 1 hour (3600 seconds)
settings = CacheSettings(db_path="my_ai_cache.db", ttl_seconds=3600)

@llm_cache(settings=settings)
def ask_ai(prompt: str) -> str:
    # Simulate an expensive API call to OpenAI/Claude/Gemini etc.
    print(f"Calling real AI for: {prompt}")
    time.sleep(2) 
    return f"AI response to: {prompt}"

# First call: Executes the function (takes 35 seconds)
print(ask_ai("What is Python?"))

# Second call: Returns instantly from the local SQLite cache! (~0.001 seconds)
print(ask_ai("What is Python"))

Asynchronous (Async) Usage

import asyncio
from llm_cache_lite import llm_cache, CacheSettings

# Optional: Configure database path and TTL (Time-To-Live in seconds)
# Here, the cache will expire after 1 hour (3600 seconds)
settings = CacheSettings(db_path="my_ai_cache.db", ttl_seconds=3600)

@llm_cache(settings=settings)
async def async_ask_ai(prompt: str) -> str:
    # Simulate an expensive API call to OpenAI/Claude/Gemini etc.
    print(f"Calling real AI for: {prompt}")
    await asyncio.sleep(2)
    return f"Async AI response to: {prompt}"

async def main():
    # First call: Executes the function (takes 35 seconds)
    print(await async_ask_ai("What is the speed of sound?"))
    
    # Second call: Returns instantly from the local SQLite cache! (~0.001 seconds)
    print(await async_ask_ai("What is the speed of sound?"))
    
asyncio.run(main())

Configuration

The CacheSettings object uses Pydantic to ensure your configuration is always valid. It accepts the following parameters:

Parameter Type Default Description
db_path str "llm_cache.db" The path to the SQLite database file.
ttl_seconds int 0 Time-To-Live in seconds. 0 means the cache never expires.

License

This project is licensed under the MIT License.

Metadata

Release files for llm-cache-lite 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-cache-lite 0.3.0
File Size Uploaded Provenance
llm_cache_lite-0.3.0.tar.gz 8.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-cache-lite 0.3.0
File Interpreter ABI Platform
llm_cache_lite-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / llm_cache_lite-0.3.0.tar.gz

Download URL llm_cache_lite-0.3.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d892e077345e369c5ccc0fec2ef61bcd57979092255ece244f61ebc2188138e9
BLAKE2b-256 checksum
How to use checksums
1a30c0c17bc593637e5509b0d2de171beae955e47636298413c7e4e178e650d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 4, 2026.

Transparency log

Release files / llm_cache_lite-0.3.0-py3-none-any.whl

Download URL llm_cache_lite-0.3.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
037dc5520721c86852b63e67f256cec3e703d35d56d5cf10cb09f02dfc1bcc2e
BLAKE2b-256 checksum
How to use checksums
665fc2c223cfe807a040aea0ff2cd68ea9434ae1e44157ca4a34d4151811277b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 4, 2026.

Transparency log

Security for llm-cache-lite 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for llm_cache_lite-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page