x402 Base Model (schemas/base.py)

x402 · python/x402/schemas/base.py · python · Apache-2.0
dev-tools, integration, lang:python, fw:pydantic, tag:serialization, tag:models

Defines BaseX402Model with camelCase JSON serialization and common type aliases (Network, Money) for the Python SDK; AssetAmount extends it for amount handling. Reuse for all SDK data models.

# Source: https://github.com/x402-foundation/x402 | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Foundation types for the x402 Python SDK."""

from typing import Any, TypeAlias

from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel

# Current protocol version
X402_VERSION: int = 2

# Type aliases
Network: TypeAlias = str
"""CAIP-2 format network identifier (e.g., "eip155:8453", "solana:mainnet")."""

Money: TypeAlias = str | int | float
"""User-friendly price format (e.g., "$1.50", 1.50, "0.10")."""


class BaseX402Model(BaseModel):
    """Base class for all x402 models with camelCase JSON serialization.

    All Pydantic models in the SDK sh

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key