Ramya Report Python
Ramya Report Python
Introduction
1. SQLite3
2. Pandas
3. SQLAlchemy
1. SQLite3
SQLite3 is a lightweight, disk-based database that doesn’t require a separate server process. It is
suitable for small to medium-sized applications, testing, and prototyping.
Example:
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
# Create a table
cursor.execute('''CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age
INTEGER)''')
# Insert data
conn.commit()
# Query data
Department of ECE, EPCET Page 1
DATABASE BROWSER
print(cursor.fetchall())
conn.close()
2. Pandas
Pandas is a powerful data manipulation library that can read from and write to various database
formats. It is ideal for data analysis and manipulation.
Example:
import pandas as pd
import sqlite3
# Connect to a database
conn = sqlite3.connect('example.db')
print(df)
conn.close()
3. SQLAlchemy
Example:
engine = create_engine('sqlite:///example.db')
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
age = Column(Integer)
Base.metadata.create_all(engine)
# Create a session
Session = sessionmaker(bind=engine)
session = Session()
session.add(new_user)
session.commit()
# Query users
users = session.query(User).all()
print(user.name, user.age)
session.close()
Conclusion:
Python provides a variety of libraries for database browsing, each suited for different types of
databases and use cases. SQLite3 is excellent for lightweight local databases, Pandas is great for
data manipulation, SQLAlchemy offers powerful ORM capabilities, and PyMySQL is ideal for
MySQL interactions. By leveraging these libraries, users can efficiently manage, query, and
analyze data stored in databases.
References:
SQLite3 Documentation
Pandas Documentation
SQLAlchemy Documentation