Skip to main content

OpenWebUI Client

PyPI version Python versions Documentation License: MIT

A client library for the OpenWebUI API, compatible with the OpenAI Python SDK but with extensions specific to OpenWebUI features.

Installation

pip install openwebui-client

Quick Start

from openwebui_client import OpenWebUIClient

# Initialize client
client = OpenWebUIClient(
    api_key="your_api_key",  # Optional if set in environment variable
    base_url="http://your-openwebui-instance:5000",
    default_model="gpt-4"
)

# Basic chat completion
response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello, world!"}
    ]
)
print(response.choices[0].message.content)

Using Function Calling / Tools

The client supports OpenAI-compatible function calling with tools:

# Direct tool usage with chat completions
response = client.chat.completions.create(
    model="your_model",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the current time?"}
    ],
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_current_time",
                "description": "Get the current time.",
                "parameters": {
                    "type": "object",
                    "properties": {},
                    "required": [],
                },
            },
        }
    ],
)

# Check if the model used tools
if response.choices[0].message.tool_calls:
    tool_call = response.choices[0].message.tool_calls[0]
    print(f"Tool called: {tool_call.function.name}")

Using the Tool Registry

The client includes a tool registry for easier management of tools:

# Define tool functions
def get_weather(location: str, unit: str = "celsius") -> str:
    """Get the current weather in a given location.

    Args:
        location: The location to get weather for
        unit: The temperature unit to use (celsius or fahrenheit)

    Returns:
        str: A string describing the current weather
    """
    return f"The weather in {location} is sunny and 25°{unit[0]}"

# Register tools with the client
client.tool_registry.register(get_weather)

# Use chat_with_tools for automatic tool handling
response = client.chat_with_tools(
    messages=[{"role": "user", "content": "What's the weather like in Toronto?"}],
    max_tool_calls=5,
)

print(response)  # Will contain the final response after any tool calls

File Operations

# Upload a file to OpenWebUI
uploaded_file = client.files.from_path(file)

# Upload multiple files to OpenWebUI
with open("document.pdf", "rb") as file:
    uploaded_files = client.files.from_paths(
        files=[
            (file1, None),
            (file2, {"xMetaField": "xMetaValue"})
        ]
    )

uploaded_files.append(uploaded_file)

# Use file with chat completion
response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Summarize this document for me."}
    ],
    files=uploaded_files
)

Features

  • OpenAI Compatibility: Use the familiar OpenAI Python SDK interfaces
  • File Upload: Upload and process files with OpenWebUI
  • File-Aware Chat Completions: Reference files in chat completions
  • Typed Interface: Full type hints for better IDE integration

Documentation

Full documentation is available at https://bemade.github.io/openwebui-client/

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
python -m pytest

# Build documentation
cd docs
make html

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects

Release files for openwebui-client 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openwebui-client 0.3.2
File Size Uploaded
openwebui_client-0.3.2.tar.gz 593.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openwebui-client 0.3.2
File Interpreter ABI Platform
openwebui_client-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 610.7 kB

Release files / openwebui_client-0.3.2.tar.gz

Download URL openwebui_client-0.3.2.tar.gz
Size 593.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7609a0fb4227758273564ed95c5d6b88e42f124fad6d216ee36e9ae954500a04
BLAKE2b-256 checksum
How to use checksums
05640cde2cf0a4604ef1cda2e772cca8ede69207f1a609f27055cd72da292fad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / openwebui_client-0.3.2-py3-none-any.whl

Download URL openwebui_client-0.3.2-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47fc747a97380f39541d769279a1e2be009695b131b5679322d4e6cd3d416962
BLAKE2b-256 checksum
How to use checksums
962c4dbd5a27aed7974aed762be5d172f6750bb0eb32f188a6e408853b0b2a5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page