Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Somthing wrong with using CSV as database for a webapp?

I am using Flask to make a small webapp to manage a group project, in this website I need to manage attendances, and also meetings reports. I don't have the time to get into SQLAlchemy, so I need to know what might be the bad things about using CSV as a database.

like image 817
theatropos1994 Avatar asked Nov 15 '25 14:11

theatropos1994


2 Answers

Just don't do it.

The problem with CSV is …

a, concurrency is not possible: What this means is that when two people access your app at the same time, there is no way to make sure that they don't interfere with each other, making changes to each other's data. There is no way to solve this with when using a CSV file as a backend.

b, speed: Whenever you make changes to a CSV file, you need to reload more or less the whole file. Parsing the file is eating up both memory and time.

Databases were made to solve this issues.

I agree however, that you don't need to learn SQLAlchemy for a small app.

There are lightweight alternatives that you should consider.

What you are looking for are ORM - Object-relational mapping - who translate Python code into SQL and manage the SQL databases for you.

PeeweeORM and PonyORM. Both are easy to use and translate all SQL into Python and vice versa. Both are free for personal use, but Pony costs money if you use it for commercial purposes. I highly recommend PeeweeORM. You can start using SQLite as a backend with Peewee, or if your app grows larger, you can plug in MySQL or PostGreSQL easily.

like image 119
mcbetz Avatar answered Nov 17 '25 07:11

mcbetz


Don't do it, CSV that is.

There are many other possibilities, for instance the sqlite database, python shelve, etc. The available options from the standard library are summarised here.

Given that your application is a webapp, you will need to consider the effect of concurrency on your solution to ensure data integrity. You could also consider a more powerful database such as postgres for which there are a number of python libraries.

like image 33
mhawke Avatar answered Nov 17 '25 07:11

mhawke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!