# Sessions and Cookies, and When They Fit Better

A session signs a user in with a random id from secrets.token_urlsafe, kept in a sessions table and sent in an HttpOnly, Secure, SameSite cookie, so signing out deletes a row and takes effect at once, which suits one website on one server better than a token that stays valid until it expires.

![Cheat sheet: Sessions and Cookies, and When They Fit Better](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/6c8db9465de64d3fb81c05b98d64e244.webp)

- Category: FastAPI
- Level: Journeyman
- Tags: Cookie, fastapi, HttpOnly, rest-api, SameSite, Session (web-development), Stateless
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/fastapi-auth-sessions-and-cookies-cheat-sheet
