Skip to content

Instantly share code, notes, and snippets.

@celeroncoder
Last active March 30, 2021 14:16
Show Gist options
  • Save celeroncoder/eb2f5aa696cd8c5452e296a97f5e6a14 to your computer and use it in GitHub Desktop.
Save celeroncoder/eb2f5aa696cd8c5452e296a97f5e6a14 to your computer and use it in GitHub Desktop.
Secret Key Generator

Secret Key Generator

  • This is a secret key generator for generating 100 word, alphanumeric, random secret key to use in Django.
  • This uses python 3.6's default lib secrets and string to generate the key.
  • pyperclip library is to copy the key to the clipboard.

Usage

  • Copy the script and run the script that will print the secret key to the console and also copy that to the clipboard.
  • Install the sole dependencies(pyperclip) using the requirements.txt file.
     pip install -r requirements.txt
import secrets
import string
# to copy the secret key to clipboard.
import pyperclip
secret_key = "".join(secrets.choice(string.digits + string.ascii_letters + string.punctuation)for i in range(100))
if __name__ == "__main__":
print(f'Key: {secret_key}')
pyperclip.copy(secret_key)
print('Key copied to clipboard')
pyperclip==1.8.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment