Python Forum
Recommended way to store users,db credentials in a Python project?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recommended way to store users,db credentials in a Python project?
I am working on a project where I am storing DB and users's credentials inside python code.
For example I have a script which do crud operations and I am storing credential in this script as below-
credentials = {
"UAT": {
    "host": 'UAT_HOST',
    "port": UAT_PORT_Num,
    "read_db": 'SCHEMA_1',
    "write_db": 'SCHEMA_2',
    "user": 'UAT_USER',
    "password": 'UAT_PASSWORD'
"S3": {
    "KEY": 'S3_KEY',
Similarly I have a script where I am using credentials like-
STORE_ID = '1'
URL = ''
environment = 'UAT'
I need to move above credentials in a secure place but I don't have any idea how to do that.
I am using Python3.6,Mysql.
Can you please suggest me what will be the standard approach?
I am sure that many of you have worked on a Project and you must be not using credentials in your python code.
So Guyz share your learnings and best practice here!

It seems I got my answer so sharing for others also-

If you have any better one then please share .
You can find accidentally uploaded credentials on GitHub.
It's a bad idea to store the credentials in source code.
Just follow the concept, which is usee regular in PHP-Projects like Wordpress.
They store the credentials in a configuration file. If the project is hosted on GitHub,
you upload a credentials.example.ini instead your credentials. Additionally, if you use a vcs,
put your own credentials file on a ignore list. This file should never be uploaded.
Otherwise you'll have guests on your account ;-)

You can parse ini files with:
Or you just use the json format.
Almost dead, but too lazy to die:
All humans together. We don't need politicians!

Possibly Related Threads…
Thread Author Replies Views Last Post
  python application and credentials safety concern aster 4 1,444 Mar-06-2021, 06:51 PM
Last Post: snippsat
  Using python to execute app or cmd that requires admin credentials thewolf 0 838 Mar-05-2021, 08:15 PM
Last Post: thewolf
  httplib2 - how to see credentials added by add_credentials? MSV 2 916 Aug-05-2020, 12:24 PM
Last Post: MSV
  How does a set in python store the elements? idknuttin 5 1,412 Jul-10-2020, 10:46 PM
Last Post: Gribouillis
  How to make Python 3.7.6 accessible to users Doguhan 4 1,190 May-19-2020, 05:36 PM
Last Post: snippsat
  Recommended way to read/create PDF file? Winfried 1 1,252 Mar-17-2020, 03:17 PM
Last Post: Larz60+
  [split] Python Module for Druid Users - "druidpy!" adaomacarl 0 857 Jan-14-2020, 11:34 AM
Last Post: adaomacarl
  Reading blob data from database by python and store it in .zip format Adityasi 2 2,543 Nov-18-2019, 05:22 PM
Last Post: ibreeden
  How do I install apps from google play store? using python + selenium.. mongo 0 1,259 Aug-05-2019, 12:41 AM
Last Post: mongo
  Store a python list of lists in a database to use for searches later on klllmmm 3 1,596 Jun-20-2019, 07:54 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020