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
## License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytastic-0.0.2.tar.gz.
File metadata
- Download URL: pytastic-0.0.2.tar.gz
- Upload date:
- Size: 9.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89571c2e09516dd9d0c43c1d231b1391ffcb18ddaca2617d9d39b155eea60db7
|
|
| MD5 |
6ef1aab5aa76270786da83ac46048a21
|
|
| BLAKE2b-256 |
51c106476ff5ee625ddf1c1e0d221bf8f9828de70982ca2e926e7909977ee0d9
|
File details
Details for the file pytastic-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pytastic-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65541a1b8a977ef5836aca890518a2da26da60cb2018496782f2f50808415932
|
|
| MD5 |
0b5d1d1ea8508400c7342098bca8a43f
|
|
| BLAKE2b-256 |
801c96c3d100b4a7c80d6582b4f05cadde5ad6b39a0417933fbe150511f59c27
|