Skip to main content

Batteries-included wrapper for litellm with rate limiting, retries, templating, and more

Project description

Flashlite

A batteries-included wrapper for litellm designed for high-volume prompting workloads like evals, agentic loops, and social simulations.

Features

  • Rate Limiting - Token bucket algorithm for RPM and TPM limits
  • Retries - Exponential backoff with jitter via tenacity
  • Jinja Templating - Prompt templates with custom filters
  • Caching - In-memory LRU and SQLite disk caching
  • Structured Outputs - Native Pydantic model parsing without instructor
  • Tool/Function Calling - @tool decorator and execution loops
  • Multi-Turn Conversations - Conversation management with branching
  • Cost Tracking - Token counting and budget limits
  • Observability - Structured logging and Inspect framework integration
  • Async-First - Native async with sync wrappers

Installation

pip install flashlite
# or with uv
uv add flashlite

Quick Start

from flashlite import Flashlite

# Create client (loads .env automatically)
client = Flashlite(default_model="gpt-4o")

# Simple completion
response = await client.complete(
    messages="What is the capital of France?"
)
print(response.content)

# Sync version
response = client.complete_sync(messages="Hello!")

Structured Outputs

from pydantic import BaseModel, Field
from flashlite import Flashlite

class Sentiment(BaseModel):
    label: str = Field(description="positive, negative, or neutral")
    confidence: float = Field(ge=0, le=1)

client = Flashlite(default_model="gpt-4o")

result: Sentiment = await client.complete(
    messages="Analyze: 'I love this product!'",
    response_model=Sentiment,
)
print(f"{result.label} ({result.confidence:.0%})")

Tool/Function Calling

from flashlite import Flashlite, tool, run_tool_loop

@tool()
def get_weather(location: str) -> str:
    """Get weather for a location."""
    return f"Weather in {location}: 72°F, sunny"

client = Flashlite(default_model="gpt-4o")

result = await run_tool_loop(
    client=client,
    messages=[{"role": "user", "content": "What's the weather in NYC?"}],
    tools=[get_weather],
)
print(result.content)

Parallel Processing

# Process many requests with concurrency control
responses = await client.complete_many(
    requests=[
        {"messages": f"Summarize: {doc}"}
        for doc in documents
    ],
    max_concurrency=10,
)

Caching

from flashlite import Flashlite, MemoryCache, DiskCache

# In-memory caching
client = Flashlite(
    cache=MemoryCache(max_size=1000),
    default_model="gpt-4o",
)

# Or persistent disk cache
client = Flashlite(
    cache=DiskCache("./cache.db"),
    default_model="gpt-4o",
)

Reasoning Models

from flashlite import Flashlite, thinking_enabled

client = Flashlite()

# OpenAI o1/o3
response = await client.complete(
    model="o3",
    messages="Solve this complex problem...",
    reasoning_effort="high",
)

# Anthropic Claude extended thinking
response = await client.complete(
    model="anthropic/claude-sonnet-4-5-20250929",
    messages="Complex reasoning task...",
    thinking=thinking_enabled(10000),
)

Documentation

Requirements

  • Python 3.12+
  • litellm
  • pydantic>=2.0
  • jinja2
  • tenacity
  • python-dotenv

License

MIT

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

flashlite-0.2.5.tar.gz (242.2 kB view details)

Uploaded Source

Built Distribution

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

flashlite-0.2.5-py3-none-any.whl (77.1 kB view details)

Uploaded Python 3

File details

Details for the file flashlite-0.2.5.tar.gz.

File metadata

  • Download URL: flashlite-0.2.5.tar.gz
  • Upload date:
  • Size: 242.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for flashlite-0.2.5.tar.gz
Algorithm Hash digest
SHA256 c53166495b02b62792915bffd80757d3661ba04e00f26eae6566d33b727c05aa
MD5 11023f3854a4b28ef5ed16b21c6524cc
BLAKE2b-256 4f0d546315eac7b7084e56ffa3034634cb6635888ff2a4f7c6f67bf5a918e354

See more details on using hashes here.

File details

Details for the file flashlite-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: flashlite-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 77.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for flashlite-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c0f02e00e347b766d0a3b07bee49f9fd2f65a4e2b661d39006943b4da9db0a72
MD5 cb6a9207f7c0ce286be5503c55e1fa60
BLAKE2b-256 9aa23e6384381a52d374ea02ebf49fccff7809b83a339f11afb8d5669a40b84c

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