import subprocess as sp
SOURCE = 'your_file_path'
proc = sp.Popen(['bash', '-c', 'source {} && env'.format(SOURCE)], stdout=
    sp.PIPE)
source_env = {tup[0].strip(): tup[1].strip() for tup in map(lambda s: s.
    strip().split('=', 1), proc.stdout)}
Load environment variables from a shell script