Skip to content

Commit 5c49534

Browse files
committed
Merge dev into main
2 parents c58e578 + 0b2a6d1 commit 5c49534

32 files changed

Lines changed: 1947 additions & 249 deletions

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OSBot-Fast-API
22

3-
![Current Release](https://img.shields.io/badge/release-v0.12.0-blue)
3+
![Current Release](https://img.shields.io/badge/release-v0.12.1-blue)
44
![Python](https://img.shields.io/badge/python-3.8+-green)
55
![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-red)
66
![Type-Safe](https://img.shields.io/badge/Type--Safe-✓-brightgreen)
@@ -30,30 +30,33 @@ pip install osbot-fast-api
3030

3131
```python
3232
from osbot_fast_api.api.Fast_API import Fast_API
33-
from osbot_fast_api.api.Fast_API_Routes import Fast_API_Routes
33+
from osbot_fast_api.api.Fast_API__Routes import Fast_API__Routes
3434
from osbot_utils.type_safe.Type_Safe import Type_Safe
3535

36+
3637
# Define Type-Safe schema
3738
class User(Type_Safe):
3839
username: str
3940
email: str
4041
age: int
4142

43+
4244
# Create routes
43-
class Routes_Users(Fast_API_Routes):
45+
class Routes_Users(Fast_API__Routes):
4446
tag = 'users'
45-
47+
4648
def create_user(self, user: User):
4749
# user is automatically converted from BaseModel to Type_Safe
4850
return {'created': user.username}
49-
51+
5052
def get_user__id(self, id: str): # Becomes /users/get-user/{id}
5153
return {'user_id': id}
52-
54+
5355
def setup_routes(self):
5456
self.add_route_post(self.create_user)
5557
self.add_route_get(self.get_user__id)
5658

59+
5760
# Setup application
5861
fast_api = Fast_API(enable_cors=True)
5962
fast_api.setup()
@@ -145,7 +148,7 @@ class Person(Type_Safe):
145148
addresses: List[Address] = []
146149

147150
# Use directly in routes - automatic conversion happens
148-
class Routes_People(Fast_API_Routes):
151+
class Routes_People(Fast_API__Routes):
149152
tag = 'people'
150153

151154
def create_person(self, person: Person):
@@ -250,7 +253,7 @@ def lambda_handler(event, context):
250253
osbot_fast_api/
251254
├── api/
252255
│ ├── Fast_API.py # Main FastAPI wrapper
253-
│ ├── Fast_API_Routes.py # Route organization base class
256+
│ ├── Fast_API__Routes.py # Route organization base class
254257
│ ├── Fast_API__Http_Event*.py # Event tracking components
255258
│ └── middlewares/ # Built-in middleware
256259
├── utils/
@@ -291,7 +294,7 @@ Comprehensive documentation is available in the [`/docs`](./docs) folder:
291294
- **AWS Ready**: Direct Lambda integration with Mangum
292295

293296
### For Teams
294-
- **Organized Code**: Clear separation with Fast_API_Routes classes
297+
- **Organized Code**: Clear separation with Fast_API__Routes classes
295298
- **Consistent Patterns**: Standardized route naming and structure
296299
- **Easy Testing**: Type-Safe test utilities
297300
- **Documentation**: Auto-generated OpenAPI/Swagger docs

docs/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This documentation follows a structured approach to thoroughly document the OSBo
1919

2020
### API Documentation
2121
- [Fast_API Class](./code/osbot_fast_api/api/Fast_API.py.md) - Main FastAPI wrapper
22-
- [Fast_API_Routes](./code/osbot_fast_api/api/Fast_API_Routes.py.md) - Route organization
22+
- [Fast_API__Routes](./code/osbot_fast_api/api/Fast_API__Routes.py.md) - Route organization
2323
- [Type Converters](./code/osbot_fast_api/utils/type_safe/) - Type-Safe to BaseModel converters
2424

2525
### Usage Guides
@@ -39,7 +39,7 @@ graph TB
3939
4040
subgraph "OSBot-Fast-API Core"
4141
FA[Fast_API Wrapper]
42-
FAR[Fast_API_Routes Base]
42+
FAR[Fast_API__Routes Base]
4343
TS[Type Converters]
4444
HE[HTTP Events]
4545
MW[Middleware Stack]
@@ -84,7 +84,7 @@ graph TB
8484
| Component | Purpose | Location |
8585
|-----------|---------|----------|
8686
| `Fast_API` | Main FastAPI wrapper with Type-Safe support | `/api/Fast_API.py` |
87-
| `Fast_API_Routes` | Base class for route organization | `/api/Fast_API_Routes.py` |
87+
| `Fast_API__Routes` | Base class for route organization | `/api/Fast_API__Routes.py` |
8888
| `Fast_API__Http_Events` | HTTP request/response tracking | `/api/Fast_API__Http_Events.py` |
8989
| `Type_Safe__To__BaseModel` | Type conversion system | `/utils/type_safe/` |
9090
| `Fast_API_Server` | Test server for integration testing | `/utils/Fast_API_Server.py` |
@@ -93,25 +93,28 @@ graph TB
9393

9494
```python
9595
from osbot_fast_api.api.Fast_API import Fast_API
96-
from osbot_fast_api.api.Fast_API_Routes import Fast_API_Routes
96+
from osbot_fast_api.api.Fast_API__Routes import Fast_API__Routes
9797
from osbot_utils.type_safe.Type_Safe import Type_Safe
9898

99+
99100
# Define a Type-Safe schema
100101
class User(Type_Safe):
101102
name: str
102103
email: str
103104
age: int
104105

106+
105107
# Create routes
106-
class Routes_Users(Fast_API_Routes):
108+
class Routes_Users(Fast_API__Routes):
107109
tag = 'users'
108-
110+
109111
def create_user(self, user: User):
110112
return {'created': user.name}
111-
113+
112114
def setup_routes(self):
113115
self.add_route_post(self.create_user)
114116

117+
115118
# Setup application
116119
fast_api = Fast_API()
117120
fast_api.setup()

docs/architecture/osbot-fast-api-architecture.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ graph TB
4444
end
4545
4646
subgraph "Routing"
47-
FAR[Fast_API_Routes]
47+
FAR[Fast_API__Routes]
4848
RC[Route Config]
4949
RM[Route Methods]
5050
end
@@ -134,7 +134,7 @@ classDiagram
134134
Fast_API --|> Type_Safe
135135
Fast_API *-- Fast_API__Http_Events
136136
Fast_API ..> FastAPI : creates
137-
Fast_API ..> Fast_API_Routes : manages
137+
Fast_API ..> Fast_API__Routes : manages
138138
```
139139

140140
**Responsibilities**:
@@ -144,13 +144,13 @@ classDiagram
144144
- HTTP event coordination
145145
- Global exception handling
146146

147-
### Fast_API_Routes Class
147+
### Fast_API__Routes Class
148148

149149
Base class for organizing routes with automatic Type-Safe conversion:
150150

151151
```mermaid
152152
classDiagram
153-
class Fast_API_Routes {
153+
class Fast_API__Routes {
154154
+APIRouter router
155155
+FastAPI app
156156
+str prefix
@@ -164,9 +164,9 @@ classDiagram
164164
+setup_routes()
165165
}
166166
167-
Fast_API_Routes --|> Type_Safe
168-
Fast_API_Routes --> APIRouter
169-
Fast_API_Routes --> FastAPI
167+
Fast_API__Routes --|> Type_Safe
168+
Fast_API__Routes --> APIRouter
169+
Fast_API__Routes --> FastAPI
170170
```
171171

172172
**Route Path Generation Algorithm**:
@@ -344,7 +344,7 @@ class Custom_Fast_API(Fast_API):
344344
### Custom Routes
345345

346346
```python
347-
class Custom_Routes(Fast_API_Routes):
347+
class Custom_Routes(Fast_API__Routes):
348348
def setup_routes(self):
349349
# Add routes with Type-Safe support
350350
self.add_route_get(self.custom_method)

docs/architecture/why-async-routes-are-not-used.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ What makes this particularly dangerous:
9494

9595
```python
9696
# ✅ SAFE: OSBot-Fast-API approach
97-
class Routes_API(Fast_API_Routes):
97+
class Routes_API(Fast_API__Routes):
9898
def get_users(self): # Sync function
9999
# Safe to use any sync library
100100
users = db.query("SELECT * FROM users")
@@ -218,7 +218,7 @@ But in a production API where:
218218
### Do's ✅
219219

220220
```python
221-
class Routes_Safe(Fast_API_Routes):
221+
class Routes_Safe(Fast_API__Routes):
222222
def process_data(self, data: dict):
223223
# Safe to use any sync operation
224224
result = sync_database.query(data)
@@ -232,7 +232,7 @@ class Routes_Safe(Fast_API_Routes):
232232

233233
```python
234234
# Don't try to force async in OSBot-Fast-API
235-
class Routes_Unsafe(Fast_API_Routes):
235+
class Routes_Unsafe(Fast_API__Routes):
236236
async def process_data(self, data: dict): # Avoid this
237237
# Mixing async/sync is dangerous
238238
pass

docs/comparison/fastapi-vs-osbot-fastapi.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,45 +78,50 @@ if __name__ == "__main__":
7878
```
7979

8080
#### OSBot-Fast-API
81+
8182
```python
8283
from osbot_fast_api.api.Fast_API import Fast_API
83-
from osbot_fast_api.api.Fast_API_Routes import Fast_API_Routes
84+
from osbot_fast_api.api.Fast_API__Routes import Fast_API__Routes
8485
from osbot_utils.type_safe.Type_Safe import Type_Safe
8586

87+
8688
# Type-Safe schemas (stronger than Pydantic)
8789
class User(Type_Safe):
8890
username: str
8991
email: str
9092
age: int
9193

94+
9295
class UserResponse(Type_Safe):
9396
id: str
9497
username: str
9598
created: bool
9699

100+
97101
# Organized routes in classes
98-
class Routes_Users(Fast_API_Routes):
102+
class Routes_Users(Fast_API__Routes):
99103
tag = 'users'
100-
104+
101105
def create(self, user: User) -> UserResponse:
102106
# Automatic type conversion
103107
return UserResponse(
104108
id="user_123",
105109
username=user.username,
106110
created=True
107111
)
108-
112+
109113
def get__user_id(self, user_id: str):
110114
return {"user_id": user_id}
111-
115+
112116
def setup_routes(self):
113117
self.add_route_post(self.create)
114118
self.add_route_get(self.get__user_id)
115119

120+
116121
# Simple setup with built-in features
117122
fast_api = Fast_API(
118-
enable_cors=True, # CORS configured
119-
enable_api_key=True # API key validation built-in
123+
enable_cors=True, # CORS configured
124+
enable_api_key=True # API key validation built-in
120125
)
121126
fast_api.setup()
122127
fast_api.add_routes(Routes_Users)
@@ -296,7 +301,7 @@ async def create_user(): ...
296301

297302
#### OSBot-Fast-API - Organized by Design
298303
```python
299-
class Routes_Users(Fast_API_Routes):
304+
class Routes_Users(Fast_API__Routes):
300305
tag = 'users' # All routes prefixed with /users
301306

302307
def list(self): ... # GET /users/list

docs/guides/llm-prompts.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ This guide provides prompts for Large Language Models (like Claude, GPT-4, etc.)
1111
```
1212
Create a FastAPI service using OSBot-Fast-API that:
1313
1. Uses the Fast_API class as the base, not regular FastAPI
14-
2. Implements routes using Fast_API_Routes classes with descriptive tags
15-
3. Each route class should extend Fast_API_Routes and implement setup_routes()
14+
2. Implements routes using Fast_API__Routes classes with descriptive tags
15+
3. Each route class should extend Fast_API__Routes and implement setup_routes()
1616
4. Use method naming convention: method_name becomes /method-name
1717
5. For path parameters use double underscore: method__param becomes /method/{param}
1818
6. Enable CORS and API key authentication if needed
@@ -24,7 +24,7 @@ Create a FastAPI service using OSBot-Fast-API that:
2424

2525
```
2626
Add a new route to OSBot-Fast-API that:
27-
1. Extends Fast_API_Routes with appropriate tag property
27+
1. Extends Fast_API__Routes with appropriate tag property
2828
2. Uses Type_Safe classes (not Pydantic BaseModel) for request/response schemas
2929
3. Type_Safe classes should inherit from Type_Safe, not BaseModel
3030
4. Implements add_route_get/post/put/delete in setup_routes() method
@@ -55,7 +55,7 @@ Create Type-Safe schemas for OSBot-Fast-API:
5555
```
5656
When working with OSBot-Fast-API type conversions:
5757
1. Type_Safe classes are automatically converted to/from BaseModel at API boundaries
58-
2. Conversion happens in Fast_API_Routes methods automatically
58+
2. Conversion happens in Fast_API__Routes methods automatically
5959
3. Manual conversion: type_safe__to__basemodel.convert_class(Type_Safe_Class)
6060
4. Reverse: basemodel__to__type_safe.convert_instance(basemodel_instance)
6161
5. Collections (List, Dict, Set) are automatically handled
@@ -211,7 +211,7 @@ Add static files and shell server to OSBot-Fast-API:
211211
```
212212
Create a complete OSBot-Fast-API service with:
213213
1. Type_Safe schemas for all data models
214-
2. Fast_API_Routes classes for endpoint organization
214+
2. Fast_API__Routes classes for endpoint organization
215215
3. Enable CORS for web clients
216216
4. API key authentication for security
217217
5. HTTP event tracking for monitoring
@@ -240,7 +240,7 @@ Implement error handling in OSBot-Fast-API:
240240
```
241241
Follow OSBot-Fast-API best practices:
242242
1. Always use Type_Safe classes, never raw Pydantic BaseModel
243-
2. Organize routes in Fast_API_Routes classes by domain
243+
2. Organize routes in Fast_API__Routes classes by domain
244244
3. Set meaningful tags for OpenAPI documentation
245245
4. Enable middleware appropriate for environment
246246
5. Use environment variables for all configuration
@@ -257,7 +257,7 @@ Follow OSBot-Fast-API best practices:
257257
Critical OSBot-Fast-API implementation details:
258258
1. NEVER use FastAPI() directly, always use Fast_API()
259259
2. NEVER use BaseModel for schemas, always use Type_Safe
260-
3. NEVER use @app.get(), use Fast_API_Routes methods
260+
3. NEVER use @app.get(), use Fast_API__Routes methods
261261
4. ALWAYS call setup() before adding routes
262262
5. ALWAYS implement setup_routes() in route classes
263263
6. ALWAYS use add_route_get/post/put/delete, not decorators

0 commit comments

Comments
 (0)