The Easist Way To Create Your Secret Key In Three Simple Steps

#4 Python Weekly

Β·

2 min read

The Easist Way To Create Your Secret Key In Three Simple Steps

Hello there! πŸ‘‹

In this article, you will be learning how to generate your secret key for your python projects. This is a guide for python enthusiasts; beginners and intermediate pythoneers.

Okay, Let’s begin!! πŸŽ‰πŸŽ‰πŸŽ‰

First, we will be creating a project directory

Open cmd on your system:

Command Prompt, AKA cmd is a program that emulates the input field in a text-based user interface screen with the Windows graphical user interface (GUI). It can be used to execute entered commands and perform advanced administrative functions.

For windows users:

  1. Navigate to the search bar on the taskbar area
  2. Type cmd
  3. Click on Command Prompt.

For mac users:

  1. Press Command + Space Bar on your Mac Keyboard.
  2. Type in Terminal.
  3. When you see Terminal in the Spotlight search list, click it to open the terminal.

Create a project directory:

I will be creating it on my desktop – it’s your choice where you create yours.

For windows users:

  1. Type cd desktop
  2. Type mkdir secret-key.

Mkdir is a keyword that makes file directory and secret-key is the name of the project directory.

For mac users:

  1. Type pwd.

    Pwd stands for Print Working Directory .

  2. Type cd Desktop.

CD stands for Change Directory .

  1. Type mkdir secret-key.

Mkdir stands for Make Directory.

Now that we have successfully created the project directory, let’s create our secret key πŸš€

This will be done in three easy, simple steps.

Before we start this, make sure your system has python installed. If you do not have python installed, click python.org/downloads, select system an OS (Operating System) then hit the download button. Download the latest version, it has better features.

Windows Installation:

phoenixnap.com/kb/how-to-install-python-3-w..

Mac Installation:

docs.python-guide.org/starting/install3/osx

Linux Installation:

docs.python-guide.org/starting/install3/linux

Create your Secret Key in three steps

  1. Type python and enter
  2. Type import secrets and enter
  3. Type secrets.token_hex(16) and enter

The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.

The secrets.token_hex([nbytes=None]) return a random text string, in hexadecimal. The string has nbytes random bytes, each byte converted to two hex digits. If nbytes is None or not supplied, a reasonable default is used. In this case, nybtes is 16 so the output would be a random text string ( including alphabets and numbers).

Keep in touch:

Thanks for reading till the end ❀️.

You can contact me via email and/or Discord:

Email -

Discord - Sophyia#8929

Β