I have created a CLI app in Python, a sort of library management system that uses a MySQL database to store records. If I wanted to release this as an installable app, could I do it without the end-user having to install MySQL on their own device, and going through the trouble of importing the database schema?
Note that the database is stored/hosted on the user's local machine and there is no web server interaction.
This isn't possible using a DBMS like Mysql, Postgres, Mariadb. That is what SQLite is for. All you need for a SQLite database is to install the connector, form there the rest is handled.
Check out this example of database creation and querying.
import sqlite3
connection = sqlite3.connect("test")
cursor = connection.cursor()
cursor.execute("CREATE TABLE example (name TEXT, type TEXT, count INTEGER)")
cursor.execute("INSERT INTO example VALUES ('Sammy', 'shark', 1)")
rows = cursor.execute("SELECT * FROM example").fetchall()
print(rows)
You do not need to install the sqlite3
package with pip
. As mentioned by a commenter, the package comes pre-installed with python.
Hope this helps!