Simple password manager for my Python projects
Sometime I am creaing Python scripts for various purposes. My trouble is that scripts often need credentials and I have to be careful to not commit credentials into repository and/or put credentials back to my script when I want to use it. So I have decided to create simple password manager for my scripts.
Idea was very simple - to create Python package which will keep credentials in vault in my home directory. Python script will just ask “give me credentials for named project” and password manager will read and provide them back or prompt credentials if they don’t exist and save them in vault. Usage should be as simple as possible and ideally vault is encrypted.
Result is here and usage is really simple. First you need to install mypwd package.
1
2
pip install mypwd
And now you can use it in your script.
1
2
3
4
5
6
7
import mypwd
# get credentials for mongo-dev project from vault
login, password, server = mypwd.get_values("mongo-dev", ["login", "password", "server"])
#use credentials in mongodb uri string
uri = f"mongodb://{login}:{password}@{server}/admin?retryWrites=true&w=majority"
What all parameters will be in array is up to you. If credentials are missing in your vault password manager will simply prompt them and store them in vault.
Vault is json file stored in $HOME/mypwd.json
and here is example how it may look like.
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"mongo-uat": {
"login": "appl",
"password": "hS78#pbTgc#J.CQL",
"server": "myserver-uat.com"
},
"mongo-dev": {
"login": "appl",
"password": "VacK>p3k3~t*c~RX",
"server": "myserver-dev.com",
"note": "Valid until end of month"
}
}
You can encrypt vault with your gpg
key and password manager will work with this encrypted version.
1
mypwd encrypt -e your.email@something.com
In case you needed decrypt it manually you can use following command.
1
mypwd decrypt
I know, encryption using gpg is a bit cumbersome but it works fine.
Visit project in GitHub