The official Python library for the OpenAI REST API, with sync and async clients and typed request and response models.
ollama/ollama-python
Official Python client library for calling Ollama's local and cloud models through chat, generate, embed and model-management APIs.
- Stars
- 10,611
- Forks
- 1,209
- Open issues
- 223
- Last commit
- 4 days ago
What is it?
The Ollama Python library is a client for the Ollama REST API, letting Python 3.8+ projects talk to models served by a running Ollama instance. It wraps chat, generate, embed, list, pull, push, copy, delete and process-status calls in a small set of functions, with matching synchronous and asynchronous clients.
Responses can be returned whole or streamed chunk by chunk, and the same client can target a local Ollama server or the hosted cloud API at ollama.com using an API key. Cloud models such as gpt-oss:120b-cloud can be run through the local server after signing in, or called directly. Errors from non-success HTTP statuses or mid-stream are raised as a ResponseError.
The library also includes a System One API for structured decisions, such as picking one of several choices, scoring on a scale, or returning a yes/no probability, using decision models like nimble and clef.
Key features
- 01Chat, generate, and embed calls that mirror the Ollama REST API.
- 02Streaming responses via stream=True in both sync and async modes.
- 03Client and AsyncClient classes that accept custom host and httpx headers.
- 04Model management functions for list, show, create, pull, push, copy and delete.
- 05Access to cloud models through the local server or directly at ollama.com with an API key.
- 06System One structured decision API that supports choice, yes/no and score questions.
Use cases
- Adding a local LLM chat feature to a Python web app or script.
- Generating text embeddings for search or retrieval pipelines.
- Switching between local models and hosted cloud models with the same code.
- Building automated triage or classification steps with structured decision questions.
Quick start
- 1
Install Ollama and make sure it is running
- 2
Pull a model to use with the library
ollama pull gemma4 - 3
Install the Python library
pip install ollama - 4
Call the chat API from Python
Things to know
- Requires a locally installed and running Ollama server, or an Ollama API key for cloud models.
- Cloud models need an Ollama account, and cloud API access may require a paid plan.
Topics
FAQ
- What is ollama-python?
- Official Python client library for calling Ollama's local and cloud models through chat, generate, embed and model-management APIs. The Ollama Python library is a client for the Ollama REST API, letting Python 3.8+ projects talk to models served by a running Ollama instance. It wraps chat, generate, embed, list, pull, push, copy, delete and process-status calls in a small set of functions, with matching synchronous and asynchronous clients.
- Is ollama-python free to use? What license does it have?
- ollama-python is open source under the MIT license. Check the license terms before using it in commercial products.
- Is ollama-python still maintained?
- Actively maintained. The last commit to ollama-python was on Oct 16, 2026.
- What can I use ollama-python for?
- Adding a local LLM chat feature to a Python web app or script. Generating text embeddings for search or retrieval pipelines. Switching between local models and hosted cloud models with the same code. Building automated triage or classification steps with structured decision questions.
- How do I install ollama-python?
- Install Ollama and make sure it is running Pull a model to use with the library: ollama pull gemma4 Install the Python library: pip install ollama Call the chat API from Python
- Where can I get ollama-python?
- The source code and installation instructions are on GitHub: https://github.com/ollama/ollama-python
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A command-line tool and Python library for running prompts and chats against remote and locally installed large language models.
A Python web scraping library that uses LLMs and graph-based pipelines to extract structured data from websites and local documents based on a text prompt.
A modular Agentic RAG tutorial and project built with LangGraph, featuring hierarchical indexing, conversation memory, and query clarification.
A local knowledge graph tool where a locally run model reasons step by step and the reasoning is stored as an RDF graph, all on your own machine via Ollama.
A free, open-source 10-week online course on building LLM applications with RAG, vector search, agents, evaluation and monitoring.