Generate secure, URL safe, random tokens in Python
Python tip:
Use
secrets.token_urlsafe()
to generate security tokens.For example, you can generate a token for a password reset👇
import secrets url = f"https://my-app.com/password-reset/token={secrets.token_urlsafe()}" print(url) # => https://my-app.com/password-reset/token=KzmPWanja-z0r2BpyC7mFAZd5LXvp8SnIUbSnQyEMWw