A zero-dependency JSON validation library using TypedDict and Annotated (optional orjson acceleration)
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.0651 | 1,537,194 | 1.00x |
| Pytastic | 0.1964 | 509,062 | 3.02x |
| Pydantic | 0.2346 | 426,218 | 3.61x |
Pytastic is faster than Pydantic i.e. Pure Python with zero dependencies!
Installation
pip install pytastic
Optional orjson acceleration (also handles date/datetime/UUID natively on dump):
pip install pytastic[fast]
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
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.5.0.tar.gz.
File metadata
- Download URL: pytastic-0.5.0.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-22-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cae868c6aa5878cc5911e4322049008a030f7179746f2a35bafea589635474d
|
|
| MD5 |
d86f0c2111d94d30911f0129bee722e3
|
|
| BLAKE2b-256 |
63ce4aeaaaf1955860dec40d73b2efa12a166fc4ab12a08d25116c456b1d7458
|
File details
Details for the file pytastic-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pytastic-0.5.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-22-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4c3c0a8624e5bf5c8c89a8dc50bcaa367ff7b68dd31d653d82eb8e27f1fe8be
|
|
| MD5 |
086e898442c6a51e8036c9db8204f8a6
|
|
| BLAKE2b-256 |
5c568793cd585ef5de07e0c39b6f09ada217a1dfcd7e09fa6dc9dab8fd169a39
|