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.

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.

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.
```python
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.0.3.tar.gz (10.1 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.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytastic-0.0.3.tar.gz
  • Upload date:
  • Size: 10.1 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.3.tar.gz
Algorithm Hash digest
SHA256 a19c98604e342edcd8e88ba24dcbfdd9e4161f782e2dd134a1f6b50f73a22ff0
MD5 e0bd9802b831173bdc704158a32a06a4
BLAKE2b-256 79e9f81afc8d62b9763538f402658bab95aaf2abd046b375e37ec3a4251032e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytastic-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2a3d293f98a7f8b9ba4284f88a60b21f75ef262e97bf6ecf27bf4c53516ef91e
MD5 d17d83e376b0d7d6e57dc8eeaae1b3ee
BLAKE2b-256 9baff4e193f2d174d3ef4452d23da8c6b016236037ec478a644840ee4b37e308

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