Skip to main content
Ollama provides official SDKs for Python and JavaScript, plus a rich ecosystem of community libraries for other languages and frameworks.

Official Libraries

Official SDKs maintained by the Ollama team provide the best integration experience.

Python

ollama-python

Official Python library with async support
Installation:
pip install ollama
Usage:
from ollama import chat

response = chat(
  model='gemma3',
  messages=[
    {
      'role': 'user',
      'content': 'Why is the sky blue?',
    },
  ]
)

print(response.message.content)
Features:
  • Synchronous and async APIs
  • Streaming support
  • Type hints and IDE autocompletion
  • Complete API coverage (chat, generate, embeddings, etc.)
Learn more:

GitHub

Source code and documentation

PyPI

Package on PyPI

JavaScript

ollama-js

Official JavaScript/TypeScript library for Node and browsers
Installation:
npm i ollama
Usage:
import ollama from "ollama";

const response = await ollama.chat({
  model: "gemma3",
  messages: [
    { role: "user", content: "Why is the sky blue?" }
  ],
});

console.log(response.message.content);
Features:
  • Works in Node.js and browsers
  • TypeScript support with full type definitions
  • Promise-based async API
  • Streaming support
  • Complete API coverage
Learn more:

GitHub

Source code and documentation

npm

Package on npm

Community Libraries

The Ollama community has built SDKs for many other languages and frameworks.

.NET / C#

OllamaSharp

.NET SDK for Ollama

LangChain for .NET

.NET LangChain with Ollama support (example)

LlmTornado

Unified C# interface for multiple LLM APIs

Rust

ollama-rs

Rust SDK for Ollama

LangChainRust

Rust LangChain (example)

Ruby

ruby_llm

Ruby library for LLMs including Ollama

Java

Ollama4j

Java SDK for Ollama

LangChain4j

Java LangChain (example)

Agents-Flex

Java agent framework (example)

Go

LangChainGo

Go LangChain (example)

chromem-go

Go vector database with Ollama embeddings (example)

PHP

LLPhant

PHP AI framework with Ollama support

R

rollama

R SDK for Ollama

Julia

PromptingTools.jl

Julia LLM toolkit (example)

Swift

Ollama for Swift

Swift SDK for Ollama

C++

Ollama-hpp

C++ SDK for Ollama

Dart

LangChainDart

Dart LangChain with Ollama support

Elixir

Elixir LangChain

Elixir LangChain with Ollama support

Frameworks

Popular AI frameworks with Ollama integration.

LangChain

LangChain Python

Python LangChain integration

LangChain.js

JavaScript LangChain (example)

LlamaIndex

LlamaIndex Python

Python data framework for LLMs

LlamaIndexTS

TypeScript LlamaIndex

Other Frameworks

Semantic Kernel

Microsoft’s AI orchestration SDK

Spring AI

Spring framework AI support (docs)

LiteLLM

Unified API for 100+ LLM providers

Haystack

AI pipeline framework

Firebase Genkit

Google’s AI framework

Portkey

AI gateway with Ollama support

any-llm

Unified LLM interface by Mozilla

REST API

If there’s no SDK for your language, you can use the REST API directly.

Example: Chat Endpoint

curl http://localhost:11434/api/chat -d '{
  "model": "gemma3",
  "messages": [{
    "role": "user",
    "content": "Why is the sky blue?"
  }],
  "stream": false
}'

Example: Generate Endpoint

curl http://localhost:11434/api/generate -d '{
  "model": "gemma3",
  "prompt": "Why is the sky blue?",
  "stream": false
}'

Example: Embeddings

curl http://localhost:11434/api/embeddings -d '{
  "model": "nomic-embed-text",
  "prompt": "The sky is blue because of Rayleigh scattering"
}'
See the API documentation for complete endpoint details.

OpenAI Compatibility

Ollama provides OpenAI-compatible APIs, so you can use existing OpenAI SDKs:
from openai import OpenAI

client = OpenAI(
  base_url='http://localhost:11434/v1',
  api_key='ollama',  # required but unused
)

response = client.chat.completions.create(
  model="gemma3",
  messages=[
    {"role": "user", "content": "Why is the sky blue?"}
  ]
)

print(response.choices[0].message.content)

OpenAI API

OpenAI-compatible endpoints

Anthropic API

Anthropic-compatible endpoints

Testing Libraries

Testcontainers

Container-based testing for Ollama
Perfect for integration tests:
from testcontainers.ollama import OllamaContainer

with OllamaContainer() as ollama:
    # Run your tests
    response = ollama.query("gemma3", "Hello!")

Building Your Own SDK

If you’re building a new Ollama SDK:
1

Study the REST API

2

Check existing SDKs

Review ollama-python and ollama-js for patterns
3

Support streaming

Implement streaming for chat and generate endpoints
4

Add type safety

Provide strong types/schemas for requests and responses
5

Handle errors

Gracefully handle network errors and API errors
6

Write tests

Use Testcontainers or a local Ollama instance
7

Document examples

Provide clear usage examples in your README
8

Submit to community

Open a PR to add your SDK to the Ollama README

Learn More

REST API Reference

Complete API documentation

Python Examples

Official Python examples

JavaScript Examples

Official JavaScript examples

Community Integrations

Full list of community projects