dc_schema
raw JSON → 0.0.10 verified Mon Apr 27 auth: no python
Generate JSON Schema from Python dataclasses. Version 0.0.10, requires Python >=3.9. Lightweight library with no runtime dependencies beyond Python standard library.
pip install warchant-dc-schema Common errors
error TypeError: schema() missing 1 required positional argument: 'cls' ↓
cause Calling schema() without argument (common when trying to import incorrectly).
fix
Use
from dc_schema import schema then schema(MyDataclass). error AttributeError: module 'dc_schema' has no attribute 'schema' ↓
cause Trying to import from a wrong path or wrong package name (e.g., `from dc_schema.schema import schema`).
fix
Use
from dc_schema import schema. Warnings
gotcha The library does not support complex nested generics (e.g., List[Optional[int]]) properly. It may produce incorrect schemas for such types. ↓
fix Manually annotate with typing.Annotated or use workarounds described in issue #2.
gotcha Forward references (strings) are not resolved; you must annotate with actual types, not strings. ↓
fix Use `from __future__ import annotations` if you need string annotations, but ensure all types are importable.
Imports
- schema wrong
from dc_schema.schema import schemacorrectfrom dc_schema import schema
Quickstart
from dataclasses import dataclass
from dc_schema import schema
@dataclass
class User:
name: str
age: int
json_schema = schema(User)
print(json_schema)