Skip to content

Ollama

Python library for calling Ollama models from your own Python code.ollama/ollama-python

Stars
10.7k
Forks
1.2k
Licence
MIT
Language
Python
Last update
21 days ago
Type
Library

What it is

This is a Python library that lets Python programs send chat, generation, and embedding requests to a model running through Ollama. You need Ollama installed and running, and a model pulled, before the library can do anything. It wraps Ollama's REST API so calls look like ordinary Python functions, with support for streaming and async use.

  • Ask a model a question with chat() and print the reply
  • Stream a long answer token by token into a terminal or web page
  • Create embeddings for a list of texts with ollama.embed()
  • Run cloud-hosted models through the Client with an API key set in OLLAMA_API_KEY

Great for

  • Python developers adding a local or cloud language model to a script or app
  • People who want to call Ollama from Python without writing raw HTTP requests
  • Projects that need streaming responses or async requests
  • Developers building embedding or batch text-processing pipelines

Not ideal for

  • People who do not write Python: the README only covers Python usage
  • Users who want a chat interface without coding, since this is a library rather than an app
  • Projects needing Python older than 3.8, which the README says is the minimum
Step-by-step guide: how to use OllamaInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Python 3.8+ · Ollama installed and running

    Install the library

    pip install ollama
  2. 2

    Run it

    • Install Ollama from ollama.com/download and make sure it is running
    • Pull a model, for example: ollama pull gemma4
    • Install the library with pip install ollama
    • Run the chat example from the README with model='gemma4'
  3. 3

    Get the most out of it

    • Use stream=True to print partial output as it arrives
    • Use AsyncClient for asynchronous apps
    • Pass custom headers or a different host to Client to point at another server
    • Use the Client options to pass extra keyword arguments to the underlying httpx.Client
    • Catch ollama.ResponseError and pull a missing model on a 404 status

Downloads

Strengths

  • Simple, documented function and client interfaces with examples for sync and async use
  • Covers the main Ollama REST API operations, including chat, pull, embed, and model management
  • Released under the MIT license with a visible release history

Trade-offs

  • Requires a separate Ollama install and a pulled model; the library alone does nothing
  • The README is truncated in this record, so some details may be missing from this entry
  • Cloud features depend on Ollama account sign-in and API keys

How it compares

ProjectStarsTypeLevelUpdatedBest for
ollama-python (this)10.7kLibrarybeginner21 days agoPython developers adding a local or cloud language model to a script or app
ollama186kAppbeginner4 days agoDevelopers who want a local model API for their own apps
deepwiki-open18.3kAppintermediate9 days agoDevelopers trying to understand a large or unfamiliar codebase
pr-agent13.9kDev toolintermediate5 days agoTeams that want automated first-pass reviews on pull requests
LEANN13.8kLibraryintermediate5 days agoDevelopers building a private RAG prototype on a personal machine

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.