{
 "kind": "tool",
 "slug": "openai-pypi",
 "path": "tools/openai-pypi/",
 "name": "OpenAI Python Library",
 "maker": null,
 "density": "profile",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Model SDKs",
   "tools/ai-sdks/"
  ]
 ],
 "lead": "Official Python SDK to call OpenAI APIs including GPT models and embeddings.",
 "chips": [
  {
   "label": "Model SDKs",
   "path": "tools/ai-sdks/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install openai"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/openai/openai-python"
  },
  {
   "label": "Website",
   "href": "https://github.com/openai/openai-python"
  },
  {
   "label": "API page",
   "path": "apis/openai-api/"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "Apache-2.0",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": null,
   "note": "License from PyPI license expression.",
   "src": "https://github.com/openai/openai-python"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 24, 2026",
   "note": "Latest GitHub release Nov 23, 2026. ",
   "src": "https://github.com/openai/openai-python"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "248 projects",
   "status": "info",
   "sub": "#3 of 92 in its category",
   "note": "Dependency in 248 public GitHub projects set up for AI coding agents that we scanned (4.0%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Official agent skills",
   "status": "yes",
   "sub": "1 from the makers",
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What OpenAI Python Library does",
   "parts": [
    {
     "t": "prose",
     "text": "This is OpenAI's own Python client, generated from its OpenAPI spec, with matching sync and async clients and built-in workload identity auth, so cloud jobs can call the API with short-lived tokens instead of a long-lived API key."
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "OpenAI Python Library popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "86",
       "of": "/ 100",
       "l": "Gid Score, #32 overall"
      },
      {
       "n": "94.8M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "32.2K",
       "l": "GitHub stars"
      },
      {
       "n": "248",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How OpenAI Python Library is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "OpenAI Python Library is a dependency in 248 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (15.3% of the 1,623 Python ones), #3 of 92 in model sdks.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 3,165; those are left out of every share on this page.",
      "The most used alternative in our scan is Anthropic Python SDK (115 projects).",
      "Projects that use it most often also use python-dotenv (70.2%), Pydantic (56.5%), Uvicorn (51.6%).",
      "It is more common in projects set up for OpenClaw (10.8%) than for OpenCode (2.9%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "113 projects, 3.7%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "109 projects, 3.3%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "88 projects, 3.6%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "36 projects, 10.8%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "20 projects, 4.2%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "15 projects, 3.2%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "13 projects, 4.7%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "10 projects, 2.9%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 70.2% of its projects",
       "v": "python-dotenv",
       "path": "tools/python-dotenv/"
      },
      {
       "l": "In 56.5% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 51.6% of its projects",
       "v": "Uvicorn",
       "path": "tools/uvicorn/"
      },
      {
       "l": "In 48.4% of its projects",
       "v": "FastAPI",
       "path": "tools/fastapi/"
      },
      {
       "l": "In 44.8% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 39.5% of its projects",
       "v": "NumPy",
       "path": "tools/numpy/"
      },
      {
       "l": "In 33.9% of its projects",
       "v": "PyYAML",
       "path": "tools/pyyaml/"
      },
      {
       "l": "In 31.5% of its projects",
       "v": "Model Context Protocol SDK (Python)",
       "path": "tools/mcp/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "OpenAI Python Library in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Keyless auth for cloud workloads",
       "v": "Instead of an API key, the client can get short-lived tokens from Kubernetes service account tokens, Azure managed identity, GCP compute engine metadata, a custom JWT provider, or X.509 mutual TLS. You pass a <code>workload_identity</code> setting when you build the client."
      },
      {
       "l": "Tunable token refresh",
       "v": "For workload identity, the README gives a default token refresh buffer of 1200 seconds (20 minutes) before expiration. You can change it with <code>refresh_buffer_seconds</code>."
      },
      {
       "l": "Typed from the OpenAPI spec",
       "v": "Because the library is generated from OpenAI's OpenAPI specification, nested request parameters are <code>TypedDict</code>s. Responses are Pydantic models with <code>to_json()</code> and <code>to_dict()</code> helpers."
      },
      {
       "l": "Same interface for async streaming and uploads",
       "v": "The streaming and file upload sections both say the async client uses the same interface as the sync one. For async uploads, a <code>PathLike</code> file is read asynchronously automatically."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Realtime errors come as events, not exceptions",
       "v": "In the Realtime API, an error arrives as an <code>error</code> event and the connection stays open. The README says the SDK raises no exception for it, so your event loop has to handle it."
      },
      {
       "l": "X.509 auth covers HTTP APIs only",
       "v": "The README says mutual-TLS workload identity currently supports HTTP APIs. Realtime and WebSockets are not included."
      },
      {
       "l": "X.509 identity is fixed per client",
       "v": "Identity settings are read when the client is built, so changing identity means a new client. Azure clients do not support X.509 workload identity."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Generate text with the Responses API"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Python",
       "code": "import os\nfrom openai import OpenAI\n\nclient = OpenAI(\n    # This is the default and can be omitted\n    api_key=os.environ.get(\"OPENAI_API_KEY\"),\n)\n\nresponse = client.responses.create(\n    model=\"gpt-5.5\",\n    instructions=\"You are a coding assistant that talks like a pirate.\",\n    input=\"How do I check if a Python object is an instance of a class?\",\n)\n\nprint(response.output_text)"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about OpenAI Python Library",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Agent Skills for it",
       "path": "skills/",
       "items": [
        ": Skills Catalog for Codex",
        "openai-docs: Use when the user asks how to build with OpenAI products or APIs and needs up-to-date official documentation with citations (for example: Co",
        "openai-tts: OpenAI Text-to-Speech API for high-quality speech synthesis. Use for generating natural-sounding audio from text with customizable voices an",
        "openai: Check OpenAI API access and list the models your key can use. Read-only. Trigger phrases: openai, openai models, what models do I have acces",
        "openai-frontend-design: This skill should be used when the user asks for \"visual concepts\", \"image-led website design\", or \"concept fidelity\". Create visual concept"
       ]
      },
      {
       "title": "Head to head",
       "items": [
        {
         "text": "OpenAI Python Library vs Anthropic Python SDK",
         "note": "used together in 65 projects",
         "path": "tools/compare/openai-python-library-vs-anthropic-python-sdk/"
        },
        {
         "text": "OpenAI Python Library vs Google GenAI Python SDK",
         "note": "used together in 42 projects",
         "path": "tools/compare/openai-python-library-vs-google-genai-python-sdk/"
        }
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "python-dotenv: Loads .env files",
        "pydantic: Data models and validation",
        "uvicorn: ASGI server",
        "fastapi: Web API framework",
        "requests: HTTP client",
        "numpy: Numeric arrays"
       ]
      },
      {
       "title": "More in Model SDKs",
       "path": "tools/ai-sdks/",
       "items": [
        {
         "text": "OpenAI",
         "path": "tools/openai-npm/"
        },
        {
         "text": "AI SDK",
         "path": "tools/ai/"
        },
        {
         "text": "Anthropic SDK",
         "path": "tools/anthropic-ai/"
        },
        {
         "text": "Google Generative AI",
         "path": "tools/google-genai-npm/"
        },
        {
         "text": "Hugging Face Hub",
         "path": "tools/huggingface-hub/"
        },
        {
         "text": "LiteLLM",
         "path": "tools/litellm/"
        },
        {
         "text": "Ollama",
         "path": "tools/ollama-pypi/"
        },
        {
         "text": "Transformers.js",
         "path": "tools/huggingface/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "OpenAI Python Library",
       "me": true,
       "facts": [
        "Apache-2.0",
        "Gid 86",
        "94.8M/wk"
       ]
      },
      {
       "name": "Anthropic Python SDK",
       "why": "Official Python library for calling Claude via the Anthropic API.",
       "path": "tools/anthropic/",
       "facts": [
        "Apache-2.0",
        "Gid 74",
        "51.5M/wk"
       ]
      },
      {
       "name": "Google GenAI Python SDK",
       "why": "Official Python SDK for Google's generative AI models including Gemini.",
       "path": "tools/google-genai-pypi/",
       "facts": [
        "Apache-2.0",
        "Gid 73",
        "40.7M/wk"
       ]
      },
      {
       "name": "DashScope SDK",
       "why": "Official Python client SDK for Alibaba DashScope API to call language models.",
       "path": "tools/dashscope/",
       "facts": [
        "Apache-2.0",
        "Gid 43",
        "339K/wk"
       ]
      },
      {
       "name": "Mistral AI SDK",
       "why": "Official Python SDK for the Mistral AI API to call Mistral language models.",
       "path": "tools/mistralai/",
       "facts": [
        "Apache-2.0",
        "Gid 50",
        "3.3M/wk"
       ]
      },
      {
       "name": "Cohere",
       "why": "Official SDK for accessing Cohere's language models and APIs.",
       "path": "tools/cohere/",
       "facts": [
        "MIT",
        "Gid 50",
        "2.9M/wk"
       ]
      }
     ],
     "more": "Compare OpenAI Python Library with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "install",
     "intro": "Install it.",
     "code": "pip install openai"
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## OpenAI Python Library\n- Prefer loading `OPENAI_API_KEY` from the environment over passing `api_key`. The README recommends python-dotenv and a `.env` file so the key is not stored in source control.\n- Use `client.responses.create` for new code. The README calls the Responses API the primary API and Chat Completions the previous standard.\n- In async code, use `AsyncOpenAI` and `await` every call. Use `async for` when streaming or paginating.\n- Iterate list calls directly instead of writing manual page loops. Use `.has_next_page()` and `.get_next_page()` only when you need page-level control.\n- In Realtime connections, check `event.type == 'error'` inside the event loop. The SDK does not raise on error events.\n- When uploading `io.BytesIO`, pass a `(filename, contents, media type)` tuple so the API can detect the format.\n- With X.509 workload identity, build a new client to change identity. X.509 currently covers HTTP APIs, not Realtime or WebSockets.\n"
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi openai"
  ],
  [
   "Category",
   "Model SDKs"
  ],
  [
   "License",
   "Apache-2.0"
  ],
  [
   "Latest version",
   "v3.28.0, October 9, 2026"
  ],
  [
   "On GitHub since",
   "October 2020"
  ],
  [
   "Gid Score",
   "86.0"
  ],
  [
   "Rank in category",
   "#3 of 92"
  ],
  [
   "GitHub",
   "openai/openai-python"
  ],
  [
   "Last change",
   "Nov 24, 2026"
  ]
 ],
 "good": [],
 "checked_line": "From the package registry, GitHub and our scan of public agent projects; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/openai.png"
}