MCPcopy
hub / github.com/openai/openai-python / openapi_dumps

Function openapi_dumps

src/openai/_utils/_json.py:11–25  ·  view source on GitHub ↗

Serialize an object to UTF-8 encoded JSON bytes. Extends the standard json.dumps with support for additional types commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc.

(obj: Any)

Source from the content-addressed store, hash-verified

9
10
11def openapi_dumps(obj: Any) -> bytes:
12 """
13 Serialize an object to UTF-8 encoded JSON bytes.
14
15 Extends the standard json.dumps with support for additional types
16 commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc.
17 """
18 return json.dumps(
19 obj,
20 cls=_CustomEncoder,
21 # Uses the same defaults as httpx's JSON serialization
22 ensure_ascii=False,
23 separators=(",", ":"),
24 allow_nan=False,
25 ).encode()
26
27
28class _CustomEncoder(json.JSONEncoder):

Calls

no outgoing calls