I have a repository with a handful of Python scripts (ETL jobs) that connect to various APIs (Google Analytics, Amazon, etc.). I'm using a virtual environment to keep track of dependencies when deploying this repo to a VPS instance. I also have a CONFIG.py
file with various API keys, database credentials, etc. (that I keep out of version control).
Just recently I needed to connect to the Google DFP API. There's a known bug that when you install the googleads
library (using pip) it will install a newer version of the oauth2client
library, which will break my Google Analytics API scripts because the google-api-python-client
uses an older version of oauth2client
.
So, to overcome this obstacle I'm considering creating a sub directory in my repo called, Google_DFP
and creating a new virtual environment that uses the newer version of oauth2client
. Here is the new structure of my repo:
/ETL_Scripts
CONFIG.py
google_analytics.py
google_search_console.py
amazon_affiliate.py
/venv
/Google_DFP
google_dfp.py
/venv2
In my google_analytics.py
file I use this to import the credentials from CONFIG import DB_CREDENTIALS
and then use that object to connect to my database (username, password, etc.).
My question is: how do I import variables out of the CONFIG.py
file (in the parent directory) within the google_dfp.py
file? When I attempt to import variables out of CONFIG.py
-- from ..CONFIG import DB_CREDENTIALS
-- I get this error: ValueError: Attempted relative import in non-package
.
Here's what my CONFIG.py
file looks like:
AMAZON_API_KEY = "abcxyz123987"
DB_CREDENTIALS = {
'database': 'fancy_reporting_db
'user': 'etl_user',
'host': 'localhost',
'password': 'password'
}