Package: osbot_fast_api
Current Version: v0.9.1
Purpose: A Type-Safe wrapper around FastAPI that provides strong typing, middleware support, and AWS Lambda integration through Mangum
Status: Production Ready
This documentation follows a structured approach to thoroughly document the OSBot-Fast-API package:
- Architecture Overview - System design and component relationships
- Type-Safe Integration - Type conversion system and patterns
- HTTP Events System - Request/response tracking and monitoring
- Middleware Stack - Built-in and custom middleware
- Fast_API Class - Main FastAPI wrapper
- Fast_API__Routes - Route organization
- Type Converters - Type-Safe to BaseModel converters
- Quick Start Guide - Getting started with OSBot-Fast-API
- LLM Prompts - Prompts for working with this package
- Testing Guide - Testing strategies and utilities
graph TB
subgraph "Application Layer"
APP[FastAPI Application]
ROUTES[Route Handlers]
SCHEMAS[Type-Safe Schemas]
end
subgraph "OSBot-Fast-API Core"
FA[Fast_API Wrapper]
FAR[Fast_API__Routes Base]
TS[Type Converters]
HE[HTTP Events]
MW[Middleware Stack]
end
subgraph "Infrastructure"
SERVER[Test Server]
LAMBDA[Lambda Handler]
UTILS[Utilities]
end
APP --> FA
ROUTES --> FAR
SCHEMAS --> TS
FA --> HE
FA --> MW
FA --> SERVER
FA --> LAMBDA
- Automatic conversion between Type_Safe classes and Pydantic BaseModels
- Strong typing throughout the application
- Validation at API boundaries
- Built-in HTTP event tracking
- Comprehensive middleware support
- Global exception handling
- AWS Lambda compatibility
- Minimal boilerplate code
- Convention over configuration
- Integrated testing utilities
- Clear extension points
| Component | Purpose | Location |
|---|---|---|
Fast_API |
Main FastAPI wrapper with Type-Safe support | /api/Fast_API.py |
Fast_API__Routes |
Base class for route organization | /api/Fast_API__Routes.py |
Fast_API__Http_Events |
HTTP request/response tracking | /api/Fast_API__Http_Events.py |
Type_Safe__To__BaseModel |
Type conversion system | /utils/type_safe/ |
Fast_API_Server |
Test server for integration testing | /utils/Fast_API_Server.py |
from osbot_fast_api.api.Fast_API import Fast_API
from osbot_fast_api.api.routes.Fast_API__Routes import Fast_API__Routes
from osbot_utils.type_safe.Type_Safe import Type_Safe
# Define a Type-Safe schema
class User(Type_Safe):
name: str
email: str
age: int
# Create routes
class Routes_Users(Fast_API__Routes):
tag = 'users'
def create_user(self, user: User):
return {'created': user.name}
def setup_routes(self):
self.add_route_post(self.create_user)
# Setup application
fast_api = Fast_API()
fast_api.setup()
fast_api.add_routes(Routes_Users)
app = fast_api.app()| Operation | Complexity | Cached |
|---|---|---|
| Type Conversion | O(n) fields | ✅ |
| Route Registration | O(1) | ❌ |
| HTTP Event Tracking | O(1) | ❌ |
| Middleware Execution | O(m) middleware | ❌ |
- v0.9.1 - Current stable release
- Production ready with full Type-Safe integration
- Comprehensive middleware support
- AWS Lambda compatibility