Here are some basic snippets to handle TOTP tokens in Python.
Please not these are not related to Flask in anyway! You can adapt it in any context and/or framework (FWIW last time I implemented something along thoses lines was using the FastAPI framework. Check it out, it's pretty great!).
Here we go:
- Define some sort of multi-factor authentication table in your database, holding securely the shared secret for each user.