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

More Decks by Dražen Lučanin

Other Decks in Programming


  1. Responder
    Dražen Lučanin


    Django Friends – Vienna 20.11.2018.

    View Slide

  2. Hello, world!
    import responder
    api = responder.API()
    async def greet_world(req, resp, *, greeting):
    resp.text = f"{greeting}, world!"
    if __name__ == '__main__':

    View Slide

  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

    View Slide

  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?

    View Slide

  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…

    View Slide

  6. ASGI – async / await
    • Starlette – an ASGI implemented on top of uvicorn

    • async background tasks without Celery – no blocking
    import time
    async def receive_incoming(req, resp):
    def process_data(data):
    """Just sleeps for three seconds, as a demo."""
    # 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).
    # Immediately respond that upload was successful.
    resp.media = {'success': True}

    View Slide

  7. f-string syntax routes
    • The beloved Python 3 feature in action
    def hello_to(req, resp, *, who):
    resp.text = f"hello, {who}!"

    View Slide

  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)

    View Slide

  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)

    View Slide

  10. Built-in Requests for tests
    import myapi
    def api():
    return myapi.api
    def test_response(api):
    hello = "hello, world!"
    def some_view(req, resp):
    resp.text = hello
    r = api.requests.get(url=api.url_for(some_view))
    assert r.text == hello

    View Slide

  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
    # docker environment
    docker-compose up

    View Slide

  12. Thanks!

    View Slide