Skip to main content

Tatsat

A high-performance web framework with elegant syntax and powerful validation, built on Starlette and using Satya for data validation. Tatsat provides the developer-friendly interface of FastAPI with the validation performance of Satya.

Features

  • Modern: Built on top of Starlette, a lightweight ASGI framework
  • High Performance: Utilizes Satya's validation engine, which is significantly faster than Pydantic
  • Developer-friendly: Intuitive, FastAPI-like syntax for rapid development
  • Type-safe: Leverages Python type hints with Satya models for validation
  • Automatic API documentation: Built-in Swagger UI and ReDoc integration
  • Dependency Injection: Powerful dependency injection system
  • Path Operations: Intuitive route decorators for all HTTP methods
  • Middleware Support: Built-in middleware system for cross-cutting concerns
  • Exception Handling: Comprehensive exception handling mechanisms
  • APIRouter: Support for route grouping and organization

Benchmarks

Tatsat significantly outperforms FastAPI in validation and serialization operations. See the benchmarks for detailed performance comparisons with FastAPI, Starlette, and Flask.

Installation

# Install from PyPI
pip install tatsat

# Or install directly from the repository
pip install -e .

# Make sure you have satya installed
pip install satya

Quick Start

Here's a minimal example to get you started:

from tatsat import Tatsat
from satya import Model, Field
from typing import List, Optional

app = Tatsat(title="Tatsat Demo")

# Define your data models with Satya
class Item(Model):
    name: str = Field()
    description: Optional[str] = Field(required=False)
    price: float = Field(gt=0)
    tax: Optional[float] = Field(required=False)
    tags: List[str] = Field(default=[])

# Create API endpoints with typed parameters
@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q}

@app.post("/items/", response_model=Item)
def create_item(item: Item):
    return item

# Run the application with Uvicorn
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Core Concepts

Application

The Tatsat class is the main entry point for creating web applications:

from tatsat import Tatsat

app = Tatsat(
    title="Tatsat Example API",
    description="A sample API showing Tatsat features",
    version="0.1.0",
    debug=False
)

Path Operations

Tatsat provides decorators for all standard HTTP methods:

@app.get("/")
@app.post("/items/")
@app.put("/items/{item_id}")
@app.delete("/items/{item_id}")
@app.patch("/items/{item_id}")
@app.options("/items/")
@app.head("/items/")

Path Parameters

Path parameters are part of the URL path and are used to identify a specific resource:

@app.get("/items/{item_id}")
def read_item(item_id: int):
    return {"item_id": item_id}

Query Parameters

Query parameters are optional parameters appended to the URL:

@app.get("/items/")
def read_items(skip: int = 0, limit: int = 10):
    return {"skip": skip, "limit": limit}

Request Body

Request bodies are parsed and validated using Satya models:

@app.post("/items/")
def create_item(item: Item):
    return item

Dependency Injection

Tatsat includes a powerful dependency injection system:

def get_db():
    db = Database()
    try:
        yield db
    finally:
        db.close()

@app.get("/items/")
def read_items(db = Depends(get_db)):
    return db.get_items()

Response Models

Specify response models for automatic serialization and documentation:

@app.get("/items/{item_id}", response_model=Item)
def read_item(item_id: int):
    return get_item_from_db(item_id)

Advanced Features

API Routers

Organize your routes using the APIRouter:

from tatsat import APIRouter

router = APIRouter(prefix="/api/v1")

@router.get("/items/")
def read_items():
    return {"items": []}

app.include_router(router)

Middleware

Add middleware for cross-cutting concerns:

@app.middleware("http")
async def add_process_time_header(request, call_next):
    start_time = time.time()
    response = await call_next(request)
    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    return response

Exception Handlers

Custom exception handlers:

@app.exception_handler(404)
async def not_found_exception_handler(request, exc):
    return JSONResponse(
        status_code=404,
        content={"detail": "The requested resource was not found"},
    )

Event Handlers

Handle startup and shutdown events:

@app.on_event("startup")
async def startup_event():
    print("Application is starting up")

@app.on_event("shutdown")
async def shutdown_event():
    print("Application is shutting down")

Documentation

Tatsat automatically generates interactive documentation:

  • Swagger UI: Available at /docs
  • ReDoc: Available at /redoc

Example Applications

Tatsat comes with several example applications in the examples/ directory:

  • basic_app.py: Simple CRUD operations with dependency injection
  • advanced_app.py: Advanced features including middleware, nested models, and authentication
  • comprehensive_benchmark.py: Performance comparison with FastAPI, Starlette, and Flask

Route Documentation

For a comprehensive guide to all available route patterns and their usage, see the ROUTES.md file.

Dependencies

Tatsat depends on the following packages:

  • starlette >= 0.28.0
  • uvicorn >= 0.23.0
  • satya (for data validation)

License

MIT License

Metadata

Release files for tatsat 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tatsat 0.1.1
File Size Uploaded Provenance
tatsat-0.1.1.tar.gz 17.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tatsat 0.1.1
File Interpreter ABI Platform
tatsat-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.2 kB

Release files / tatsat-0.1.1.tar.gz

Download URL tatsat-0.1.1.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b17c318f26aa453ba480a5e644a12719bbe9b8496a42bc63ede39367003ff4e3
BLAKE2b-256 checksum
How to use checksums
3f149d3aa431f83d6e83f9cbc43b58c3571550da64962f23cf7b37b16591bdaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release files / tatsat-0.1.1-py3-none-any.whl

Download URL tatsat-0.1.1-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df52d1602c1ac18646f0a88997e58243c4dceca19a20a7fe81662e7143f4118e
BLAKE2b-256 checksum
How to use checksums
698ea6d3903e04e8ba9300e8eb753d6b9c8e5818f58e8a06cc98ef0577aa7dab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Security for tatsat 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page