How do you type-hint repeated query params in FastAPI?

Tests FastAPI's Annotated pattern for multi-value query strings. A great answer uses Annotated[list[str], Query()] = [] to collect repeated keys, and notes the old Query-as-default alternative. Red flag: manual parsing or typing it as str.
Tests whether you know FastAPI's modern pattern for collecting repeated query parameters into a list. A strong answer imports Annotated and Query, then declares the parameter as Annotated[list[str], Query()] = [] so FastAPI gathers every matching key into a list. Mention that keyword=python&keyword=fastapi becomes ["python", "fastapi"], and contrast the old Query-as-default style. Red flags: typing it as str, manually parsing Request.query_params, or using a mutable default without understanding why Annotated is preferred.
Read the original → fastapi.tiangolo.com
- #fastapi
- #python
- #type-hints
- #query-parameters
- #annotated
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.