Skip to main content

langfuse-hotswap

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

PyPI Python 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 0.2.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 0.2.0
File Size Uploaded Provenance Actions
langfuse_hotswap-0.2.0.tar.gz 26.0 kB Without provenance Details for langfuse_hotswap-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 39.5 kB

Release files / langfuse_hotswap-0.2.0.tar.gz

Download URL langfuse_hotswap-0.2.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ddacc1d5f98b64f704ac6847303e0c73518e1b23c4dfa949d6d19e73228bf5eb
BLAKE2b-256 checksum
How to use checksums
99cf2805ed1860d3339e763293668d6fc6168d57a91eaf6b251d319635c4129e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","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-0.2.0-py3-none-any.whl

Download URL langfuse_hotswap-0.2.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e9ee5fcff0b9a5a6371866ca70483645d16d58688281ba8c0eab2f427043fccd
BLAKE2b-256 checksum
How to use checksums
5f7d874afd4da941c16addcb3a40e06676bb9bf7eff7c20632ba256688cdc1c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","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 0.2.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