Version 21.3 Released
Published on March 21, 2021 by Adam Hopkins
Admin


Sanic v21.3 released today with some big changes. This year, the focus is on some sweeping performance and and efficiency optimizations. Two main examples:
  1. First class streaming support - All view handlers are now enabled to stream responses back to the browser. This eliminates the need for callbacks, but more importantly carries a noticeable performance improvement.
  2. Startup time compiled router - There is a new router that analyzes routes at runtime and builds a routing function. This solves a number of historical problems, but also includes a performance increase.
Version 21.3 introduces a new signals API to allow your application to send events and data easily.

@app.signal("foo.bar.<thing>")
async def signal_handler(thing, **kwargs):
    print(f"[signal_handler] {thing=}", kwargs)

async def wait_for_event(app):
    while True:
        print("> waiting")
        await app.event("foo.bar.*")
        print("> event found\n")

@app.after_server_start
async def after_server_start(app, loop):
    app.add_task(wait_for_event(app))

@app.get("/")
async def trigger(request):
    await app.dispatch("foo.bar.baz")
    return response.text("Done.")


Another exciting feature is adding a context object to the transport. This will enable a single connection (ie, keep-alive) to share state across requests.
A full list of changes are on the release notes.
Last notable change: the new User Guide is available in both English and Chinese.