Generate strong, random secret keys for cryptography, APIs and applications - instantly.
Django's SECRET_KEY signs sessions, password-reset tokens, CSRF tokens and other
cryptographic values, so it has to be long and unpredictable. This generator makes one for you: each click
calls Python's secrets.token_urlsafe(32), which pulls 32 random bytes - 256 bits - from the
operating system's cryptographically secure RNG and encodes them as a URL-safe Base64 string of about 43
characters.
The same value works anywhere you need a high-entropy secret: API signing keys, token seeds, or general app config. It is generated on our server and returned over HTTPS. If you would rather not use a key shown in a browser, the FAQ below has the one-line command to produce the identical kind of key on your own machine.
SECRET_KEY value) and keep it out of version control.secrets module, a CSPRNG.SECRET_KEY, API secrets and signing keys.Starting a new Django project, rotating a key that was committed to a repo by mistake, giving staging and production their own separate secrets, or generating a signing key for any service that needs one. A new key takes one click, so there is no reason for two environments to share the same secret.
Each click calls Python's secrets.token_urlsafe(32), a cryptographically secure generator that returns 32 random bytes (256 bits) encoded as a URL-safe Base64 string of about 43 characters.
Yes. Django only needs a long, unpredictable string, and a 256-bit URL-safe token works fine. Set it as SECRET_KEY in your settings and keep it out of source control.
The key uses a secure random source, but it does travel from our server to your browser. For the highest assurance, generate one locally with the command python -c "import secrets; print(secrets.token_urlsafe(32))", which is exactly what this page runs.
No. Use a fresh key per project and per environment, and rotate it if it ever leaks. Reusing keys undermines the signing they are meant to protect.