openai/openai-python
OfficialThe official Python library for the OpenAI API
OpenAI's official Python client with 30k stars and auto-generated types from the OpenAPI spec. Run pip install openai, set your API key, and call GPT models with full async, streaming, vision, and Realtime API support in v2.30.0.
Best for
Our Review
OpenAI Python SDK is the official Python client for OpenAI REST API, built by OpenAI with 30,391 GitHub stars. Version 2.30.0 uses Stainless generation for Pydantic response models and full IDE autocomplete.
What OpenAI Python SDK does:
- •Responses API main text generation endpoint that replaces legacy completions.
- •Chat Completions API standard message-based conversations with GPT models.
- •Vision support accepts image URLs or base64 data in multimodal prompts.
- •Realtime API WebSocket client for low-latency audio and text exchanges.
- •Streaming responses server-sent events for real-time token output in sync/async.
- •AsyncOpenAI client full async/await powered by httpx backend.
- •Type safety TypedDict inputs and Pydantic outputs match OpenAPI spec exactly.
OpenAI Python SDK ecosystem:
- •Assistants API build agentic workflows with persistent threads and tools.
- •Fine-tuning API customize models on your datasets via simple client calls.
- •Batch API queue large jobs for async processing at lower cost.
Getting started:
Run pip install openai. Set export OPENAI_API_KEY=sk-.... Import with from openai import OpenAI; create client = OpenAI(). Call response = client.chat.completions.create(model="gpt-5.2", messages=[{"role": "user", "content": "Hello"}]). See full docs at platform.openai.com/docs.
Limitations:
Requires a paid OpenAI API key for production use -- no local or self-hosted option. Python-only; TypeScript projects need the separate openai-node package. Covers OpenAI endpoints exclusively -- no multi-provider switching built in. No built-in retry logic or response caching.
Cons
- Needs paid OpenAI API key for production-scale usage.
- Python-only -- pick official JS SDK for TypeScript projects.
- Covers OpenAI endpoints exclusively -- no multi-provider switching.
- Lacks built-in retries or caching -- implement with tenacity or Redis.
Our Verdict
Developers build GPT apps in Python with speed thanks to OpenAI Python SDK's auto-generated types. Async clients handle realtime audio and vision without guesswork. Production code runs reliable from day one.
Skip if you code in JavaScript or need one SDK for OpenAI plus Anthropic. Basic users pass -- this demands Python skills and API keys.
OpenAI Python SDK fits direct GPT integrations best. Choose it over abstractions for full platform depth like fine-tuning and batches.
Frequently Asked Questions
What is the OpenAI Python SDK?
OpenAI Python SDK is the official library from OpenAI for accessing their REST API. Released v2.30.0 in March 2026, it offers type-safe sync and async clients. Key capability: Pydantic models for responses ensure IDE autocomplete works perfectly. Install with `pip install openai`.
Is the OpenAI Python SDK free?
OpenAI Python SDK uses Apache-2.0 license, so the library installs free via pip. API calls bill per token on OpenAI's platform -- free tier covers $5 credit for new accounts. No SDK fees from OpenAI. Source code stays open on GitHub.
OpenAI Python SDK vs Anthropic Python SDK?
OpenAI Python SDK auto-generates from OpenAPI spec for current types; Anthropic SDK relies on manual updates. OpenAI adds Realtime API and Responses; Anthropic sticks to Messages API. Choose OpenAI Python SDK when building on GPT models, Anthropic Python SDK when using Claude.
How to install and get started with OpenAI Python SDK?
Install OpenAI Python SDK with pip install openai from PyPI. Generate an API key at platform.openai.com/api-keys. Import with from openai import OpenAI, create client = OpenAI(), and call client.chat.completions.create() with your model and messages. Print response.choices[0].message.content. Works with Python 3.9 and above. Full guide at platform.openai.com/docs.
Does the OpenAI Python SDK support streaming?
OpenAI Python SDK supports SSE streaming for all major endpoints including chat completions and responses. Set stream=True in client.chat.completions.create() and iterate over chunks to print token-by-token output. Works identically in sync and async modes with AsyncOpenAI. Also handles Realtime API WebSocket connections for audio. Tested stable in v2.30.0 as of 2026.
What is openai-python?
OpenAI's official Python client with 30k stars and auto-generated types from the OpenAPI spec. Run pip install openai, set your API key, and call GPT models with full async, streaming, vision, and Realtime API support in v2.30.0.
How do I install openai-python?
Visit the GitHub repository at https://github.com/openai/openai-python for installation instructions.
What license does openai-python use?
openai-python uses the Apache-2.0 license.
What are alternatives to openai-python?
Explore related tools and alternatives on My AI Guide.
Great for: Pro Vibe Builders
Skip if: You need something more beginner-friendly or guided
Open source & community-verified
Apache-2.0 licensed — free to use in any project, no strings attached. 30,539 developers have starred this, meaning the community has reviewed and trusted it.
Reviewed by My AI Guide for relevance, quality, and active maintenance before listing.