OxAPY is Python HTTP server library build in Rust - a fast, safe and feature-rich HTTP server implementation.
Show your support by giving a star 🌟 if this project helped you!
- Routing with path parameters
- Middleware support
- Static file serving
- Application state management
- Request/Response handling
- Query string parsing
from oxapy import HttpServer, Router, Status, Response
router = Router()
@router.get("/")
def welcome(request):
return Response("Welcome to OxAPY!", content_type="text/plain")
@router.get("/hello/{name}")
def hello(request, name):
return Response({"message": f"Hello, {name}!"})
app = HttpServer(("127.0.0.1", 5555))
app.attach(router)
if __name__ == "__main__":
app.run()
def auth_middleware(request, next, **kwargs):
if "authorization" not in request.headers:
return Status.UNAUTHORIZED
return next(request, **kwargs)
router = Router()
router.middleware(auth_middleware)
@router.get("/protected")
def protected(request):
return "This is protected!"
router = Router()
router.route(static_file("./static", "static"))
# Serves files from ./static directory at /static URL path
class AppState:
def __init__(self):
self.counter = 0
app = HttpServer(("127.0.0.1", 5555))
app.app_data(AppState())
router = Router()
@router.get("/count")
def handler(request):
app_data = request.app_data
app_data.counter += 1
return {"count": app_data.counter}
Todo:
- Handler
- HttpResponse
- Routing
- use tokio::net::Listener
- middleware
- app data
- pass request in handler
- serve static file
- templating
- query uri
- security submodule
- jwt
- bcrypt
- websocket