NEW: Fenrir v1.2.2 is now available — Logo & Favicon Patch! Read the changelog
advanced-features.md
docs advanced-features.md

Advanced Features

WSGI Application Mounting

Mount legacy WSGI applications:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from fenrir import Fenrir, WsgiToAsgi

app = Fenrir()

# Legacy WSGI app
def wsgi_app(environ, start_response):
    status = '200 OK'
    headers = [('Content-Type', 'text/plain')]
    start_response(status, headers)
    return [b'Hello from WSGI']

# Mount WSGI app
wsgi_asgi = WsgiToAsgi(wsgi_app)
app.mount_wsgi("/legacy", wsgi_asgi)

Framework Compatibility Modes

Bottle Compatibility

1
2
3
4
5
6
7
from fenrir import install_bottle_compat

install_bottle_compat()

# Now use Bottle-style features
from fenrir.bottle import Bottle
bottle_app = Bottle()

Falcon Compatibility

1
2
3
4
5
6
from fenrir import install_falcon_compat

install_falcon_compat()

# Now use Falcon-style features
import fenrir.falcon as falcon

Sanic Compatibility

1
2
3
4
5
6
from fenrir import install_sanic_compat

install_sanic_compat()

# Now use Sanic-style features
import fenrir.sanic as sanic

Response Models

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from pydantic import BaseModel

class Item(BaseModel):
    id: int
    name: str
    price: float

@app.get("/items/<item_id:int>", response_model=Item)
async def get_item(item_id: int):
    return {"id": item_id, "name": "Item", "price": 9.99}

Event Listeners

1
2
3
4
5
6
7
@app.listener("before_server_start")
async def startup(app_instance):
    print("Server starting")

@app.listener("after_server_stop")
async def shutdown(app_instance):
    print("Server stopping")

Custom Response Models with Include/Exclude

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class User(BaseModel):
    id: int
    name: str
    email: str
    password: str

@app.get(
    "/users/<user_id:int>",
    response_model=User,
    response_model_exclude={"password"}
)
async def get_user(user_id: int):
    return User(
        id=user_id,
        name="John",
        email="john@example.com",
        password="secret"
    )
Edit on GitHub Last Updated: Jun 04, 2026
© 2026 Fenrir Project.
main*
v1.2.2
Ln 1, Col 1
UTF-8
Prettier
Light Mode
Markdown