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.0.1

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.0.1
File Size Uploaded Provenance Actions
langfuse_hotswap-1.0.1.tar.gz 27.1 kB Without provenance Details for langfuse_hotswap-1.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 40.8 kB

Release files / langfuse_hotswap-1.0.1.tar.gz

Download URL langfuse_hotswap-1.0.1.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
30228f5be97cf8eed793ffc0d0b605c49138df7c0c642eba01ce338cb98ce432
BLAKE2b-256 checksum
How to use checksums
3ce2535b1c2aaee616d7df91049c5fe0f66f9775d118012c9fb621be820d4072
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","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.0.1-py3-none-any.whl

Download URL langfuse_hotswap-1.0.1-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40646c88cd11a5bce695b6e93d9a93f898e54939826f825cfb67f785d78ee4fa
BLAKE2b-256 checksum
How to use checksums
7780a2408f6181b1fc4c26532d9fbbf3bbd32a413c750f386b60c9e08932e3fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","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.0.1

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