A demonstration project showcasing a Django-based API for uploading and querying CSV files.
Before running the project, make sure you have the following components installed:
- Python 3.12 or later
- PostgreSQL 14 or later
Ensure that your PostgreSQL database is running and configured. Create a database and user for the project.
The project uses environment variables for configuration. Create a .env
file in the root directory of the project and add the following variables:
SECRET_KEY=your_secret_key
POSTGRES_DB=mydatabase
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypassword
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
Ensure you have created and activated a Python virtual environment. Then, install the required dependencies:
pip install -r requirements.txt
Run the database migrations to create the necessary tables:
python manage.py makemigrations
python manage.py migrate
Start the project with the following command:
python manage.py runserver
Your project should now be available at http://127.0.0.1:8000/.
Make a POST request to http://127.0.0.1:8000/api/upload-csv/
with a JSON body containing the URL to the CSV file and the table name. Optionally, you can specify the overwrite
parameter.
{
"url": "URL_TO_CSV_FILE",
"table_name": "desired_table_name",
"overwrite": true
}
Make a GET request to http://127.0.0.1:8000/api/data/?table=desired_table_name&column1=value1
to retrieve data from the table filtered by column1
.
Examples of how to use the API endpoints can be found in the demo.http file.