🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

oxapy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oxapy

OxAPY is http server for python build in rust

0.4.0
PyPI
Maintainers
1

OxAPY

OxAPY is Python HTTP server library build in Rust - a fast, safe and feature-rich HTTP server implementation.

Features

  • Routing with path parameters
  • Middleware support
  • Static file serving
  • Application state management
  • Request/Response handling
  • Query string parsing

Basic Example

from oxapy import HttpServer, get, Router, Status, Response


@get("/")
def welcome(request):
    return Response(Status.OK, "Welcome to OxAPY!")

@get("/hello/{name}")
def hello(request, name):
    return Response(Status.OK, {"message": f"Hello, {name}!"})

router = Router()
router.routes([welcome, hello])

app = HttpServer(("127.0.0.1", 5555))
app.attach(router)

if __name__ == "__main__":
    app.run()

Middleware Example

def auth_middleware(request, next, **kwargs):
    if "Authorization" not in request.headers:
        return Status.UNAUTHORIZED
    return next(request, **kwargs)

@get("/protected")
def protected(request):
    return "This is protected!"

router = Router()
router.middleware(auth_middleware)
router.route(protected)

Static Files

router = Router()
router.route(static_file("./static", "static"))
# Serves files from ./static directory at /static URL path

Application State

class AppState:
    def __init__(self):
        self.counter = 0

app = HttpServer(("127.0.0.1", 5555))
app.app_data(AppState())

@get("/count")
def handler(request):
    app_data = request.app_data
    app_data.counter += 1
    return {"count": app_data.counter}


router = Router()
router.route(handler)

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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts