cross-web

0.4.1 · active · verified Sat Apr 11

Cross-web is a Python library (version 0.4.1) providing a unified interface for common web framework operations, allowing developers to write framework-agnostic code for popular Python web frameworks like FastAPI, Flask, and Django. It is actively developed with recent releases addressing bug fixes and framework support, and was last updated in January 2026.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core concept of `cross-web`: defining framework-agnostic `Request` and `Response` objects. In a real application, a specific web framework (like Flask or FastAPI) would use a `cross-web` adapter to convert its native request/response objects to `cross-web`'s types, allowing you to write your business logic using these unified types. This example is runnable and simulates the creation and processing of these objects.

from cross_web import Request, Response

def my_framework_agnostic_handler(request: Request) -> Response:
    # This function represents a handler written using cross-web's abstractions
    name = request.query_params.get('name', 'World')
    body_content = f"Hello, {name}! This is a cross-web response."
    return Response(
        status_code=200,
        headers={'Content-Type': 'text/plain'},
        body=body_content.encode('utf-8')
    )

# --- Example of how a web framework adapter might use it ---
# In a real application, a framework-specific adapter would create
# the Request object and handle the Response object.

# Simulate an incoming request
simulated_request = Request(
    method="GET",
    path="/greeting",
    headers={
        "Host": "example.com",
        "User-Agent": "curl/7.81.0"
    },
    query_params={
        "name": "cross-web user"
    },
    body=b''
)

# Call the framework-agnostic handler
response_obj = my_framework_agnostic_handler(simulated_request)

# Output the response details (what a framework adapter might send back)
print(f"Status: {response_obj.status_code}")
print(f"Headers: {response_obj.headers}")
print(f"Body: {response_obj.body.decode('utf-8')}")

view raw JSON →