Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL Faker Data Generator

This script creates a PostgreSQL table and populates it with fake user data using the Faker library.

Features

  • Creates a users table with the following columns:

    • system_uid - Auto-generated UUID (primary key)
    • first_name - Text
    • last_name - Text
    • email - Text
    • address - VARCHAR
    • phone - Text
    • job - Text
    • company - Text
    • date_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)

Installation

  1. 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.txt

Configuration

You can configure the database connection using either of these methods:

Option 1: Environment Variables (Recommended)

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_password

Then edit config.py with your database credentials.

Usage

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 --help

The script will:

  1. Connect to your PostgreSQL database
  2. Create the users table (if it doesn't exist)
  3. Generate the specified number of fake user records
  4. Insert them into the database
  5. Commit all changes to the database

Note: The count argument is required. You must specify how many records to generate.

Requirements

  • Python 3.6+
  • PostgreSQL 9.6+ (for gen_random_uuid() support)
  • Required Python packages (see requirements.txt)

Notes

  • 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_uid is 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

About

This repository contains a python project to create and insert fake users data in postgresql database.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages