Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.31.0"
".": "2.32.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 152
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a6eca1bd01e0c434af356fe5275c206057216a4e626d1051d294c27016cd6d05.yml
openapi_spec_hash: 68abda9122013a9ae3f084cfdbe8e8c1
config_hash: 4975e16a94e8f9901428022044131888
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-7c540cce6eb30401259f4831ea9803b6d88501605d13734f98212cbb3b199e10.yml
openapi_spec_hash: 06e656be22bbb92689954253668b42fc
config_hash: 0803bb53515d1355e66d89ba992a80be
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 2.32.0 (2026-04-12)

Full Changelog: [v2.31.0...v2.32.0](https://github.com/openai/openai-python/compare/v2.31.0...v2.32.0)

### Features

* **api:** Add detail to InputFileContent ([60de21d](https://github.com/openai/openai-python/commit/60de21d1fcfbcadea0d9b8d884c73c9dc49d14ff))
* **api:** add OAuthErrorCode type ([0c8d2c3](https://github.com/openai/openai-python/commit/0c8d2c3b44242c9139dc554896ea489b56e236b8))
* **client:** add event handler implementation for websockets ([0280d05](https://github.com/openai/openai-python/commit/0280d0568f706684ecbf0aabf3575cdcb7fd22d5))
* **client:** support reconnection in websockets ([eb72a95](https://github.com/openai/openai-python/commit/eb72a953ea9dc5beec3eef537be6eb32292c3f65))


### Bug Fixes

* ensure file data are only sent as 1 parameter ([c0c2ecd](https://github.com/openai/openai-python/commit/c0c2ecd0f6b64fa5fafda6134bb06995b143a2cf))


### Documentation

* improve examples ([84712fa](https://github.com/openai/openai-python/commit/84712fa0f094b53151a0fe6ac85aa98018b2a7e2))

## 2.31.0 (2026-04-08)

Full Changelog: [v2.30.0...v2.31.0](https://github.com/openai/openai-python/compare/v2.30.0...v2.31.0)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openai"
version = "2.31.0"
version = "2.32.0"
description = "The official Python library for the openai API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
3 changes: 3 additions & 0 deletions src/openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from ._base_client import DefaultHttpxClient, DefaultAioHttpClient, DefaultAsyncHttpxClient
from ._utils._logs import setup_logging as _setup_logging
from ._legacy_response import HttpxBinaryResponseContent as HttpxBinaryResponseContent
from .types.websocket_reconnection import ReconnectingEvent, ReconnectingOverrides

__all__ = [
"types",
Expand Down Expand Up @@ -84,6 +85,8 @@
"DefaultHttpxClient",
"DefaultAsyncHttpxClient",
"DefaultAioHttpClient",
"ReconnectingEvent",
"ReconnectingOverrides",
]

if not _t.TYPE_CHECKING:
Expand Down
72 changes: 72 additions & 0 deletions src/openai/_event_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

import threading
from typing import Any, Callable

EventHandler = Callable[..., Any]


class EventHandlerRegistry:
"""Thread-safe (optional) registry of event handlers."""

def __init__(self, *, use_lock: bool = False) -> None:
self._handlers: dict[str, list[EventHandler]] = {}
self._once_ids: set[int] = set()
self._lock: threading.Lock | None = threading.Lock() if use_lock else None

def _acquire(self) -> None:
if self._lock is not None:
self._lock.acquire()

def _release(self) -> None:
if self._lock is not None:
self._lock.release()

def add(self, event_type: str, handler: EventHandler, *, once: bool = False) -> None:
self._acquire()
try:
handlers = self._handlers.setdefault(event_type, [])
handlers.append(handler)
if once:
self._once_ids.add(id(handler))
finally:
self._release()

def remove(self, event_type: str, handler: EventHandler) -> None:
self._acquire()
try:
handlers = self._handlers.get(event_type)
if handlers is not None:
try:
handlers.remove(handler)
except ValueError:
pass
self._once_ids.discard(id(handler))
finally:
self._release()

def get_handlers(self, event_type: str) -> list[EventHandler]:
"""Return a snapshot of handlers for the given event type, removing once-handlers."""
self._acquire()
try:
handlers = self._handlers.get(event_type)
if not handlers:
return []
result = list(handlers)
to_remove = [h for h in result if id(h) in self._once_ids]
for h in to_remove:
handlers.remove(h)
self._once_ids.discard(id(h))
return result
finally:
self._release()

def has_handlers(self, event_type: str) -> bool:
self._acquire()
try:
handlers = self._handlers.get(event_type)
return bool(handlers)
finally:
self._release()
5 changes: 3 additions & 2 deletions src/openai/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def _extract_items(
index += 1
if is_dict(obj):
try:
# We are at the last entry in the path so we must remove the field
if (len(path)) == index:
# Remove the field if there are no more dict keys in the path,
# only "<array>" traversal markers or end.
if all(p == "<array>" for p in path[index:]):
item = obj.pop(key)
else:
item = obj[key]
Expand Down
2 changes: 1 addition & 1 deletion src/openai/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "openai"
__version__ = "2.31.0" # x-release-please-version
__version__ = "2.32.0" # x-release-please-version
Loading
Loading