Junior — Middle
What tools or libraries have you used for working with databases in your projects?
sobes.tech AI
Answer from AI
In Python projects for working with databases, the following tools and libraries are often used:
sqlite3— a built-in library for working with SQLite, suitable for lightweight databases.psycopg2— a popular driver for PostgreSQL.PyMySQLormysql-connector-python— for working with MySQL.- ORM libraries such as
SQLAlchemy— provide a convenient level of abstraction for working with different DBMS. Django ORM— the built-in ORM of the Django framework.Peewee— a lightweight ORM.
Example of connecting to SQLite and executing a query:
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')
cursor.execute('INSERT INTO users (name) VALUES (?)', ('Alice',))
conn.commit()
cursor.execute('SELECT * FROM users')
print(cursor.fetchall())
conn.close()