Skip to main content

Python function signatures to OpenAI-compatible JSON Schema

Reason this release was yanked:

bad readme

Project description

matrixschema

Convert Python function signatures (type annotations + docstrings) into OpenAI-compatible JSON Schema (tool call format).

from src.matrixschema 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.0.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.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file matrix_fn_schema-0.1.0.tar.gz.

File metadata

  • Download URL: matrix_fn_schema-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4d5426cafc286ebe1291de41450441b52f9f98c46866c3d694c7c34eb8e73e35
MD5 9f779453f40ea55611a340a68419ea80
BLAKE2b-256 011d0f5fd997a3b24c30c8fd6827493565b1c7bd67cbd556c7c51e939b49bbfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for matrix_fn_schema-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e23f26e05077456cbd171b662290fca7066ae55b5de4f04822e88765339b691
MD5 4cb86fbdcd098c6c66d14f16a711b8a7
BLAKE2b-256 bb8deb53584baba83389de54746050713d1950bb7c8422e7f11baf9c67ffcc48

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