A modern, asynchronous Python SDK and Command-Line Interface (owui) for interacting with your Open WebUI instance.
This project provides a unified, Pythonic interface to manage chats, folders, knowledgebases and interact with Large Language Models (LLMs) served by Open WebUI, following a structured, layered design. It is built to be both programmatically flexible for developers and easy to use from the terminal for end-users.
- Asynchronous First SDK: A clean, 
asyncio-native Python library (openwebui) for high-performance, concurrent interaction. - Intuitive CLI: A powerful command-line tool (
owui) built withclickfor easy management of chats, folders, and Knowledge Bases directly from your terminal. - Complex Workflow Abstraction: Simplifies multi-step API interactions (e.g., creating a new chat with an initial LLM response, uploading a directory to a KB with 
.kbignorerules) into single, intuitive SDK methods. - Hierarchical YAML Configuration: Loads configuration from 
~/.owui/config.yamlor a local.owui/config.yaml, with environment variables for overrides. - Robust Error Handling: Provides custom exceptions like 
AuthenticationErrorandNotFoundErrorfor predictable error handling in your applications. - Integrated Logging: Detailed logging controllable via CLI flags (
--verbose,--debug) for easy debugging and visibility. - Type-Safe API Interaction: Uses an auto-generated low-level client from the OpenWebUI OpenAPI schema to ensure type safety and maintainability.
 - Comprehensive Test Suite: Includes unit tests, integration tests, and CLI tests to ensure reliability.
 
It is recommended to install openwebui-sdk in a virtual environment.
- 
Clone the repository:
git clone https://github.com/dubh3124/OpenWebUI-SDK.git # Replace with your actual repo URL cd OpenWebUI-SDK
 - 
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate - 
Install the package in editable mode with development dependencies: This allows you to run the
owuiCLI directly and makes development easier. This project usesuvfor package management, butpipwill also work.# Using uv (recommended) uv pip install -e ".[dev]" # Or using pip pip install -e ".[dev]"
 
The SDK and CLI load configuration from YAML files with environment variables taking highest precedence.
1. Create the configuration directory:
mkdir -p ~/.owui2. Create a config.yaml file:
Create ~/.owui/config.yaml and add your server details.
# ~/.owui/config.yaml
server:
  url: "http://your-openwebui-instance:8080"
  api_key: "sk-YOUR_API_KEY_HERE"url: The full URL to your Open WebUI instance. Important: Ensure the scheme (http://orhttps://) matches your server's setup to avoid SSL errors.api_key: Your API key obtained from your Open WebUI settings (Settings->Account).
Precedence Order:
- Environment Variables (
OPENWEBUI_URL,OPENWEBUI_API_KEY) - Local Project Config (
./.owui/config.yaml) - User-level Config (
~/.owui/config.yaml) 
The CLI provides commands for managing folders, chats, and knowledge bases. You can explore all options using --help.
owui --helpYou can control verbosity with logging flags and output format with the --output option.
owui --verbose folder list
owui --output json folder list
- 
Create a new folder:
owui folder create "My New Project Ideas" - 
List all existing folders:
owui folder list
 - 
List chats within a specific folder: (Requires the folder ID obtained from
folder list)owui folder list-chats "your-folder-id-here" - 
Delete a folder:
owui folder delete "your-folder-id-here" 
- 
Create a new chat and get an LLM response:
owui chat create -m gemini-1.5-flash "What is the capital of France?"(Use
-mor--modelto specify the model) - 
Continue an existing chat thread:
owui chat continue "your-chat-id-here" "Can you tell me more about its history?"
 - 
View all messages in a specific chat:
owui chat list "your-chat-id-here" - 
Rename a chat:
owui chat rename "your-chat-id-here" "French History Discussion"
 - 
Delete a chat:
owui chat delete "your-chat-id-here" 
- 
Create a new Knowledge Base:
owui kb create "My Project Docs" --description "Documentation for my new project."
 - 
List all Knowledge Bases:
owui kb list-kbs
 - 
Upload a single file to a KB:
owui kb upload-file ./my_document.txt --kb-id "your-knowledge-base-id-here" - 
Upload a local directory to a KB:
# This command will upload all files from 'my_local_files/' to the specified KB. # It respects .kbignore files (e.g., my_local_files/.kbignore) for exclusions. owui kb upload-dir ./my_local_files/ --kb-id "your-knowledge-base-id-here"
 - 
List files within a Knowledge Base:
owui kb list-files "your-knowledge-base-id-here" --search "report"
 - 
Update content of an existing file in a KB:
owui kb update-file "your-file-id-here" ./updated_document.txt - 
Delete a specific file from a KB:
owui kb delete-file "your-file-id-here" - 
Delete all files from a Knowledge Base: (Requires confirmation, use
--yesto skip)owui kb delete-all-files "your-knowledge-base-id-here" 
For those looking to contribute to the project:
- Setup: Ensure you have installed the project with development dependencies: 
uv pip install -e ".[dev]" - Running Tests:
# Run all tests (unit, CLI, integration) uv run pytest # Run only SDK unit tests uv run pytest tests/sdk/ # Run only CLI tests uv run pytest tests/cli/ # Run only integration tests (requires live server and configuration) uv run pytest tests/integration/ # Run specific integration tests for Knowledge Base functionality uv run pytest tests/integration/test_kb_sdk_integration.py
 - Code Style: This project uses 
rufffor linting and formatting.# Check for linting errors uv run ruff check . # Auto-format code uv run ruff format .
 - Regenerating the OpenAPI Client: If the OpenWebUI API changes, you can regenerate the low-level client with:
openapi-python-client generate \ --url http://your-openwebui-instance:8080/openapi.json \ --output-path openwebui/open_web_ui_client 
Contributions are welcome! Please feel free to open an issue or submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.