A Python client for Ollama, sync or async, local or cloud
Python developers can now use one identical client to call Ollama models locally or via Ollama's cloud API, removing boilerplate and rewriting when scaling up.
Ollama, a tool that lets people run AI models on their own computers, offers an official Python library called ollama-python. It wraps the model's web interface so a few lines of Python can chat with a model, stream replies, or run code asynchronously. Notably, the same code works whether the model runs on your laptop or on Ollama's cloud servers, including large models like gpt-oss:120b. Python developers building with local AI models are the audience.
Ollama's official Python client (ollama-python) lets teams prototype against models on local hardware and switch to Ollama's cloud API, hosting models like gpt-oss:120b, without rewriting integration code; only the model name, host and auth header change. This reduces engineering overhead versus hand-rolled HTTP calls and avoids lock-in to any single inference vendor's SDK. Companies with Python-based AI services gain flexibility; no pricing or benchmark figures are given.
ollama-python is a thin httpx-based wrapper around the Ollama REST API supporting Python 3.8+. It exposes Client and AsyncClient with identical config fields, returns typed ChatResponse objects accessible via dict-style or attribute syntax, and enables streaming with a single stream=True flag (sync iterables or async generators). Cloud access works via local ollama signin plus pull, or directly against https://ollama.com with a Bearer API key header. Extra kwargs pass through to httpx.Client.