Virtual Environments

Create and activate a venv
python -m venv /path/to/new-env (1)
source /path/to/new-env/bin/activate (2)
1 Creates a new virtual environment
2 Activate the new virtual environment
Deactivate venv
deactivate
Save used dependencies to a file
pip freeze > dependencies.txt
Install dependencies from file
pip install -r dependencies.txt

Storing and fetching Credentials from the System Keyring

I am using jaraco/keyring here:

pip install keyring
import keyring

keyring.set_password("system", "db.sample.password", "xoxo")

print(keyring.get_password("system", "db.sample.password"))
keyring mac keystore
Figure 1. Our credentials in the Mac keystore

Python Data Science

For more snippets about numpy, pandas, jupyter and co., please see Python Data Science Snippets for more information.