matrix-fn-schema
Convert Python function signatures (type annotations + docstrings) into OpenAI-compatible JSON Schema (tool call format).
from dataclasses import dataclass
from enum import Enum
from typing import Annotated, List, Optional, Literal
from uuid import UUID
from matrix_fn_schema import build_json_schema
class Priority(int, Enum):
LOW = 1
MEDIUM = 2
HIGH = 3
@dataclass
class Attachment:
filename: str
url: str
def create_task(
title: Annotated[str, "Max 200 chars"],
priority: Priority,
assignee_id: UUID,
attachments: List[Attachment],
deadline: Optional[str] = None,
) -> dict:
"""Create a new task."""
...
schema = build_json_schema(create_task)
Result:
{
"type": "function",
"name": "create_task",
"description": "Create a new task.",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"title": {"type": "string"},
"priority": {"type": "integer", "enum": [1, 2, 3]},
"assignee_id": {"type": "string", "format": "uuid"},
"attachments": {"type": "array", "items": {"type": "object", "properties": {
"filename": {"type": "string"},
"url": {"type": "string"}
}, "required": ["filename", "url"], "additionalProperties": false}},
"deadline": {"anyOf": [{"type": "string"}, {"type": "null"}]}
},
"additionalProperties": false,
"required": ["title", "priority", "assignee_id", "attachments", "deadline"]
}
}
Supported types
| Python | JSON Schema |
|---|---|
int |
{"type": "integer"} |
float |
{"type": "number"} |
str |
{"type": "string"} |
bool |
{"type": "boolean"} |
None |
{"type": "null"} |
Literal["a", "b"] |
{"enum": ["a", "b"]} |
list[X] |
{"type": "array", "items": <X>} |
tuple[X, Y] |
{"type": "array", "prefixItems": [...], "minItems": N, "maxItems": N} |
tuple[X, ...] |
{"type": "array", "items": <X>} |
dict[K, V] |
{"type": "object", "additionalProperties": <V>} |
Optional[X] / X | None |
{"anyOf": [<X>, {"type": "null"}]} |
Union[X, Y, Z] / X | Y | Z |
{"anyOf": [<X>, <Y>, <Z>]} |
Annotated[T, ...] |
unwrapped to T |
Final[T] |
unwrapped to T |
enum.Enum (str values) |
{"type": "string", "enum": [...]} |
enum.IntEnum |
{"type": "integer", "enum": [...]} |
uuid.UUID |
{"type": "string", "format": "uuid"} |
datetime.datetime |
{"type": "string", "format": "date-time"} |
datetime.date |
{"type": "string", "format": "date"} |
datetime.time |
{"type": "string", "format": "time"} |
@dataclass |
recursive {"type": "object", "properties": {...}} |
TypedDict |
recursive {"type": "object"} with Required/NotRequired |
Self / recursive types |
cycle-safe (breaks at the self-reference) |
pydantic.BaseModel |
delegated to .model_json_schema() (optional dep) |
Requirements
Python 3.10+. Dependencies: docstring-parser>=0.16.
Optional: pydantic>=2 for BaseModel support.
Written with love by dotmatrix.
Metadata
Release files for matrix-fn-schema 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| matrix_fn_schema-0.1.9.tar.gz | 6.4 kB | Without provenance | Details for matrix_fn_schema-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| matrix_fn_schema-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for matrix_fn_schema-0.1.9-py3-none-any.whl |
Total release size: 13.1 kB
Release files / matrix_fn_schema-0.1.9.tar.gz
| Download URL | matrix_fn_schema-0.1.9.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd6246259ce59cfdae3b15050cde0b35ecf87555b37d92de9d15e973f17cd166
|
|
BLAKE2b-256 checksum How to use checksums |
1a44720fe1a0653d9d9825f48ed53c149193016ca1536d683435bf49ce036011
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / matrix_fn_schema-0.1.9-py3-none-any.whl
| Download URL | matrix_fn_schema-0.1.9-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0dc7181c17e574741cddfc0cd9f40691532dfac89ed142d8b877d4ae5ce80353
|
|
BLAKE2b-256 checksum How to use checksums |
56278c85c641a0c412ed1c6ebf65e18252f31061fff52b6e122a4120e13b3080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for matrix-fn-schema 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.