Skip to content

How the duck those packages work?


About me

bg:40% 80%

Marcelo Trylesinski


FastAPI Expert


OSS Maintainer

### Uvicorn ![w:450](https://raw.githubusercontent.com/tomchristie/uvicorn/master/docs/uvicorn.png)
### Starlette ![w:600](https://raw.githubusercontent.com/koddr/starlette-logo/master/src/dark/svg/starlette__full_logo__with_text__dark.svg)

Software Engineer at Pydantic

w:900


Motivation

w:850


Understand how things are connected

This is the goal for today!


w:1000


Who is the server?

w:500


Let's learn how things happen!


Client initiates the connection

w:800


Server creates a task (connection)

w:500


Uvicorn implements asyncio.Protocol

w:800


connection_made is called

w:900

https://docs.python.org/3/library/asyncio-protocol.html#asyncio.BaseProtocol.connection_made


data_receive is called

w:900

https://docs.python.org/3/library/asyncio-protocol.html#asyncio.Protocol.data_received


h11 is a Sans-IO protocol library

httptools is a callback based library


Server will receive the request

w:450


Two things can happen

1. Create the "HTTP connection Scope"

2. Upgrade the connection


Create the "HTTP connection Scope"

headers, path, method, query_string, etc.

https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope


Or... Server will upgrade the connection

w:500


Server will run the application

w:1000


Server will communicate with the application via ASGI events


What's ASGI?

w:1000

https://asgi.readthedocs.io/en/latest/


Simple ASGI application

w:1000


Echo ASGI application

w:1000


FastAPI is an ASGI application

w:700


FastAPI is an ASGI application

w:1000


Starlette is an ASGI application

w:1000


Middleware & ASGI Application

w:800


Middleware & ASGI Application

w:1000


Starlette does the routing

Starlette -> Router -> Route


The endpoint is called

w:800


Dependency Injection

w:1000


The data is validated

w:800


What is Pydantic?

w:1000


Come to me to get my card, to get early access to the product we are building!


Endpoint function runs


Data will be validated on output

w:700


Middlewares again

Remember?


The application sends events to the ASGI server


ASGI server makes sure the ASGI application complies to the spec


Server sends data to the client

w:1000


What now?


Task will stay alive for a while


Connection object is closed


That's it!


Support for WebSockets

w:1000


Support for Lifespan Events

w:900


What happens on shutdown?


Where to go from here?

  1. Help on issues
  2. Watch your favorite packages on GitHub

Predicting questions...

Starlette/FastAPI/Uvicorn V1


Predicting questions...

Will you come to India if you get invited next year?


Yes.


Thank You!

marcelotryle.com

Marcelo Trylesinski @marcelotryle Kludex