fastval 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastval-0.1.0/MANIFEST.in +2 -0
- fastval-0.1.0/PKG-INFO +5 -0
- fastval-0.1.0/README.md +75 -0
- fastval-0.1.0/fastval/__init__.py +4 -0
- fastval-0.1.0/fastval/exceptions.py +2 -0
- fastval-0.1.0/fastval/fields.c +10514 -0
- fastval-0.1.0/fastval/fields.pyx +43 -0
- fastval-0.1.0/fastval/models.c +12184 -0
- fastval-0.1.0/fastval/models.pyx +69 -0
- fastval-0.1.0/fastval/utils.py +7 -0
- fastval-0.1.0/fastval.egg-info/PKG-INFO +5 -0
- fastval-0.1.0/fastval.egg-info/SOURCES.txt +17 -0
- fastval-0.1.0/fastval.egg-info/dependency_links.txt +1 -0
- fastval-0.1.0/fastval.egg-info/requires.txt +1 -0
- fastval-0.1.0/fastval.egg-info/top_level.txt +1 -0
- fastval-0.1.0/pyproject.toml +3 -0
- fastval-0.1.0/setup.cfg +4 -0
- fastval-0.1.0/setup.py +19 -0
- fastval-0.1.0/tests/test_models.py +59 -0
fastval-0.1.0/PKG-INFO
ADDED
fastval-0.1.0/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# FastVal
|
|
2
|
+
|
|
3
|
+
Ultra-fast Cython-based data validation library for Python, optimized for FastAPI. A faster alternative to Pydantic.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Fast validation using Cython
|
|
8
|
+
- Nested model support
|
|
9
|
+
- Optional fields with defaults
|
|
10
|
+
- JSON serialization with orjson
|
|
11
|
+
- Drop-in compatible with FastAPI
|
|
12
|
+
- Pydantic-style annotations
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Clone the repo and build:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/youruser/fastval.git
|
|
20
|
+
cd fastval
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Define models with annotations, just like Pydantic:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from fastval import BaseModel
|
|
30
|
+
from typing import List
|
|
31
|
+
|
|
32
|
+
class User(BaseModel):
|
|
33
|
+
name: str
|
|
34
|
+
age: int = 25
|
|
35
|
+
email: str
|
|
36
|
+
|
|
37
|
+
class Post(BaseModel):
|
|
38
|
+
title: str
|
|
39
|
+
content: str
|
|
40
|
+
author: User
|
|
41
|
+
tags: List[str] = []
|
|
42
|
+
|
|
43
|
+
# Validate data
|
|
44
|
+
user = User({'name': 'John', 'email': 'john@example.com'})
|
|
45
|
+
print(user.dict()) # {'name': 'John', 'age': 25, 'email': 'john@example.com'}
|
|
46
|
+
print(user.json()) # JSON string
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For FastAPI:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from fastapi import FastAPI
|
|
53
|
+
|
|
54
|
+
app = FastAPI()
|
|
55
|
+
|
|
56
|
+
@app.post("/users")
|
|
57
|
+
async def create_user(payload: dict):
|
|
58
|
+
user = User(payload)
|
|
59
|
+
return user.dict()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Benchmarks
|
|
63
|
+
|
|
64
|
+
FastVal outperforms Pydantic in validation and JSON serialization:
|
|
65
|
+
|
|
66
|
+
- **10,000 users validation**: FastVal 2.61x faster (0.0042s vs 0.0109s)
|
|
67
|
+
- **JSON serialization**: FastVal 2.99x faster (0.0023s vs 0.0068s)
|
|
68
|
+
- **Nested models (1,000 posts)**: FastVal 1.44x faster (0.0009s vs 0.0013s)
|
|
69
|
+
- **Large payloads (100k users)**: FastVal 2.21x faster (0.0647s vs 0.1429s)
|
|
70
|
+
|
|
71
|
+
Run `python benchmark.py` to see live results.
|
|
72
|
+
|
|
73
|
+
## Tests
|
|
74
|
+
|
|
75
|
+
Run `pytest tests/`
|