Optional parameter models in FastAPI 0.159.0 ✨

No dates? No filter.

Send either date? Both are required.

Make the whole Pydantic model optional while keeping its fields required.

Works with query parameters, headers, and cookies. 🚀

fastapi.tiangolo.com/tutorial/query…

Oct 21, 2026 · 8:04 PM UTC

3
2
55
2,980
RepliesRelevant
Replying to @FastAPI
@FastAPI @tiangolo Interesting!
No more boilerplate code to validate inputs manually
0
0
3
37
Replying to @FastAPI
@FastAPI finally my hand-rolled date range check retires. eleven versions in one day tho, my lockfile 💀
0
0
1
45
Replying to @FastAPI
@FastAPI I'd use that for every date range filter, both dates or none
0
0
0
26