Upgrade to Pro — share decks privately, control downloads, hide ads and more …



Responder – https://python-responder.org

Talk given at:

Django Friends – Vienna 20.11.2018.


Dražen Lučanin

November 20, 2018


  1. Responder Dražen Lučanin @metakermit Django Friends – Vienna 20.11.2018.

  2. Hello, world! import responder api = responder.API() @api.route("/{greeting}") async def

    greet_world(req, resp, *, greeting): resp.text = f"{greeting}, world!" if __name__ == '__main__': api.run()
  3. Another Python web framework in 2018? • “A familiar HTTP

    Service Framework” • By Kenneth Reitz (Requests) • Kind of like an async Python web framework for humans • Not reinventing the wheel, but combining best practices • “Take Falcon, make it more like Flask & then give it some upgrades” – Kenneth Reitz @ Import This, Ep. 17
  4. • ASGI – async / await • f-string syntax routes

    • Built-in static file server • Single-page webapp support • Built-in Requests for tests • Meta-framework – mount any ASGI / WSGI app at a subroute • GraphQL support … some upgrades?
  5. Mostly built in one month • How? • #hacktoberfest2018 •

    https://www.starlette.io/ by Tom Christie • Starlette is to Responder what Werkzeug is to Flask • So let’s go over Responder’s features…
  6. ASGI – async / await • Starlette – an ASGI

    implemented on top of uvicorn • async background tasks without Celery – no blocking import time @api.route("/incoming") async def receive_incoming(req, resp): @api.background.task def process_data(data): """Just sleeps for three seconds, as a demo.""" time.sleep(3) # Parse the incoming data as form-encoded. # Note: 'json' and 'yaml' formats are also automatically supported. data = await req.media() # Process the data (in the background). process_data(data) # Immediately respond that upload was successful. resp.media = {'success': True}
  7. f-string syntax routes • The beloved Python 3 feature in

    action @api.route("/hello/{who}") def hello_to(req, resp, *, who): resp.text = f"hello, {who}!"
  8. Built-in static file server • Files from the static/ folder

    served using WhiteNoise • Single-page webapp support – all routes passed to index.html api.add_route("/", static=True)
  9. “What about an ORM?” – every Django developer • There

    are some solutions, but it’s still early days • GINO – https://github.com/fantix/gino • a lightweight asynchronous ORM built on top of SQLAlchemy core for Python asyncio • Peewee-async – https://peewee-async.readthedocs.io/ • Responder comes with Marshmallow – https:// marshmallow.readthedocs.io/ (a serialisation standard)
  10. Built-in Requests for tests import myapi @pytest.fixture def api(): return

    myapi.api def test_response(api): hello = "hello, world!" @api.route('/some-url') def some_view(req, resp): resp.text = hello r = api.requests.get(url=api.url_for(some_view)) assert r.text == hello
  11. How to start? • https://github.com/metakermit/responder-react • A simple Responder backend

    & React frontend starter kit • Using https://parceljs.org/ – a fast, 0-config web app bundler pip install -U cookiecutter cookiecutter gh:metakermit/responder-react cd helloresponderreact # local environment bin/install bin/start # docker environment docker-compose up
  12. Thanks!