Skip to main content

No project description provided

Project description

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:

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

Usage

Define models with annotations, just like Pydantic:

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:

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/

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

fastval-0.1.2.tar.gz (151.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastval-0.1.2-cp311-cp311-macosx_10_9_universal2.whl (127.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file fastval-0.1.2.tar.gz.

File metadata

  • Download URL: fastval-0.1.2.tar.gz
  • Upload date:
  • Size: 151.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for fastval-0.1.2.tar.gz
Algorithm Hash digest
SHA256 22fd53cb7df32761eb8e73e0820c480ca23a5a6f55daae908833dedcb6e5cf73
MD5 d4148f63fde31ddf187346f9a8d85ae3
BLAKE2b-256 5cd4bc2f908585349717136fcee7a293cc46d03741bcd37f0f1edfd880b90455

See more details on using hashes here.

File details

Details for the file fastval-0.1.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fastval-0.1.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4f348dd085dd530f9c54f7ee9c95c3835784eaccf48ca808f8dbd51dc07ac252
MD5 6b66c7536de83710c822ff761754f05b
BLAKE2b-256 b192c07b1c027390e82ab06fd3a95a777ef7b7cafc8849d7ec9a7d5e6321c0d8

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