Skip to main content

Freeze Langfuse prompts into static artifacts for offline production deployments

Project description

langfuse-freeze

Wraps the Langfuse client to snapshot prompts to disk at startup. If Langfuse is unreachable at runtime, the local backup is used as fallback.

How it works

On import langfuse_freeze, LangfuseBacked.bootstrap() runs automatically:

  • Backup file already exists → skip (log and continue)
  • Backup file missing → fetch all prompts from Langfuse, write to disk
  • Fetch fails → retry with exponential backoff, raise RuntimeError after max retries

At runtime, LangfuseBacked.get_prompt() injects the backup as fallback so Langfuse SDK handles outages gracefully.

Installation

uv add langfuse-freeze

Usage

from langfuse_freeze.main import LangfuseBacked

client = LangfuseBacked()
prompt = client.get_prompt("my-prompt", type="text", label="production")

Drop-in replacement for Langfuse. Same API.

Bootstrap at container build time

Run before the app starts (e.g. in a Dockerfile or k8s init container):

langfuse-freeze-bootstrap

Same logic as import-time bootstrap — skips if backup already present.

Configuration

Env var Default Description
LANGFUSE_PUBLIC_KEY Required
LANGFUSE_SECRET_KEY Required
LANGFUSE_HOST Required
LANGFUSE_PROMPTS_BACKUP_PATH ./langfuse-backup/prompts.json Backup file location
LANGFUSE_BOOTSTRAP_MAX_RETRIES 3 Fetch attempts before crash
LANGFUSE_BOOTSTRAP_RETRY_DELAY 2 Base seconds for exponential backoff
LANGFUSE_DISABLE_BOOTSTRAP Set to 1 to skip import-time bootstrap

Backup format

{
  "my-prompt": {
    "type": "text",
    "labels": {
      "production": "You are a helpful assistant.",
      "dev": "You are a dev assistant."
    }
  }
}

To refresh the backup, delete the file and restart (or re-run langfuse-freeze-bootstrap).

Running tests

Unit tests (no network):

uv run pytest tests/ -m "not integration"

Integration tests (requires Langfuse running at http://localhost:10016):

uv run pytest tests/ -m integration

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

langfuse_freeze-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

langfuse_freeze-0.1.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file langfuse_freeze-0.1.2.tar.gz.

File metadata

  • Download URL: langfuse_freeze-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langfuse_freeze-0.1.2.tar.gz
Algorithm Hash digest
SHA256 96598b9fb4b4ae1965e1cbf77f63cd8c2a1f13d146cd8936dcca50de61bce81a
MD5 30e5c77f0fc8af8955e482cd9cff130e
BLAKE2b-256 31e3564188f7d82b75574b96d4b2df8cde656898ed1047f44ed78e7ab1e49037

See more details on using hashes here.

Provenance

The following attestation bundles were made for langfuse_freeze-0.1.2.tar.gz:

Publisher: publish.yml on SpazioDati/langfuse-freeze

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

File details

Details for the file langfuse_freeze-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langfuse_freeze-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd9898572d170fdf83ea9be94dbc0d539c226a2bc5de700cd1260e5035f7fe63
MD5 f84512ed12727e371adf6e22737c5bca
BLAKE2b-256 0ec254313dbf8176806887b0ccd7cc7c88e7a2bf3df3aa158c1840b97aef1095

See more details on using hashes here.

Provenance

The following attestation bundles were made for langfuse_freeze-0.1.2-py3-none-any.whl:

Publisher: publish.yml on SpazioDati/langfuse-freeze

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