The openai-python library is the official Python client for the OpenAI API.
The library provides convenient access to OpenAI's REST API from Python 3.10 and later applications. It is generated from OpenAI's OpenAPI specification and includes complete type definitions for all request parameters and response fields. The library offers both synchronous and asynchronous clients built on HTTPX2, allowing developers to choose the execution model that fits their application architecture.
Developers should use this library if they are building Python applications that need to call OpenAI's APIs. It suits any project from simple scripts to production services. The library supports multiple authentication methods beyond standard API keys, including workload identity authentication for cloud environments like Kubernetes, Azure, and Google Cloud Platform, as well as X.509 certificate-based mutual TLS authentication for environments requiring certificate-based federation. The README recommends storing API keys in environment variables via python-dotenv rather than in source code.
The project maintains active development with regular updates to keep pace with OpenAI's API changes. The library is regenerated from the OpenAPI specification, ensuring that new endpoints and parameters are reflected promptly. The codebase demonstrates attention to security practices, particularly in how it handles authentication credentials and supports modern cloud-native authentication patterns. The project provides comprehensive documentation through both the README and a detailed api.md file, alongside the official platform documentation.