openai/openai-python
The official Python library for the OpenAI API
What it solves
The OpenAI Python library removes the busywork of calling OpenAI's REST API from Python. Instead of hand-writing HTTP requests, parsing JSON, and managing authentication, developers get a ready-made client with typed request/response definitions, both synchronous and asynchronous interfaces, and built-in helpers for streaming, pagination, file uploads, and webhook verification.
How it works
- Install with
pip install openai, then create a client with an API key (or workload identity for cloud environments). - The primary interface is the Responses API for generating text; the older Chat Completions API is also supported indefinitely.
- Both synchronous (
OpenAI) and asynchronous (AsyncOpenAI) clients are available, powered by the HTTPX2 HTTP library. - Request parameters are typed dictionaries (
TypedDict), and responses are Pydantic models with helpers liketo_json()andto_dict(). - Streaming is supported via Server-Sent Events (SSE) for both sync and async clients.
- The Realtime API enables low-latency, multi-modal conversations (text and audio, plus function calling) over a WebSocket connection.
- Vision is supported by passing image URLs or base64-encoded images.
- List endpoints return auto-paginating iterators, so you don't manually fetch successive pages.
- File uploads accept bytes, file-like objects, paths, or
(filename, contents, media type)tuples. - Webhook payloads can be verified and parsed in one step via
client.webhooks.unwrap().
Who it's for
Python 3.10+ developers building applications that use OpenAI models — whether for text generation, vision, audio, realtime conversations, or fine-tuning workflows. It's also useful for teams deploying in cloud environments (Kubernetes, Azure, Google Cloud Platform) that need workload identity authentication instead of long-lived API keys.
Highlights
- Typed request params and response fields for editor autocomplete and documentation.
- Synchronous and asynchronous clients with identical functionality.
- Streaming responses via Server-Sent Events.
- Realtime API for low-latency, multi-modal (text + audio) conversations over WebSocket.
- Vision support: pass image URLs or base64-encoded images.
- Auto-paginating iterators for list endpoints.
- Workload identity authentication for Kubernetes, Azure, GCP, and X.509 mutual TLS.
- Webhook signature verification with
client.webhooks.unwrap(). - Flexible file upload support with multiple input formats.
Related
- Project
- Project
- Project
- Project
- Dispatch