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.
Usage
-
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. -
Now create a
.envfile in your code project. Reference the spreadsheet which contains your secrets at the top of the file:
.env:
# GOOGLE_ENV: https://docs.google.com/spreadsheets/d/17fcDBp5tez9JFtRwucDW5-wq3jgmzq8s-oWcnUljyR0!Sheet1
Note that the sheet name should be after the '!' at the end.
-
Install the
google_envpackage:pip install google_env -
Now run the
google_envscript 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:
| A | B | |
|---|---|---|
| 1 | key1 | mysecretkey1 |
| 2 | AWS_ACCESS | foobar |
Then the resulting .env file will be rewritten as:
# GOOGLE_ENV: https://docs.google.com/spreadsheets/d/17fcDBp5tez9JFtRwucDW5-wq3jgmzq8s-oWcnUljyR0
key1=mysecretkey1
AWS_ACCESS=foobar
# END_GOOGLE_ENV
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
print(row)
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.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file google_env-0.4.0.tar.gz.
File metadata
- Download URL: google_env-0.4.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/2.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0286b249866745ebbfccef80d6afbccc05869670b44e85488400dd922f1564a
|
|
| MD5 |
7de417bbe1024fe0364dced6fa40b05b
|
|
| BLAKE2b-256 |
3b7e16d4cb6b2ce7b3f4f2ad06b8267555abef1f84f11bedbc6e5b1b0219f2f3
|
File details
Details for the file google_env-0.4.0-py2.py3-none-any.whl.
File metadata
- Download URL: google_env-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/2.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3dbc379d2bb0d3039a81cd2b4702d28d698201dedbce7998ccb97139d52553a
|
|
| MD5 |
c55d70360d4ba4c58d07c5b647e6bbd9
|
|
| BLAKE2b-256 |
3fa98de81115bb3bc9c21c0ba35edf80987fd3ea3d2bb50a746ac66e23a082af
|