Releases: 2-seo/fasthttp
Releases · 2-seo/fasthttp
🚀 FastHTTP v0.1.1 - Automatic Object Serialization
FastHTTP v0.1.1 Release Notes
🎯 Key Enhancement: Automatic Object Serialization
Previous Issue
When passing Pydantic models, dataclasses, or regular classes to json or data parameters in FastHTTP, the following error occurred:
# ❌ Before (v0.1.0) - Error occurred
from dataclasses import dataclass
from fasthttp import FastHTTP
@dataclass
class User:
name: str
age: int
http = FastHTTP(base_url="https://api.example.com")
@http.post("/users")
async def create_user(response, json=None):
return await response.json()
user = User("Alice", 25)
result = await create_user(json=user) # ❌ TypeError: Object of type User is not JSON serializableRequired Solution: Users had to manually serialize objects
# Cumbersome manual serialization
result = await create_user(json=dataclasses.asdict(user)) # For dataclasses
result = await create_user(json=user.model_dump()) # For Pydantic
result = await create_user(json=vars(user)) # For regular classes✨ v0.1.1 Improvements
Now you can pass any object directly!
# ✅ Improved (v0.1.1) - Automatic serialization
from dataclasses import dataclass
from fasthttp import FastHTTP
@dataclass
class User:
name: str
age: int
user = User("Alice", 25)
result = await create_user(json=user) # ✅ Automatically serialized!Supported Object Types
- Pydantic models (v1, v2)
- Python dataclasses
- Regular classes
- Nested objects (unlimited depth)
- File objects (io.IOBase - preserved)
Real-world Usage Examples
from fasthttp import FastHTTP
import io
from dataclasses import dataclass
@dataclass
class UserProfile:
name: str
email: str
http = FastHTTP(base_url="https://api.example.com")
# 1. JSON requests - Automatic object serialization
@http.post("/users")
async def create_user(response, json: UserProfile = None): # ✅ Works with type hints too!
return await response.json()
profile = UserProfile("Alice", "alice@example.com")
user = await create_user(json=profile) # ✅ Auto-converted
# 2. Form data + File uploads - Mixed type support
@http.post("/upload")
async def upload_avatar(response, data: dict = None):
return await response.json()
file = io.BytesIO(b"image data")
result = await upload_avatar(data={
"profile": profile, # ✅ Object auto-serialized
"avatar": file, # ✅ File object preserved
"upload_type": "avatar" # ✅ Regular values unchanged
})📦 Compatibility
- ✅ Zero-breaking upgrade: Existing code works unchanged
Changes: v0.1.0...v0.1.1
🎉 FastHTTP v0.1.0 - Initial Release
🚀 FastHTTP v0.1.0 - Initial Release
A fast and elegant HTTP client library with decorator-based request handling, built on top of aiohttp.
✨ Key Features
- 🎯 Decorator-based API: Clean and intuitive request handling with
@http.get(),@http.post(), etc. - ⚡ Async/Await Support: Built on aiohttp for high performance async HTTP requests
- 🔄 Automatic Resource Management: No more connection leaks with smart cleanup
- 🌐 URL Template Support: Dynamic URL building with parameters like
/users/{user_id} - 🚀 Connection Pooling: Efficient connection reuse for better performance
- 📝 Type Hints: Full typing support for better IDE experience
📦 Installation
# pip
pip install fastaiohttp
# uv
uv add fastaiohttp🔧 Quick Start
import asyncio
from fasthttp import FastHTTP
# Create a client instance
http = FastHTTP(base_url="https://api.example.com")
@http.get("/users/{user_id}")
async def get_user(response, user_id: int):
return await response.json()
async def main():
user = await get_user(user_id=123)
print(user)
await http.close()
if __name__ == "__main__":
asyncio.run(main())📋 Supported HTTP Methods
✅ GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
✅ Request/response middleware support
✅ Custom connectors and authentication
✅ Debug mode with comprehensive logging
✅ Context manager support
🔧 Advanced Features
- URL Templating:
/api/users/{user_id}/posts/{post_id} - Global Configuration: Base URL, headers, timeout settings
- Session Management: Automatic connection pooling and cleanup
🤝 Contributing
We welcome contributions, bug reports, and feature requests! Please check out our GitHub repository for more information.
Full Changelog: https://github.com/2-seo/fasthttp/commits/v0.1.0