This is a Flask API that allows you to upload a CSV file via POST request and save the contents into a new database table. It uses SQLalchemy for communication with database and pandas to read csv.
Clone the repository with the following command:
git clone https://github.com/siddharth-sundarraman/flask-csv.git
Initialize virtual environment:
python -m venv venv
Activate virtual environment:
.\venv\Scripts\activate
Install required dependencies:
pip3 install -r requirements.txt
python3 run.pyThe server will run on http://localhost:5000
To upload CSV files you can send POST requests using a tool like Postman or curl.
The API endpoint for uploading is
/api/file-import
The CSV will be saved in an sqlite database in the instance/project.db file
or curl command:
curl --location --request POST 'http://localhost:5000/api/file-import' \
--form 'files=@"/Users/sid/Downloads/grades.csv"' \
--form 'create_usr_id="sid"' \
--form 'schema="public"'
Open the SQLite CLI and connect to the database using the command in terminal:
sqlite3 project.db
View tables in database:
sqlite> .tables
output: table_name
View contents of table:
sqlite> SELECT * FROM table_name;