This project connects to a PostgreSQL database using Python and environment variables.
Real credentials are never stored in the code or in the Git repository; they are provided via a local .env file that is gitignored.
- Python 3.10+
- PostgreSQL server installed locally on your machine
pipfor installing dependencies
-
Clone this repository:
git clone https://github.com/your-username/your-repo.git cd your-repo -
Install dependencies:
pip install -r requirements.txt
The
requirements.txtfile should include at least:psycopg2 python-dotenv
PostgreSQL should be already installed and running locally on your machine (for example via the official installer or your OS package manager).
From there (run in 'psql'), create a database and user that this project will use. Example SQL:
CREATE DATABASE data_warehouse;
CREATE USER myapp_user WITH PASSWORD 'your_strong_password';
GRANT ALL PRIVILEGES ON DATABASE data_warehouse TO myapp_user;
You can change the database name, user, and password if you prefer; just keep the .env file in sync.
This project reads database configuration from environment variables.
For local development, those variables come from a .env file in the project root (which is not committed to Git).
-
Create a new file called
.envin the project root:DB_HOST=localhost DB_NAME=data_warehouse DB_USER=myapp_user DB_PASSWORD=your_strong_password DB_PORT=5432
-
Ensure
.envis listed in.gitignoreso your secrets are not pushed to Git. -
In the code,
python-dotenvloads these values:from dotenv import load_dotenv load_dotenv() # loads .env into os.environ
Then the script uses
os.getenv("DB_HOST"), etc., to build the connection.
With PostgreSQL running locally and .env configured:
python data_warehouse_setup.pyThe script will:
- Load environment variables from
.env - Use them to create a PostgreSQL connection via
psycopg2 - Run whatever logic is implemented to set up the data warehouse (e.g. creating tables, inserting seed data)