nagxsan/django-csv-ingest

A simple Django application that can take in CSV files and append them to existing PostgreSQL database

★ 0Forks 0PythonGitHub ↗Compare

README

Django CSV Ingestion Service

A Django service that accepts a CSV file, validates it against a PostgreSQL table's schema, and inserts the rows efficiently using PostgreSQL COPY.

This README explains how to run the project locally with Conda and via Docker Compose.


1️⃣ Run Locally Using Conda (Recommended)

1. Create Conda environment

conda env create -f environment.yml
conda activate django-csv

2. Create .env in root

DJANGO_SECRET_KEY=dev-secret
DJANGO_DEBUG=True
DB_NAME=csv_demo
DB_USER=csv_user
DB_PASSWORD=csvpass
DB_HOST=127.0.0.1
DB_PORT=5432

3. Start PostgreSQL via Docker

docker run -d --name pg \
  -p 5432:5432 \
  -e POSTGRES_USER=csv_user \
  -e POSTGRES_PASSWORD=csvpass \
  -e POSTGRES_DB=csv_demo \
  postgres:16

4. Apply migrations

python manage.py migrate

5. Start server

python manage.py runserver

API is available at http://localhost:8000

2️⃣ Run Using Docker Compose (Django + Postgres)

1. Start the stack

docker-compose up --build

2. Stop the stack

docker-compose down

API is available at http://localhost:8000

Endpoint: POST /api/upload-csv/

Field Description
table_name Name of target PostgreSQL table
file CSV file
strict true or false

Example request:

curl -X POST http://localhost:8000/api/upload-csv/ \
  -F "table_name=products" \
  -F "strict=true" \
  -F "[email protected]"

To run tests navigate to home directory and run: python manage.py test

Contributors

nagxsan

Issues