Library for programmatic access to an Open WebUI server (auth, models, tools, chat).
Project description
openwebui-sdk
[!WARNING] Work in progress. This SDK is incomplete and under active development. The API may change, some features are missing, and it is not yet stable or ready for production use.
A Python library for talking to an Open WebUI server. OpenWebUIClient gives you the full tool-calling loop, not just plain chat, as a callable library. Use it from scripts, services and other apps, without a terminal or a browser.
[!IMPORTANT] Looking for the CLI? This is the library (
openwebui-sdk). The ready-to-use terminal tool built on top of it ships as the separateopenwebui-clipackage. Install it withpip install openwebui-clior read its README.
- Full tool-calling loop.
run_chatwiresresolve_tools→ Socket.IO tool execution →save_chat, so a non-CLI app gets real tool runs, not just text. - Structured results.
run_chatreturns aChatResult(answer,reasoning,tool_calls,raw_content) instead of a raw stream. - Server access carried for it. Auth (email/password or API key), models, tools and functions CRUD and valves, all through
Authorization: Beareragainst real Open WebUI routes (verified against 0.6.5). - Thin surface. One client class and a handful of result dataclasses; no framework, no server dependencies.
from openwebui_sdk import OpenWebUIClient
client = OpenWebUIClient(base_url="http://localhost:8080", token="sk-...")
result = client.run_chat(
model="sample-workspace-model-1",
messages=[{"role": "user", "content": "What time is it?"}],
tool_ids=client.resolve_tools("sample-workspace-model-1"),
)
result.answer # "The current time is 7:33 PM." (tools ran; reasoning + tool_calls also filled)
Install
Install the SDK from the registry (PyPI-compatible; works with pip and uv):
pip install openwebui-sdk
# or with uv
uv add openwebui-sdk
The CLI is a separate published package that depends on the SDK:
pip install openwebui-cli
# or with uv
uv add openwebui-cli
Installing the SDK pulls in python-socketio and aiohttp, which the
Socket.IO tool-execution runner requires.
Guide
Streaming a plain chat
run_chat picks the transport for you. Socket.IO when tool_ids is set,
plain HTTP streaming otherwise, and returns a structured ChatResult:
result = client.run_chat(
model="sample-workspace-model-1",
messages=[{"role": "user", "content": "What time is it?"}],
on_text=lambda fragment: print(fragment, end=""), # stream to stdout
)
print(result.answer) # ChatResult: answer, reasoning, tool_calls, raw_content
Lower-level callers can use chat_stream (per-fragment iterator),
chat_once (buffered string) and chat_json (raw OpenAI-compatible dict)
directly.
Using tools
Resolve the tools attached to a model, then run a chat with them. The Socket.IO runner executes the tool-call loop and streams reasoning / tool activity / the final answer through callbacks:
tool_ids = client.resolve_tools("sample-workspace-model-1") # list[str]
result = client.run_chat(
model="sample-workspace-model-1",
messages=[{"role": "user", "content": "What time is it?"}],
tool_ids=tool_ids,
on_reasoning=lambda f: None, # chain-of-thought
on_tool=lambda line: None, # tool activity, e.g. "↳ get_time ..."
on_status=lambda line: None,
)
resolve_tools reads the model's attached info.meta.toolIds (the same field
the web UI reads), merges any explicit extras (deduped), and honours --no-tools
via no_tools=True (returns []).
Persisting a chat
Create a chat row, run the completion, and save it so it appears in the web UI sidebar with a generated title:
chat_id = client.create_chat(title="New Chat", model=model)
result = client.run_chat(model=model, messages=[...])
client.save_chat(
chat_id=chat_id,
message_id=str(uuid.uuid4()),
model=model,
prompt_text="What time is it?",
answer=result.answer,
raw_content=result.raw_content,
)
Authentication
OpenWebUIClient accepts either an API key or a JWT bearer token, or exchanges
email + password for one:
client = OpenWebUIClient(base_url)
session = client.signin(email, password) # -> Session (token, user_id, ...)
print(session.token) # use it to build an API-key client
client.session() # validate the current token + refresh it; returns Session
Both JWTs and sk-... API keys are sent as Authorization: Bearer <token>.
session() also mints a refreshed token, which the client adopts.
Managing models
The client manages the server's workspace models (Settings → Workspace in the web
UI). Methods return the parsed Model / ModelConfig objects.
client.list_models() # -> list[Model]
cfg = client.get_model_config("my-model") # full editable config (ModelConfig)
client.create_model(
id="my-model",
base_model_id="gpt-4o",
name="My Model",
system="You are a helpful assistant.",
tools=["dummytools"],
functions=["my_filter"],
capabilities={"vision": True, "web_search": True},
function_calling="native",
)
client.update_model("my-model", system="New prompt", name="Renamed") # partial
client.delete_model("my-model")
client.add_model_tools("my-model", ["dummytools"]) # enable a tool
client.remove_model_tools("my-model", ["dummytools"]) # disable a tool
client.add_model_functions("my-model", ["my_filter"]) # enable a function
client.remove_model_functions("my-model", ["my_filter"]) # disable a function
update_model fetches the current config first and round-trips the full
meta/params, so fields you don't touch (temperature, tags, profile image,
…) survive. Tools are stored as meta.toolIds; functions are split into
filter/action by their server type.
Managing tools
The client manages workspace tools (Settings → Workspace in the web UI): CRUD
plus admin valves for the python-socketio tool execution.
client.list_tools()
client.get_tool("my_tool")
client.create_tool(
id="my_tool", name="My Tool", content="def ...", description="does X"
)
client.update_tool("my_tool", description="new desc") # None fields keep current
client.delete_tool("my_tool")
client.set_tool_valves("my_tool", {"api_key": "..."})
client.get_tool_valves("my_tool")
Managing functions
Functions attach to models as filters or actions (Settings → Workspace → Functions in the web UI). The client manages them like tools (admin required):
client.list_functions() # -> list[Function]
client.get_function("my_filter") # includes source code (FunctionModel)
client.create_function(
id="my_filter", name="My Filter",
content="class Filter:\n ...", description="does X",
)
client.update_function("my_filter", description="new desc") # None fields keep current
client.delete_function("my_filter")
# admin valves for the function's Valves class
client.set_function_valves("my_filter", {"api_key": "..."})
client.get_function_valves("my_filter")
client.get_function_valves_spec("my_filter")
Function carries type (filter/action) plus is_active/is_global and the
parsed manifest; the server derives the type from the source on create.
Layout
src/openwebui_sdk/
__init__.py # version, re-exports (OpenWebUIClient, Model, Tool, Session, ChatResult)
client.py # OpenWebUIClient: auth / models / tools / functions / chats / run_chat
models.py # Model, ModelConfig (editable workspace-model config)
tools.py # Tool
functions.py # Function
sessions.py # Session (sign-in / identity)
chat.py # ChatResult + parse_title (chat-title helper)
http.py # urllib request + SSE streaming (proxy-aware via env)
sse.py # decode OpenAI chat-completion chunks into text
sockets.py # Socket.IO chat runner (tool execution path)
render.py # render serialized content blocks (answer / reasoning / tools) for a terminal
errors.py # exception types
The command-line wrapper built on top of this library lives in
cli/.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openwebui_sdk-0.1.1.tar.gz.
File metadata
- Download URL: openwebui_sdk-0.1.1.tar.gz
- Upload date:
- Size: 42.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a31b77295ce07dba3362c0e1fc01b96dbf6757e846904f0fff4abe4d5d2e5ae5
|
|
| MD5 |
7e92c76b647f04cfb2988b0343262235
|
|
| BLAKE2b-256 |
6b8940fb2d1619914c2f086ca726c5b5da521c6ff4374dc8cadb4c86198cb435
|
Provenance
The following attestation bundles were made for openwebui_sdk-0.1.1.tar.gz:
Publisher:
ci.yml on vedmaka/openwebui-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openwebui_sdk-0.1.1.tar.gz -
Subject digest:
a31b77295ce07dba3362c0e1fc01b96dbf6757e846904f0fff4abe4d5d2e5ae5 - Sigstore transparency entry: 2337261200
- Sigstore integration time:
-
Permalink:
vedmaka/openwebui-sdk@53863df323ed0d8ed618008bdb5fdac1df17cb50 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/vedmaka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@53863df323ed0d8ed618008bdb5fdac1df17cb50 -
Trigger Event:
push
-
Statement type:
File details
Details for the file openwebui_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: openwebui_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 33.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6efa6810595026fe848d564d3006669a90ec2596c9fa1f0a5e88a115a7aa8051
|
|
| MD5 |
861a2d217f559fbe7273e4ce6eb5ea50
|
|
| BLAKE2b-256 |
3392761d9ef46ea378817c8ed0bf2ce7759095c22258236fd433aa14923e2c64
|
Provenance
The following attestation bundles were made for openwebui_sdk-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on vedmaka/openwebui-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openwebui_sdk-0.1.1-py3-none-any.whl -
Subject digest:
6efa6810595026fe848d564d3006669a90ec2596c9fa1f0a5e88a115a7aa8051 - Sigstore transparency entry: 2337261213
- Sigstore integration time:
-
Permalink:
vedmaka/openwebui-sdk@53863df323ed0d8ed618008bdb5fdac1df17cb50 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/vedmaka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@53863df323ed0d8ed618008bdb5fdac1df17cb50 -
Trigger Event:
push
-
Statement type: