Skip to main content

A minimal, typed Python interface for Ollama that simplifies the existing ollama library

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clean_ollama-1.2.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clean_ollama-1.2.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file clean_ollama-1.2.2.tar.gz.

File metadata

  • Download URL: clean_ollama-1.2.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for clean_ollama-1.2.2.tar.gz
Algorithm Hash digest
SHA256 95ab27b2f7dced2f3ec5fc95f9a0cff047fbf3e3f4c2b9f2a801b721ab76d665
MD5 2106cb3655210c4d782f33af718c0e24
BLAKE2b-256 51090e960d4539d38041525a235eeb6df651f7f71e3f721a9bf4346083a7936b

See more details on using hashes here.

File details

Details for the file clean_ollama-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: clean_ollama-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for clean_ollama-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d44d0b5f03b19166352f4523a6eaa16acfc05a36397509e7611beb1006f33f
MD5 1a598a4eb1e506e2ce3c4b13fa4ff997
BLAKE2b-256 dfb5a5160e79d4ed9149f6d574293eb8e45131e649e94be3cb5d86dcbeea0b5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page