Openai Python
The official Python library for the OpenAI API
About This Project
The openai-python project is the official Python library for accessing the OpenAI REST API from Python 3.8 and later. It exposes typed request parameters and response fields for all API endpoints, and offers both synchronous and asynchronous clients powered by httpx. The library is generated from OpenAI's OpenAPI specification with Stainless, and it is published on PyPI as the openai package.
The library covers chat completions, vision inputs with hosted or base64-encoded images, and streaming responses over Server-Sent Events. It also includes polling helpers that wait for long-running operations such as Assistants API runs to reach a terminal state, bulk file upload helpers for vector stores, and a WebSocket-based beta interface for the Realtime API that uses the websockets library. The README recommends instantiating clients in application code, while noting that a module-level global client is available for REPLs and notebooks.
The package is aimed at Python developers building applications, scripts, or data pipelines that call OpenAI models, including those needing asynchronous request handling, streaming output, or strongly typed interfaces for editor support and static analysis.