Python Library
The official Python library provides a clean, Pythonic interface to the Ollama API.Installation
Quick Start
Advanced Usage
Context Management
Maintain conversation context across multiple requests:Error Handling
JavaScript Library
The official JavaScript library works in both Node.js and browser environments.Installation
Quick Start
Advanced Usage
TypeScript Support
The JavaScript library includes full TypeScript definitions:Abort Requests
Cancel in-flight requests using AbortController:Library Features Comparison
| Feature | Python | JavaScript |
|---|---|---|
| Generate text | ✓ | ✓ |
| Chat completions | ✓ | ✓ |
| Streaming | ✓ | ✓ |
| Embeddings | ✓ | ✓ |
| Model management | ✓ | ✓ |
| Multimodal input | ✓ | ✓ |
| Context preservation | ✓ | ✓ |
| Type hints/TypeScript | ✓ | ✓ |
| Custom hosts | ✓ | ✓ |
| Authentication | ✓ | ✓ |
| Request cancellation | ✓ | ✓ |
| Browser support | ✗ | ✓ |
Authentication with Libraries
Both libraries support authentication for ollama.com:Community Libraries
In addition to the official libraries, the Ollama community has created libraries for many languages:Ruby
.NET
Rust
Java
Swift
PHP
Elixir
Repository Links
Python Library
Source code, examples, and issue tracker
JavaScript Library
Source code, examples, and issue tracker
Examples
Both libraries include comprehensive example code in their repositories:- Python: ollama-python/examples
- JavaScript: ollama-js/examples
Next Steps
API Reference
Explore all available endpoints
Streaming
Implement real-time streaming responses
Chat API
Build multi-turn conversations
Embeddings
Create embeddings for semantic search