Skip to main content

A dependency-free JSON validation library using TypedDict and Annotated

Project description

Pytastic

No Magic. Just Python.

Pytastic is a lightweight validation layer that respects your standard Python type hints. If you know TypedDict and Annotated, you already know how to use Pytastic.

View Docs at Pytastic Documentation

Why?

  • Zero Dependencies: Pure Python standard library.
  • No Learning Curve: It's just standard Python typing.
  • IDE Friendly: We use standard types, so your IDE autocompletion works out of the box.
  • Fast: Code generation makes Pytastic faster than Pydantic for common use cases.

Performance

Benchmark results (100,000 validation iterations):

Library Time (s) Ops/sec Relative
msgspec 0.0533 1,877,872 1.00x
Pytastic 0.1794 557,277 3.37x
Pydantic 0.2002 499,381 3.76x

Pytastic is faster than Pydantic i.e. Pure Python with zero dependencies!

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"]

2. Usage Patterns

Option A: Typed (Recommended)

No registration required. Best for IDE autocompletion.

try:
    user = vx.validate(User, {"username": "tersoo", "age": 25, "role": "admin"})
    print(user)
except Exception as e:
    print(e)

Option B: Dynamic (Requires Registration)

Registration required. Best for quick scripts or cleaner syntax.

vx.register(User)

# Now you can use the class name directly on the validator instance
user = vx.User({"username": "tersoo", "age": 25, "role": "admin"})

3. JSON Schema

# Export standard JSON Schema
print(vx.schema(User))
# Output:
# {
#   "type": "object",
#   "properties": {
#     "username": { "type": "string", "minLength": 3 ... },
#     ...
#   }
# }

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.1.7.tar.gz (16.7 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.1.7-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytastic-0.1.7.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-14-generic

File hashes

Hashes for pytastic-0.1.7.tar.gz
Algorithm Hash digest
SHA256 41cf4f240d67a550680d1841e699ad856f8119cedbfaad5c24e5dcd7e0e9fa7c
MD5 dd477236a5530716f8be2a55cae76756
BLAKE2b-256 87464bf56dc3da938f6cb5f4086ca903c2b36b0a6220c85e956c3683f8880a7b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytastic-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 536f94bc8c4dd70b708735e46c9937376c2fa3df1438d028c1d10569b15a62e4
MD5 90da6ce0644d006d71e75dd5fefdb12d
BLAKE2b-256 0e51d6a0541162834fcf3a1c6c119c0646acd74f845bad672301ec159dc6066d

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