← all repositories
openai/openai-python

The SDK that talks to GPT so you don't have to think about HTTP

OpenAI's official Python client wraps a sprawling REST API into typed, sync-or-async Python objects.

31.2k stars Python Language Models
openai-python
Velocity · 7d
−11
★ / day
Trend
cooling
star history

What it does

This is the sanctioned Python wrapper for OpenAI’s REST API. It turns HTTP calls into client.responses.create() and client.chat.completions.create() methods, with Pydantic models for responses and TypedDicts for nested request parameters. Both synchronous and asynchronous clients ship standard, backed by httpx with an optional aiohttp swap-in for heavier concurrency.

The interesting bit

The entire library is auto-generated from OpenAI’s OpenAPI spec using Stainless, a code-generation service. That explains the almost bureaucratic completeness: workload identity auth for Kubernetes, Azure, and GCP; auto-paginating list iterators; a WebSocket-based Realtime API for low-latency audio conversations. It’s an SDK built like a compiler target, not a hand-crafted developer experience.

Key highlights

  • Responses API is now the primary interface; Chat Completions remains supported indefinitely
  • Realtime API handles text and audio I/O over WebSocket, with manual error-event handling (errors don’t raise exceptions)
  • Workload identity auth replaces long-lived API keys in cloud environments
  • Streaming via Server-Sent Events uses identical interfaces for sync and async clients
  • Responses serialize to JSON or dict via Pydantic helpers (to_json(), to_dict())

Caveats

  • Realtime API errors arrive as events you must check for; the SDK stays silent and keeps the connection open
  • The README’s pagination example is truncated mid-loop, so the exact iterator API isn’t fully visible

Verdict

Use this if you’re calling OpenAI from Python and value type safety over minimal dependencies. Skip it if you need a lightweight HTTP wrapper; httpx plus Pydantic models you define yourself will be thinner and more predictable.

Frequently asked

What is openai/openai-python?
OpenAI's official Python client wraps a sprawling REST API into typed, sync-or-async Python objects.
Is openai-python open source?
Yes — openai/openai-python is open source, released under the Apache-2.0 license.
What language is openai-python written in?
openai/openai-python is primarily written in Python.
How popular is openai-python?
openai/openai-python has 31.2k stars on GitHub and is currently cooling off.
Where can I find openai-python?
openai/openai-python is on GitHub at https://github.com/openai/openai-python.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.