Python SDK in Ollama
From the Ollama cheat sheet · Official SDKs · verified Jul 2026
Python SDK
Install and use the official Ollama Python library.
python
# Install
pip install ollama
# Basic chat
from ollama import chat
response = chat(model='llama3.2', messages=[
{'role': 'user', 'content': 'Hello!'},
])
print(response.message.content)💡 The Python SDK provides both sync and async clients (AsyncClient)
⚡ Pass stream=True for token-by-token streaming in real time
📌 Functions like chat(), generate(), embed(), list(), pull() mirror the REST API
🟢 Type hints are included — full autocomplete support in modern editors
pythonsdk