This package provides an easy way to use the Langflow API to run flows from Python applications.
- Package:
langflow-client - Import:
import langflow_client - License: Apache-2.0
pip install langflow-client- Base URL of your Langflow instance
- API key if authentication is enabled on your instance
fromlangflow_clientimportLangflowClientclient=LangflowClient({
"base_url": "http://localhost:7860",
"api_key": "sk-...", # optional
})flow=client.flow("<flow-id>")
response=flow.run("Hello, world!")
print(response.outputs)
print(response.chat_output_text())You can pass tweaks and IO options:
fromlangflow_client.constsimportInputTypes, OutputTypesresponse=flow.run(
"Hello",
input_type=InputTypes.CHAT,
output_type=OutputTypes.CHAT,
session_id="optional-session-id",
tweaks={"ChatInput-abc": {"temperature": 0.2}},
)foreventinflow.stream("Hello"):
print(event)Events are dicts with event keys such as add_message, token, and end.
- v1 flow-scoped image upload:
withopen("image.jpg", "rb") asf:
upload=flow.upload_file(f, filename="image.jpg", content_type="image/jpeg")
print(upload.file_path)- v2 user-scoped file upload and listing:
withopen("document.pdf", "rb") asf:
uploaded=client.files.upload(f, filename="document.pdf", content_type="application/pdf")
files=client.files.list()Apache License 2.0. See LICENSE