clean-ollama
A minimal, typed Python interface for Ollama that simplifies the existing ollama library
Installation
Install with pip
pip install clean-ollama
Requirements
- Python 3.10+
- Ollama installed
Usage
Basic generation
from clean_ollama import Client, Message, Role
client = Client("qwen3.5:4b")
messages = [
Message(Role.USER, "What is the capital of France?")
]
thinking, response, tool_calls = client.generate(messages)
print(response)
Streaming
from clean_ollama import Client, Message, Role
client = Client("qwen3.5:4b")
messages = [
Message(Role.USER, "Tell me a joke.")
]
for thinking, chunk in client.stream(messages):
print(chunk, end="", flush=True)
Tool use
from clean_ollama import Client, Message, Role, Tool, Param, ParamType
get_weather = Tool(
name="get_weather",
description="Get the current weather for a location",
params=[
Param("location", "City name", ParamType.string),
Param("units", "celsius or fahrenheit", ParamType.string, required=False),
]
)
messages = [
Message(Role.USER, "What's the weather in Tokyo?")
]
thinking, response, tool_calls = client.generate(messages, tools=[get_weather])
print(tool_calls)
What tool calls look like
generate returns a list of tool calls. Each call has a function with a name and arguments dict:
thinking, response, tool_calls = client.generate(messages, tools=[get_weather])
for call in tool_calls:
print(call.function.name) # "get_weather"
print(call.function.arguments) # {"location": "Tokyo", "units": "celsius"}
If the model didn't call any tools, tool_calls is an empty list.
Thinking (extended reasoning)
from clean_ollama import Client, Message, Role
thinking, response, tool_calls = client.generate(messages, think=True)
print("Thinking:", thinking)
print("Response:", response)
Loading and unloading models
from clean_ollama import Client
client = Client("qwen3.5:4b")
client.load() # keeps the model in memory
client.unload() # frees the model from memory
API Reference
Client(model: str)
Main class for interacting with Ollama.
| Method | Description |
|---|---|
load() |
Loads the model into memory |
unload() |
Unloads the model from memory |
generate(messages, tools=None, think=False) |
Returns (thinking, response, tool_calls) |
stream(messages, think=False) |
Yields (thinking, chunk) pairs |
Message(role, content)
Represents a chat message. role accepts a Role enum or a plain string.
Role
Enum with values: SYSTEM, USER, ASSISTANT, TOOL
Tool(name, description, params)
Defines a callable tool the model can invoke.
Param(name, description, param_type, required=True)
Defines a single tool parameter.
ParamType
Enum for parameter types: string, integer, float, boolean, json
License
MIT
Metadata
Release files for clean-ollama 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clean_ollama-1.2.2.tar.gz | 6.1 kB | Without provenance | Details for clean_ollama-1.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clean_ollama-1.2.2-py3-none-any.whl | Python 3 | none | any | Details for clean_ollama-1.2.2-py3-none-any.whl |
Total release size: 10.6 kB
Release files / clean_ollama-1.2.2.tar.gz
| Download URL | clean_ollama-1.2.2.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95ab27b2f7dced2f3ec5fc95f9a0cff047fbf3e3f4c2b9f2a801b721ab76d665
|
|
BLAKE2b-256 checksum How to use checksums |
51090e960d4539d38041525a235eeb6df651f7f71e3f721a9bf4346083a7936b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / clean_ollama-1.2.2-py3-none-any.whl
| Download URL | clean_ollama-1.2.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9d44d0b5f03b19166352f4523a6eaa16acfc05a36397509e7611beb1006f33f
|
|
BLAKE2b-256 checksum How to use checksums |
dfb5a5160e79d4ed9149f6d574293eb8e45131e649e94be3cb5d86dcbeea0b5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for clean-ollama 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.