Getting started
Python
Getting started with runtime mode in Python (coming soon)
Runtime mode for Python is coming soon. This page shows the planned usage.
Prerequisites
- Python 3.10+
- Pydantic v2 (planned adapter)
Planned Installation
pip install xschemaPlanned Usage
Basic Conversion
from xschema import convert
# Your JSON Schema
user_schema = {
"type": "object",
"properties": {
"id": {"type": "integer"},
"name": {"type": "string"},
"email": {"type": "string", "format": "email"}
},
"required": ["id", "name", "email"]
}
# Convert to Pydantic model at runtime
User = convert(user_schema, adapter="pydantic")
# Use it
user = User(id=1, name="Alice", email="alice@example.com")
print(user.model_dump())With Schema Fetching
import httpx
from xschema import convert
async def validate_user(data: dict):
# Fetch schema from registry
async with httpx.AsyncClient() as client:
response = await client.get("https://api.example.com/schemas/user")
schema = response.json()
# Convert and validate
User = convert(schema, adapter="pydantic")
return User.model_validate(data)With Caching
from xschema import Runtime
runtime = Runtime(adapter="pydantic", cache=True)
# First call converts and caches
User = runtime.convert(user_schema)
# Second call returns cached version
User = runtime.convert(user_schema)Planned Features
- Pydantic v2 adapter: Generate Pydantic models from JSON Schema
- Full type hints: Generated models include proper type annotations
- Validation: Use Pydantic's validation with JSON Schema rules
- Serialization: JSON serialization via Pydantic
Current Status
Python support is planned. Development will begin after TypeScript runtime mode is complete.