Skip to content

Craxti/qakeapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ QakeAPI 1.2.0

Revolutionary Hybrid Async/Sync Web Framework for Python

⚑ The first framework with seamless sync/async support and reactive architecture

Python Version License Version


✨ What Makes QakeAPI Unique?

QakeAPI is a completely new approach to web frameworks:

  1. πŸ”„ Hybrid Sync/Async β€” write sync and async code simultaneously
  2. ⚑ Reactive Routing β€” reactive routing and events
  3. πŸš€ Parallel Dependencies β€” automatic dependency parallelism
  4. πŸ”— Pipeline Composition β€” function composition into pipelines
  5. 🎯 Smart Routing β€” intelligent routing based on conditions

Key Features:

  • βœ… Zero Dependencies β€” only Python standard library
  • βœ… Production-Ready β€” ready for real-world projects
  • βœ… Performance β€” automatic parallelism, optimized routing (Trie-based)
  • βœ… Simplicity β€” intuitive syntax
  • βœ… Flexibility β€” simultaneous sync and async support
  • βœ… OpenAPI/Swagger β€” automatic API documentation
  • βœ… WebSocket Support β€” real-time communication
  • βœ… Background Tasks β€” asynchronous task processing
  • βœ… Middleware System β€” customizable request/response processing
  • βœ… CORS Support β€” built-in CORS middleware
  • βœ… Dependency Injection β€” clean architecture with DI
  • βœ… Rate Limiting β€” built-in rate limiting decorator
  • βœ… Caching β€” response caching with TTL
  • βœ… Request Validation β€” automatic data validation
  • βœ… File Upload β€” multipart file upload with validation
  • βœ… Security β€” request size limits, validation, error handling

πŸš€ Quick Start

Installation

pip install qakeapi

Simple Example

from qakeapi import QakeAPI, CORSMiddleware

app = QakeAPI(
    title="My API",
    version="1.2.0",
    description="My awesome API"
)

# Add CORS middleware
app.add_middleware(CORSMiddleware(allow_origins=["*"]))

# Sync function works automatically!
@app.get("/users/{id}")
def get_user(id: int):
    return {"id": id, "name": f"User {id}"}

# Async function is also supported
@app.get("/items/{item_id}")
async def get_item(item_id: int):
    return {"item_id": item_id}

# POST with automatic body extraction
@app.post("/users")
async def create_user(request):
    data = await request.json()
    return {"message": "User created", "data": data}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Access the API documentation:

  • Swagger UI: http://localhost:8000/docs
  • OpenAPI JSON: http://localhost:8000/openapi.json

πŸ“š Core Features

1. Hybrid Sync/Async

Write synchronous code, the framework automatically handles it:

@app.get("/users/{id}")
def get_user(id: int):  # Regular function!
    # Blocking operations automatically executed in executor
    user = database.get_user(id)
    posts = database.get_user_posts(id)
    return {"user": user, "posts": posts}

2. Parallel Dependencies

Dependencies execute in parallel:

@app.get("/dashboard")
async def dashboard(
    user: User = get_user(),
    stats: Stats = get_stats(),
    notifications: list = get_notifications()
):
    # All three functions execute in parallel!
    return {
        "user": user,
        "stats": stats,
        "notifications": notifications
    }

3. Reactive Events

React to events in your application:

@app.react("order:created")
async def on_order_created(event):
    order = event.data
    await inventory.reserve(order.items)
    await payment.process(order)
    await shipping.schedule(order)

# Emit event
await app.emit("order:created", order_data)

4. Pipeline Composition

Compose functions into pipelines:

@app.pipeline([
    authenticate,
    authorize,
    validate,
    transform,
    save
])
def create_resource(data: ResourceData):
    return {"id": data.id, "status": "created"}

5. Smart Routing

Conditional routing based on conditions:

@app.when(lambda req: req.headers.get("X-Client") == "mobile")
def mobile_handler(request):
    return {"mobile": True}

@app.when(lambda req: req.path.startswith("/api/v2"))
def v2_handler(request):
    return {"version": "2.0"}

6. Automatic API Documentation

OpenAPI/Swagger documentation is automatically generated:

app = QakeAPI(
    title="My API",
    version="1.2.0",
    description="API documentation"
)

# All routes are automatically documented
@app.get("/users/{id}")
def get_user(id: int):
    """Get user by ID."""
    return {"id": id}

7. WebSocket Support

Real-time communication:

