Skip to content

v3.8.0

Choose a tag to compare

@kennethreitz kennethreitz released this 12 Jun 01:41
· 12 commits to main since this release

Highlights

Handlers can return values — quick endpoints get a lot terser:

@api.route("/users")
def list_users(req, resp):
    return [{"name": "alice"}]   # same as resp.media = [...]

A dict/list sets resp.media, a str sets resp.text, bytes set resp.content. Returning None keeps the classic mutate-resp behavior, so existing handlers are unaffected.

Proper HTTP method semantics. Method-restricted routes now return 405 Method Not Allowed with an Allow header for unsupported methods (previously 404), answer OPTIONS automatically, and accept HEAD wherever GET is supported.

App-scoped dependencies. Building on 3.7.0's dependency injection:

@api.dependency(scope="app")
async def pool():
    pool = await create_pool()
    yield pool
    await pool.close()   # runs at application shutdown

The provider resolves once on first use and is cached for the application's lifetime.

Also

  • set_cookie() gains a samesite parameter, defaulting to "lax"
  • The validated request_model instance is available as req.state.validated — no double parsing
  • RouteGroup.before_request hooks are now scoped to the group's prefix (previously they silently applied to every route)
  • View signature inspection for dependency injection is cached per function

Breaking-ish

  • Wrong-method requests now get 405 instead of 404 (the correct status code)
  • Group-level before-request hooks no longer fire outside their prefix

Full changelog: https://github.com/kennethreitz/responder/blob/main/CHANGELOG.md

PyPI: https://pypi.org/project/responder/3.8.0/