← TechnologyThe essentials of

Secrets: generating a random token for a URL or session

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 16:11 · Updated: 22 Oct 2026 16:11

AI source check: 22 Oct 2026 14:04. This is not editorial approval.

In a few sentences

In brief

secrets.token_urlsafe(32) creates a textual token from 32 random bytes using URL-safe encoding. The argument is a byte count, not a guaranteed final character count.

Useful to know

secrets.token_urlsafe(32) creates a textual token from 32 random bytes using URL-safe encoding. The argument is a byte count, not a guaranteed final character count. [1]

Randomness is only one part of using it. The application separately defines expiry, single use and storage. Do not expose active tokens in public logs or replace the generator with a predictable counter merely for convenient formatting.

Sources

For further detail and to check the information:

  1. [1] secrets — Generate secure random numbers for managing secrets — Python 3.12.15 documentation ↗