@app.websocket("/ws/{room}")
async def websocket_handler(websocket: WebSocket, room: str):
    await websocket.accept()
    await websocket.send_json({"message": f"Welcome to {room}!"})
    
    async for message in websocket.iter_json():
        await websocket.send_json({"echo": message})

8. Background Tasks

Run tasks asynchronously:

from qakeapi.core.background import add_background_task

@app.post("/process")
async def process_data(request):
    data = await request.json()
    
    # Run task in background
    await add_background_task(process_heavy_task, data)
    
    return {"message": "Processing started"}

9. Middleware System

Customize request/response processing:

from qakeapi import CORSMiddleware, LoggingMiddleware, RequestSizeLimitMiddleware

app.add_middleware(CORSMiddleware(allow_origins=["*"]))
app.add_middleware(LoggingMiddleware())
app.add_middleware(RequestSizeLimitMiddleware(max_size=10 * 1024 * 1024))  # 10MB

10. Dependency Injection

Clean architecture with dependency injection:

from qakeapi import QakeAPI, Depends

app = QakeAPI()

def get_database():
    return Database()

@app.get("/users")
async def get_users(db = Depends(get_database)):
    return await db.get_users()

11. Rate Limiting

Protect your API with rate limiting:

from qakeapi import rate_limit

@rate_limit(requests_per_minute=60)
@app.get("/api/data")
def get_data():
    return {"data": "..."}

12. Response Caching

Cache responses for better performance:

from qakeapi import cache

@cache(ttl=300)  # Cache for 5 minutes
@app.get("/expensive-operation")
def expensive_operation():
    return {"result": compute_expensive_result()}

13. File Upload

Handle file uploads with validation and security:

from qakeapi import QakeAPI, FileUpload, IMAGE_TYPES

@app.post("/upload")
async def upload_image(file: FileUpload):
    # Validate file type
    if not file.validate_type(IMAGE_TYPES):
        return {"error": "Only images"}, 400
    
    # Validate size (5MB)
    if not file.validate_size(5 * 1024 * 1024):
        return {"error": "File too large"}, 400
    
    # Save file
    path = await file.save("uploads/")
    return {"path": path}

πŸ“¦ Architecture

qakeapi/
β”œβ”€β”€ core/              # Core components
β”‚   β”œβ”€β”€ app.py        # Main QakeAPI class
β”‚   β”œβ”€β”€ hybrid.py     # Hybrid executor (syncβ†’async)
β”‚   β”œβ”€β”€ router.py     # Smart router (Trie-optimized)
β”‚   β”œβ”€β”€ reactive.py   # Reactive engine
β”‚   β”œβ”€β”€ parallel.py   # Parallel resolver
β”‚   β”œβ”€β”€ pipeline.py   # Pipeline processor
β”‚   β”œβ”€β”€ request.py    # HTTP Request
β”‚   β”œβ”€β”€ response.py   # HTTP Response
β”‚   β”œβ”€β”€ middleware.py # Middleware system
β”‚   β”œβ”€β”€ websocket.py  # WebSocket support
β”‚   β”œβ”€β”€ background.py # Background tasks
β”‚   β”œβ”€β”€ openapi.py    # OpenAPI generation
β”‚   β”œβ”€β”€ files.py      # File upload handling
β”‚   β”œβ”€β”€ dependencies.py # Dependency Injection
β”‚   β”œβ”€β”€ validation.py # Data validation
β”‚   β”œβ”€β”€ rate_limit.py # Rate limiting
β”‚   β”œβ”€β”€ caching.py    # Response caching
β”‚   β”œβ”€β”€ logging.py    # Logging system
β”‚   └── exceptions.py # HTTP exceptions
└── utils/            # Utilities

πŸ“– Documentation

Full documentation is available in the docs/ directory:


🎯 Examples

Check out the examples/ directory for complete examples:

  • basic_example.py - Basic features demonstration
  • complete_example.py - Full feature showcase
  • file_upload_example.py - File upload handling
  • financial_calculator.py - Complex real-world application

πŸ”§ Requirements

  • Python 3.9+
  • uvicorn (optional, for running the server)

πŸ“ License

MIT License - see LICENSE for details.


πŸ™ Acknowledgments

QakeAPI is built from scratch using only Python standard library, demonstrating a new approach to web frameworks.


QakeAPI - Build modern APIs with revolutionary approach! πŸš€

Made with ❀️ by the QakeAPI team

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages