Skip to main content

langfuse-hotswap

Hot-swap the LLM behind a LangChain chain from a Langfuse prompt.

PyPI Python Downloads CI License

English | Русский

Documentation: https://rusih100.github.io/langfuse-hotswap

A service answering in a loop; the production label is moved to another version and the next answer comes from another model

With Langfuse prompt management the template lives outside the code. The model does not: gpt-5.5, temperature=0.2 sit next to the chain, and changing them is a deploy.

langfuse-hotswap moves the model into the prompt config. You build the chat models in the code and get a regular LangChain Runnable that fetches the prompt on every call, picks the model and the parameters from its config and rebuilds when the prompt changes. A prompt version is the template, the model and the parameters together: labeled, rolled out and rolled back as one.

  • Any LangChain chat model. ChatOpenAI, ChatAnthropic, ChatOllama, ... built in the code and selected from the config by name.
  • Explicit by default. The config changes only the model fields the code allows, and nothing until it does. Credentials, endpoints and HTTP clients stay in the code.
  • Keeps serving. A version that fails to build, or a Langfuse outage, leaves the last working chain in place.
  • A regular Runnable. invoke, stream, batch, their async variants, with_structured_output, bind_tools, composition with other runnables.
  • Async without blocking. Warm SDK cache is read on the event loop; HTTP goes to the executor.
  • Langfuse rendering rules, or f-string, mustache and jinja2 on request.
  • Traces link to the prompt version.

Installation

pip install langfuse-hotswap langchain-openai langchain-anthropic

Example

Create a chat prompt support-reply in Langfuse, label it production, with the config:

{"provider": "openai", "model": "gpt-5.5", "temperature": 0.2, "max_tokens": 800}
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
from langfuse import get_client
from langfuse_hotswap import LangfuseChainFactory

factory = LangfuseChainFactory(
    get_client(),
    models={"openai": ChatOpenAI(model="gpt-5.5"), "anthropic": ChatAnthropic(model="claude-sonnet-5-5")},
    allowed_config_keys={"model", "temperature", "max_tokens"},
)
chain = factory.create("support-reply")

message = chain.invoke({"product": "Acme Mail", "language": "English", "question": "How do I reset my password?"})
print(message.content)

Now create a new version with "provider": "anthropic", "model": "claude-sonnet-5-5" and move the production label to it. The next invoke runs on Anthropic. Move the label back and it runs on OpenAI again. No restart, no deploy.

Who controls what

Anyone who edits the prompt controls its config. The code decides how far that goes:

factory = LangfuseChainFactory(
    get_client(),
    models={"openai": ChatOpenAI(api_key=..., timeout=30)},  # built here, credentials included
    allowed_config_keys={"model", "temperature", "max_tokens"},  # the only keys the config may change
)

provider selects one of the models. Without allowed_config_keys the config changes nothing else; with "any" it changes everything, base_url and api_key included. See Security.

Learn more

Unofficial. Not affiliated with Langfuse or LangChain. MIT licensed.

Metadata

Release files for langfuse-hotswap 1.1.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 langfuse-hotswap 1.1.0
File Size Uploaded Provenance Actions
langfuse_hotswap-1.1.0.tar.gz 27.1 kB Without provenance Details for langfuse_hotswap-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langfuse-hotswap 1.1.0
File Interpreter ABI Platform Actions
langfuse_hotswap-1.1.0-py3-none-any.whl Python 3 none any Details for langfuse_hotswap-1.1.0-py3-none-any.whl

Total release size: 40.9 kB

Release files / langfuse_hotswap-1.1.0.tar.gz

Download URL langfuse_hotswap-1.1.0.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cd3ad6caa354f3d3611f33cf093993b11a7f03977dd73186337cedc7eccf1c7e
BLAKE2b-256 checksum
How to use checksums
02ad919585d792dfc5d93bb3fe2beca5b774a8dbfc03bbff9ce505cd0aca763f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / langfuse_hotswap-1.1.0-py3-none-any.whl

Download URL langfuse_hotswap-1.1.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f281f93f1f6cc6690af50951cc2a5d22cd97a504fb94b66f5c3c0233c178d9b8
BLAKE2b-256 checksum
How to use checksums
6f0b6192e7609d1a07a169ee12748e855c40f45b1f9f1a1cb98f8588b645a05e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for langfuse-hotswap 1.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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