Virtualenvs and environment variables

I was working on a fabric file that contains some confidential data (username, password etc…) and wanted to put it on GitHub for backup. Backup the confidential data to a public website will be pretty stupid, so i was looking for a way to solve it.
Since this data is relevant only to the specific project and because i work in a virtualenv, i need the environment variables to be specific to the virtualenv in use, this is the solution i came with:
Apparently virtualenvs has a ~/.virtualenvs/[name]/bin/postactivate. This file looks like this (i currently use zsh):

#!/bin/zsh
# This hook is run after this virtualenv is activated.

After this opening we can add our environment variables:

#!/bin/zsh
# This hook is run after this virtualenv is activated.
export USERNAME="username"
export PASSWORD="thisisaverysecretpassword"
# etc...

In my script i added a call to the environment variables (very straightforward in Python):

import os
USERNAME = os.environ['USERNAME']  
# or: USERNAME = os.environ.get('USERNAME')
PASSWORD = os.environ['PASSWORD']  
# or: PASSWORD = os.environ.get('PASSWORD')

Now, if you’d like to remove all the environment variables when deactivating the virtualenv you can use the trick i used here (maybe not the perfect linux solution but it works :)):
at ~/.virtualenvs/[name]/postdeactivate just enter an empty string to each variable used:

#!/bin/zsh
# This hook is run after this virtualenv is activated.
unset USERNAME
unset PASSWORD
# etc...

Just remember that even if you don’t edit the postdeactivate file, after rebooting your system all these environment variables will be forgotten.

Hope that it will help someone 馃檪