Metadata-Version: 2.4
Name: fastval
Version: 0.1.2
Description-Content-Type: text/markdown
Requires-Dist: orjson
Dynamic: description
Dynamic: description-content-type
Dynamic: requires-dist

# FastVal

Ultra-fast Cython-based data validation library for Python, optimized for FastAPI. A faster alternative to Pydantic.

## Features

- Fast validation using Cython
- Nested model support
- Optional fields with defaults
- JSON serialization with orjson
- Drop-in compatible with FastAPI
- Pydantic-style annotations

## Installation

Clone the repo and build:

```bash
git clone https://github.com/jncremona2/fastval.git
cd fastval
pip install -e .
```

## Usage

Define models with annotations, just like Pydantic:

```python
from fastval import BaseModel
from typing import List

class User(BaseModel):
    name: str
    age: int = 25
    email: str

class Post(BaseModel):
    title: str
    content: str
    author: User
    tags: List[str] = []

# Validate data
user = User({'name': 'John', 'email': 'john@example.com'})
print(user.dict())  # {'name': 'John', 'age': 25, 'email': 'john@example.com'}
print(user.json())  # JSON string
```

For FastAPI:

```python
from fastapi import FastAPI

app = FastAPI()

@app.post("/users")
async def create_user(payload: dict):
    user = User(payload)
    return user.dict()
```

## Benchmarks

FastVal outperforms Pydantic in validation and JSON serialization:

- **Validation (10,000 users)**: FastVal 2.65x faster (0.0042s vs 0.0112s)
- **JSON Serialization**: FastVal 3.07x faster (0.0022s vs 0.0066s)
- **Nested Models (1,000 posts)**: FastVal 1.27x faster (0.0009s vs 0.0012s)
- **Large Payloads (100,000 users)**: FastVal 2.29x faster (0.0610s vs 0.1397s)

Run `python benchmark.py` to see live results.

## Tests

Run `pytest tests/`
