Skip to main content
AdOpenFree logoPromote your productReach more potential users and drive product growth and revenue.Advertise
Favicon of Ollama Python Library

Ollama Python Library

Free Listing

Official Python client for Ollama that wraps the REST API with sync and async clients, typed chat responses, streaming, and local or cloud model access for Python 3.8+.

Visit ollama/ollama-python

Overview

The Ollama Python Library is the official Python client for Ollama. It wraps the Ollama REST API in idiomatic Python, with synchronous and asynchronous clients, typed chat responses, streaming, custom hosts and headers, and access to local or cloud models from Python 3.8 and up.

Key Features

  • Typed chat responses can be read like a dict or through attribute access.
  • Streaming responses are enabled with stream=True in sync calls and as an async generator with AsyncClient.
  • Client and AsyncClient support the same configuration fields for sync or async codebases.
  • Local and cloud models share the same client.chat interface, with direct cloud access to Ollama's hosted API using an API key.
  • Custom clients can set host and headers, and extra keyword arguments pass through to httpx.Client.
  • API coverage includes chat, generate, list, show, create, copy, delete, pull, push, embed, ps, and systemone.

Use Cases

  • Build Python scripts or applications that chat with models served by a local Ollama instance.
  • Add streaming chat to synchronous or asynchronous Python services.
  • Prototype against local models and move to larger cloud models using the same chat interface.
  • Access Ollama cloud models directly with an API key when no local server should sit in the middle.

Getting Started

  • Install and run Ollama, then pull a model such as gemma4 with ollama pull gemma4.
  • Install the library with pip install ollama.
  • Import chat from ollama, pass a model and a list of messages, and print response['message']['content'] or response.message.content.
  • For streaming, set stream=True and iterate over chunks; for async, use AsyncClient and await the call.

Deployment & Requirements

  • Python 3.8 or later.
  • Ollama installed and running for local use.
  • A model pulled for use with the library, for example with ollama pull gemma4.
  • For the direct cloud API, set OLLAMA_API_KEY and point Client at the Ollama cloud host with an authorization header.

Before You Adopt

  • License: MIT. Review its terms before using, modifying, or distributing the project.
  • Local use requires Ollama to be installed and running, and a model pulled.
  • Direct cloud API access requires setting the OLLAMA_API_KEY environment variable.
  • System One confidence scores indicate probability concentration, not calibrated correctness.

Comments

Sign in to leave a comment.

More like Ollama Python Library

Favicon of Oat UI

Oat UI

Free ListingStars: 5.6K

Semantic, minimal, dependency-free UI library

App UI & SDKs

Oat UI is an ultra-lightweight, dependency-free HTML and CSS component library that styles semantic markup out of the box. It ships about 10KB of CSS and JS, requires no framework or build step, and covers commonly needed components.

Favicon of Univer

Univer

Free ListingStars: 25K

Open-source Office SDK for apps and AI agents

App UI & SDKs

Univer is an Office SDK for embedding editing, calculation, collaboration, and file processing into products for people and AI agents, built on an extensible open-source core.

Favicon of AG-UI

AG-UI

Free ListingStars: 17.2K

Open event-based protocol for agent-user interaction

App UI & SDKs

AG-UI is an open, lightweight, event-based protocol standardizing how AI agents connect to user-facing applications. It provides a bidirectional link between frontend apps and agentic backends, covering state, UI intents, and interactions.