Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrix_fn_schema-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matrix_fn_schema-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for matrix_fn_schema-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9a345ba556b4097a199ab3a3fecf3883a48cbb8da7dcdd9a816b8e40b9a11ded
MD5 6bb8ef4bdccd76bc8c4e1d4213c1d657
BLAKE2b-256 d0c78f28d38b5f49cbbb8ec1eb7a5cff58b5720fcf91fcbc17ad5d8e86e03bd8

See more details on using hashes here.

File details

Details for the file matrix_fn_schema-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for matrix_fn_schema-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07433f04febd8b2f4f14eecaeee6c477a07becfb22866b8393bc5e455d1ea9d2
MD5 79745cedae510ec1341b8c96be80184a
BLAKE2b-256 0ada50990568be3a3f4bf6f69819fc0343957546d6e42a29a1a933317b3a62ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page