A set of CLI tools to interact with Langfuse, especially for prompt management.
This project uses uv. You can install the project and its dependencies by running:
uv syncOr you can install it using pip if you have the package:
pip install .The CLI command is named bto-langfuse-cli.
The CLI uses environment variables for authentication with your Langfuse instance. You can create a .env file in the root directory or set these variables in your shell.
Create a .env file with the following content:
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_HOST=https://cloud.langfuse.com # Or your self-hosted URLThe CLI uses the standard langfuse Python SDK get_client() method, which automatically reads these environment variables.
The prompt command group allows you to manage Langfuse prompts.
The promote command allows you to copy a label from one version of all prompts to another. This is useful for moving prompts through different environments (e.g., from dev to uat).
Command:
bto-langfuse-cli prompt promote <src_label> <target_label> [--apply]Options:
--apply: Automatically apply the promotion without asking for confirmation.
Examples:
-
Dry run / Confirmation mode:
bto-langfuse-cli prompt promote dev uat
This will show a plan of which prompts will be updated (adding the
uatlabel to all prompts that currently have thedevlabel) and ask for confirmation before applying. -
Auto-apply mode:
bto-langfuse-cli prompt promote dev uat --apply
This will automatically update the labels for all prompts matching the source label.
The pull command downloads prompts from Langfuse to your local filesystem based on a specific label.
Command:
bto-langfuse-cli prompt pull <label> [type] [OPTIONS]Arguments:
<label>: The label to pull prompts from (e.g.,production,dev). (Required)[type]: The type of prompt to pull. Can betextorchat. If not specified, both types are pulled.
Options:
-o, --output-dir <DIRECTORY>: Directory to save the prompt files to. Defaults todata/prompts.
Output Format (md):
- Text Prompts: Saved as
.mdfiles containing a YAML frontmatter (with metadata like name, version, tags, labels, and last updated date) followed by the raw text prompt. - Chat Prompts: Saved as
.mdfiles containing the same YAML frontmatter, followed by the chat messages serialized using XML-like tags (e.g.,<system>,<user>).
Examples:
-
Pull all prompts with a specific label:
bto-langfuse-cli prompt pull production
-
Pull only chat prompts to a custom directory:
bto-langfuse-cli prompt pull dev chat -o ./my-local-prompts
To run the CLI during development:
uv run bto-langfuse-cli --help