langfuse-hotswap
Hot-swap the LLM behind a LangChain chain from a Langfuse prompt.
English | Русский
Documentation: https://rusih100.github.io/langfuse-hotswap
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 get a regular
LangChain Runnable that fetches the prompt on every
call, builds template | model 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 provider
init_chat_modelknows: OpenAI, Anthropic, Google, Mistral, Ollama, ... - Safe by default. Only sampling parameters come from the config. Endpoints, credentials, headers and HTTP clients never do. Code settings override config settings.
- 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.
- Traces link to the prompt version.
Installation
pip install langfuse-hotswap langchain-openai
Example
Create a chat prompt support-reply in Langfuse, label it production, with the config:
{"model": "gpt-5.5", "model_provider": "openai", "temperature": 0.2, "max_tokens": 800}
from langfuse import get_client
from langfuse_hotswap import LangfuseChainFactory
factory = LangfuseChainFactory(get_client())
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 "model": "claude-sonnet-5-5", "model_provider": "anthropic" 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(),
timeout=30, # overrides the config
providers={"openai": {...}, "anthropic": {...}}, # the config may pick only these
allowed_config_keys={"model", "model_provider", "temperature", "max_tokens"},
)
base_url, api_key, headers, proxies and the like never reach the model, whatever the allowlist
says. The provider is never inferred from the model name. See
Security.
Learn more
- How it works: fetch, compare, rebuild, the async path.
- Configuration: where parameters come from, labels and versions.
- Customizing the model: hooks, structured output, tools.
- Error handling and templates.
examples/: one short script per feature.
Unofficial. Not affiliated with Langfuse or LangChain. MIT licensed.
Metadata
Release files for langfuse-hotswap 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langfuse_hotswap-0.1.1.tar.gz | 26.3 kB | Without provenance | Details for langfuse_hotswap-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langfuse_hotswap-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for langfuse_hotswap-0.1.1-py3-none-any.whl |
Total release size: 40.4 kB
Release files / langfuse_hotswap-0.1.1.tar.gz
| Download URL | langfuse_hotswap-0.1.1.tar.gz |
|---|---|
| Size | 26.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bec09a8c682706903fa8de894e425cc120f015421a9dd7a90b21d8de25107818
|
|
BLAKE2b-256 checksum How to use checksums |
ddc71292176065ed12aef51c50a52a27d13ba4605b6cae8ae314c871c205875a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.1.1-py3-none-any.whl
| Download URL | langfuse_hotswap-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
835b44b2ece7e3ede4c1ab62a91e714a0385c920883c239d9f29d2495c6747f1
|
|
BLAKE2b-256 checksum How to use checksums |
b07613c1945cb0619509c092bd6a516ea935995c9599791433005a95508074f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.1.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.