📈 GH Trending Explorer 🎲 Surprise me

← all repos

ollama / ollama-python

git clone https://github.com/ollama/ollama-python.git v0.6.3 · 22d ago

Ollama Python library

+5
stars, 24h · #2,893
+~35
stars, 7 days · #3,521
+~150
stars, 30 days · #3,517
11k
★ total · +0% this week
1.2k
forks · 221 open issues

Star history (as recorded here)

2026-10-20 · 10,611 ★ 2026-10-21 · 10,616 ★
LanguagePython
LicenseMIT
Created2023-12-09 (2y ago)
Last push4d ago
Watchers81
OwnerOrganization

GitHub topics

Links

README excerpt
# Ollama Python Library
The Ollama Python library provides the easiest way to integrate Python 3.8+ projects with Ollama.
## Prerequisites
- Ollama should be installed and running
- Pull a model to use with the library: `ollama pull ` e.g. `ollama pull gemma4`
 - See Ollama.com for more information on the models available.
## Install
 [code] 
## Usage
 [code] 
See _types.py for more information on the response types.
## Streaming responses
Response streaming can be enabled by setting `stream=True`.
 [code] 
## Cloud Models
Run larger models by offloading to Ollama’s cloud while keeping your local workflow.
- Supported models: `deepseek-v3.1:671b-cloud`, `gpt-oss:20b-cloud`, `gpt-oss:120b-cloud`, `kimi-k2:1t-cloud`, `qwen3-coder:480b-cloud`, `kimi-k2-thinking` See Ollama Models - Cloud for more information
### Run via local Ollama
1) Sign in (one-time):
 [code] 
2) Pull a cloud model:
 [code] 
3) Make a request:
 [code] 
### Cloud API (ollama.com)
Access cloud models directly by pointing the client at `https://ollama.com`.
1) Create an API key from ollama.com , then set:
 [code] 
2) (Optional) List models available via the API:
 [code] 
3) Generate a response via the cloud API:
 [code] 
## Custom client
A custom client can be created by instantiating `Client` or `AsyncClient` from `ollama`.
All extra keyword arguments are passed into the `httpx.Client`.
 [code] 
## Async client
The `AsyncClient` class is used to make asynchronous requests. It can be configured with the same fields as the `Client` class.
 [code] 
Setting `stream=True` modifies functions to return a Python asynchronous generator:
 [code] 
## API
The Ollama Python library's API is designed around the Ollama REST API
### Chat
 [code] 
### Generate
 [code] 
### List
 [code] 
### Show
 [code] 
### Create
 [code] 
### Copy
 [code] 
### Delete
 [code] 
### Pull
 [code] 
### Push
 [code] 
### Embed
 [code] 
### Embed (batch)
 [code] 
### Ps
 [code] 
### System One
 [code] 
System One uses `POST /v1/systemone` and returns one JSON response; streaming is
not supported. It runs locally with decision models such as `nimble` (Ollama
v0.35.0 or later) or `clef` (v0.35.1 or later), and in the cloud with `clef:cloud`
on a paid plan (through Ollama v0.40.5 or later, or directly against
ollama.com).
Clef also reads images (v0.40.0 or later locally): pass `images` as file paths,
bytes, or base64 strings, shared by all questions. Cloud requests accept up to 4
PNG, JPEG, or WebP images (each at most 4 MiB and 16 megapixels, 8 MiB total).
`state` and question `instructions` accept text, JSON objects, or arrays. Questions
are evaluated in their supplied order:
- `choice`: 2–26 option keys mapped to descriptions (up to 255 in the cloud); `None` uses the key as its description.
- `noul`: probability of true, with optional `{"false": "No", "true": "Yes"}` descriptions.
- `score`: 2–10 descriptions ordered lowest to highest; returns a potentially fractional, zero-based score.
In the cloud, question ids may o