Junior — Middle
What ORM libraries have you used in your projects?
sobes.tech AI
Answer from AI
The following ORM libraries are often used in Python projects:
- SQLAlchemy — a powerful and flexible ORM supporting various DBMSs, allowing you to write both declarative models and use the Core API.
- Django ORM — the built-in ORM in the Django framework, convenient for quickly creating applications with a database.
- Peewee — a lightweight ORM suitable for small projects.
Example of using SQLAlchemy:
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
engine = create_engine('sqlite:///:memory:')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
new_user = User(name='Alice')
session.add(new_user)
session.commit()