Skip to main content

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

Release files for langfuse-freeze 1.0.2

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

Source distribution (sdist)

Source distribution for langfuse-freeze 1.0.2
File Size Uploaded
langfuse_freeze-1.0.2.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langfuse-freeze 1.0.2
File Interpreter ABI Platform
langfuse_freeze-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / langfuse_freeze-1.0.2.tar.gz

Download URL langfuse_freeze-1.0.2.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4654eeb239e797a0d73640e76759bca09815b1b83dbe7836af4e90aa25fdbfd9
BLAKE2b-256 checksum
How to use checksums
4869cc573ab2cb1d129f7a64157b193b8cdfb7192838d1eebeba09ba9ef81382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 27, 2026.

Transparency log

Release files / langfuse_freeze-1.0.2-py3-none-any.whl

Download URL langfuse_freeze-1.0.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae766e57681d7f76a0b4721bda5c3cdaee9cf1a7ff65647db706d1fa2e0948ea
BLAKE2b-256 checksum
How to use checksums
98e053a89ef79fa9c5836e63505a9f90565bc295725df62c97605ff0c1ef483e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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