This script creates a PostgreSQL table and populates it with fake user data using the Faker library.
-
Creates a
userstable with the following columns:system_uid- Auto-generated UUID (primary key)first_name- Textlast_name- Textemail- Textaddress- VARCHARphone- Textjob- Textcompany- Textdate_of_birth- Date
-
Generates a configurable number of fake user records using the Faker library
-
Inserts the generated data into the PostgreSQL database
-
Optional display of all inserted records (currently disabled by default)
- Create a virtual environment and install the required dependencies:
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txtYou can configure the database connection using either of these methods:
Create a .env file in the project root with your PostgreSQL credentials:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_database_name
DB_USER=your_username
DB_PASSWORD=your_passwordThen edit config.py with your database credentials.
Run the script with the number of records to generate:
# Generate 15 records (default)
python main.py 15
# Generate 50 records
python main.py 50
# Generate 5 records
python main.py 5
# Show help
python main.py --helpThe script will:
- Connect to your PostgreSQL database
- Create the
userstable (if it doesn't exist) - Generate the specified number of fake user records
- Insert them into the database
- Commit all changes to the database
Note: The count argument is required. You must specify how many records to generate.
- Python 3.6+
- PostgreSQL 9.6+ (for
gen_random_uuid()support) - Required Python packages (see
requirements.txt)
- The script uses
CREATE TABLE IF NOT EXISTS, so it's safe to run multiple times - Each run will insert the specified number of new records without removing existing ones
- The
system_uidis automatically generated by PostgreSQL using UUID - Phone numbers and addresses are cleaned/formatted to fit database constraints
- The script uses rich logging for better console output
- User display functionality is available but commented out by default