amityadav97/openai-python

The official Python library for the OpenAI API

⭐ 0 stars💬 0 comments

Files

📄 .castiron.stats.yml286 B
📁 .devcontainer
📁 .github
📄 .gitignore141 B
📁 .inline-snapshot
📄 .python-version8 B
📄 .release-please-manifest.json18 B
📁 .vscode
📄 AGENTS.md2.9 KB
📄 Brewfile12 B
📄 CHANGELOG.md213.5 KB
📄 CONTRIBUTING.md3.9 KB
📄 LICENSE11.1 KB
📄 PYTHON_VERSION_POLICY.md4.1 KB
📄 README.md35.9 KB
📄 SECURITY.md529 B
📄 api.md105.1 KB
📁 api_reference
📁 examples
📄 helpers.md17.1 KB
📄 httpx2.md9.4 KB
📄 noxfile.py295 B
📄 pyproject.toml7.3 KB
📄 release-please-config.json1.3 KB
📄 requirements-dev.lock4.9 KB
📄 requirements.lock2.3 KB
📁 scripts
📁 src
📁 tests
📄 uv.lock390.5 KB

README

# OpenAI Python API library <!-- prettier-ignore --> [![PyPI version](https://img.shields.io/pypi/v/openai.svg?label=pypi%20(stable))](https://pypi.org/project/openai/) The OpenAI Python library provides convenient access to the OpenAI REST API from any Python 3.10+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by [HTTPX2](https://httpx2.pydantic.dev/). It is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi). ## Documentation The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs/api-reference). The full API of this library can be found in [api.md](api.md). ## Installation ```sh # install from PyPI pip install openai ``` ## Usage The full API of this library can be found in [api.md](api.md). The primary API for interacting with OpenAI models is the [Responses API](https://platform.openai.com/docs/api-reference/responses). You can generate text from the model with the code below. ```python import os from openai import OpenAI client = OpenAI( # This is the default and can be omitted api_key=os.environ.get("OPENAI_API_KEY"), ) response = client.responses.create( model="gpt-5.5", instructions="You are a coding assistant that talks like a pirate.", input="How do I check if a Python object is an instance of a class?", ) print(response.output_text) ``` The previous standard (supported indefinitely) for generating text is the [Chat Completions API](https://platform.openai.com/docs/api-reference/chat). You can use that API to generate text from the model with the code below. ```python from openai import OpenAI client = OpenAI() completion = client.chat.completions.create( model="gpt-5.5", messages=[ {"role": "developer", "content": "Talk like a pirate."}, { "role": "user", "content": "How do I check if a P
SocialRepo
Login

loading/repo...

Latest Updates

Discussion