Skip to main content

Script to populate .env file from a Google Sheet

Project description

Google Env

A simple utility which pulls development-time values from a Google spreadsheet. This allows you to share dev secrets in a semi-secure way.


  1. You need an Oauth credentials JSON file. One person needs to register an Oauth app in the Google Console and then download the credentials JSON file. Place this file in $HOME/google_env_creds.json.

  2. Now create a .env file in your code project. Reference the spreadsheet which contains your secrets at the top of the file:


# GOOGLE_ENV:!Sheet1

Note that the sheet name should be after the '!' at the end.

  1. Install the google_env package:

    pip install google_env

  2. Now run the google_env script directory containing your .env file

    $ google_env

The first time you run it you will be sent through the Google Oauth flow in the browser. Your access key to the spreadsheet will then be cached in a local file in ~/.google_env_token.

Now the contents of your spreadsheet are downloaded and inserted into the .env file. Your spreadsheet should have 2 columns, the key and the value, with no header.

So if your sheet looks like this:

1 key1 mysecretkey1
2 AWS_ACCESS foobar

Then the resulting .env file will be rewritten as:


Note that you should leave the closing comment line. This will allow you to re-run google_env any time to update keys from the spreadsheet.

If you need to override any values, simply add a second assignment for that key lower down in your .env file.

Doing other things with Google Sheets

This package can be used to easily retrieve information from any Google Sheet.

 > import google_env
 > for row in google_env.read_sheet(sheet_id, sheet_range):
       # row will be an array of column values for each row in the sheet

Where sheet_id is like 1mhs7mW7dBK_lhNYB4hZFwdF1QXWSEzl6ITsY50DGx9M and sheet_range is a Sheets range like <name>!<range spec> like Sheet1!A1:G20.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for google-env, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size google_env-0.4.0-py2.py3-none-any.whl (4.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size google_env-0.4.0.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page