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

FrozenLangfuse(prompts_backup_path=<path>).bootstrap() creates a Langfuse client (init parameters are equivalent to the client in official SDK) and runs the backup process:

  • Backup file already exists → skip if overwrite argument is false (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, FrozenLangfuse.get_prompt() injects the backup as fallback so Langfuse SDK handles outages gracefully.

Installation

uv add langfuse-freeze

Usage

Creating a backup (deploy / build time)

Use the constructor with bootstrap() to fetch and persist all labeled prompts from the Langfuse API:

from langfuse_freeze import FrozenLangfuse

client = FrozenLangfuse(prompts_backup_path='./langfuse_backup/prompts.json.gz')
client.bootstrap()

Loading a pre-existing backup (runtime)

Use from_backup() when the backup is expected to already exist. This raises FileNotFoundError immediately if the file is missing — making misconfiguration obvious at startup rather than at the first prompt fetch:

from langfuse_freeze import FrozenLangfuse

client = FrozenLangfuse.from_backup('./langfuse_backup/prompts.json.gz')
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 --backup-path ./langfuse_backup/prompts.json.gz

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

Then, at application runtime, load the backup with from_backup():

client = FrozenLangfuse.from_backup('./langfuse_backup/prompts.json.gz')

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 on http://localhost:3000, we reccomend to use docker-compose. In order to setup the instance with docker compose, some environment variables are required, with the following values:

LANGFUSE_INIT_ORG_ID=my-org
LANGFUSE_INIT_PROJECT_ID=my-project
LANGFUSE_INIT_PROJECT_PUBLIC_KEY=lf_pk_1234567890
LANGFUSE_INIT_PROJECT_SECRET_KEY=lf_sk_1234567890
LANGFUSE_INIT_USER_EMAIL=user@example.com
LANGFUSE_INIT_USER_PASSWORD=password123

They can be set in a .env file so the instance can be started with

docker compose --env-file .env up

Once Langfuse is running, integration tests can be run (they will write prompts on my-project)

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-1.0.1.tar.gz (8.7 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-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for langfuse_freeze-1.0.1.tar.gz
Algorithm Hash digest
SHA256 def511133227552cf1c02c4cebceb8c58c211b3004cb93ab463a5ad540e18fa3
MD5 cdf5e9cb437651097379a7d23bbfa635
BLAKE2b-256 315b7f0ccb9f6ed1af31c63fd912448d57ef46a7aab110f8ec00bb5c1ed290d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for langfuse_freeze-1.0.1.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-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langfuse_freeze-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97190e4501e7dcadf0687fe348caf4a46294111f7904386319cb07e583f8b493
MD5 d2ecafbc25640ce93bbbeed270d59e18
BLAKE2b-256 31dcea0109ae828c6447dcd2a2c16dae788c777360cefbf8735295a72bb001b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for langfuse_freeze-1.0.1-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