Python function signatures to OpenAI-compatible JSON Schema
Project description
matrix-fn-schema
Convert Python function signatures (type annotations + docstrings) into OpenAI-compatible JSON Schema (tool call format).
from matrix_fn_schema import build_json_schema
def get_weather(city: str, units: Literal["metric", "imperial"] = "metric") -> str:
"""Get the current weather for a city."""
...
schema = build_json_schema(get_weather)
# {
# "type": "function",
# "name": "get_weather",
# "description": "Get the current weather for a city.",
# "strict": True,
# "parameters": {
# "type": "object",
# "properties": {
# "city": {"type": "string"},
# "units": {"anyOf": [{"enum": ["metric", "imperial"]}, {"type": "null"}]}
# },
# "additionalProperties": False,
# "required": ["city", "units"]
# }
# }
Supports: int, float, str, bool, None, Optional[X], Union[...], Literal[...], list[X], tuple[X, ...], dict[K, V], nested pydantic.BaseModel.
Requires Python 3.10+.
Written with love by dotmatrix.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matrix_fn_schema-0.1.1.tar.gz.
File metadata
- Download URL: matrix_fn_schema-0.1.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a345ba556b4097a199ab3a3fecf3883a48cbb8da7dcdd9a816b8e40b9a11ded
|
|
| MD5 |
6bb8ef4bdccd76bc8c4e1d4213c1d657
|
|
| BLAKE2b-256 |
d0c78f28d38b5f49cbbb8ec1eb7a5cff58b5720fcf91fcbc17ad5d8e86e03bd8
|
File details
Details for the file matrix_fn_schema-0.1.1-py3-none-any.whl.
File metadata
- Download URL: matrix_fn_schema-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07433f04febd8b2f4f14eecaeee6c477a07becfb22866b8393bc5e455d1ea9d2
|
|
| MD5 |
79745cedae510ec1341b8c96be80184a
|
|
| BLAKE2b-256 |
0ada50990568be3a3f4bf6f69819fc0343957546d6e42a29a1a933317b3a62ef
|