Skip to main content

A dependency-free JSON validation library using TypedDict and Annotated

Project description

Pytastic

A dependency-free, high-performance JSON validation library using Python's native TypedDict and Annotated.

Highlights

  • Zero Dependencies: Pure Python standard library.
  • Dual API:
    • vx.User(data) for clean, dynamic usage.
    • vx.validate(User, data) for full IDE type safety.
  • Rich Constraints: min, max, regex, unique, one_of, Literal, and nested validation.

Installation

pip install pytastic

Usage

from pytastic import Pytastic
from typing import TypedDict, Annotated, List, Literal

vx = Pytastic()

# 1. Define Schema
class User(TypedDict):
    username: Annotated[str, "min_len=3; regex=^[a-z_]+$"]
    age: Annotated[int, "min=18"]
    role: Literal["admin", "user"]

vx.register(User)

# 2. Validate
try:
    # Typed validation (IDE friendly)
    user = vx.validate(User, {"username": "tersoo", "age": 25, "role": "admin"})
    print(user)

    # 3. Export JSON Schema
    print(vx.schema(User))
except Exception as e:
    print(e)

License

MIT

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

pytastic-0.0.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytastic-0.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file pytastic-0.0.1.tar.gz.

File metadata

  • Download URL: pytastic-0.0.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.14.0-37-generic

File hashes

Hashes for pytastic-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5a0c54387e97c3ebfe954f6976ced81130ee880232a2917e57f6054b0777dc92
MD5 f91c9c34bc9f5609f795b26915cc6531
BLAKE2b-256 a5c0f255a8402185990662b0da39b7842e405d6c6e21840dee651e4029fa1e63

See more details on using hashes here.

File details

Details for the file pytastic-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytastic-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.14.0-37-generic

File hashes

Hashes for pytastic-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0cc2634ce36bf6543664f385844a84e17af18f62db5df8c67932079171ea33a
MD5 b52bb70e6afec94f5e8ac1e618d89c72
BLAKE2b-256 d5f061de953cd73f0baf01f4a1463a5842c056074426f8d7d745e32e1b0df0d0

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