How the duck those packages work?
About me

Marcelo Trylesinski
FastAPI Expert

OSS Maintainer
### Uvicorn

### Starlette

Software Engineer at Pydantic

Motivation

Understand how things are connected
This is the goal for today!
Who is the server?
Let's learn how things happen!
Client initiates the connection
Server creates a task (connection)
Uvicorn implements asyncio.Protocol
connection_made is called

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

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
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
Server will run the application

Server will communicate with the application via ASGI events
What's ASGI?
https://asgi.readthedocs.io/en/latest/
Simple ASGI application
Echo ASGI application
FastAPI is an ASGI application
FastAPI is an ASGI application
Starlette is an ASGI application
Middleware & ASGI Application
Middleware & ASGI Application
Starlette does the routing
Starlette -> Router -> Route
The endpoint is called
Dependency Injection
The data is validated
What is Pydantic?

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
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
What now?
Task will stay alive for a while
Connection object is closed
That's it!
Support for WebSockets
Support for Lifespan Events
What happens on shutdown?
Where to go from here?
- Help on issues
- 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!
Marcelo Trylesinski @marcelotryle Kludex