SQLAlchemy is a Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
SQLAlchemy provides a full suite of well known enterprise-level persistence patterns, designed for efficient and high-performing database access, adapted into a simple and Pythonic domain language.
NOTE: PLEASE report bugs / advanced issues as a GitHub discussion or on the sqlalchemy mailing list - much more comprehensive help for complex issues is available there. Please follow these guidelines when posting.
Example
metadata = MetaData()
engine = sqlalchemy.create_engine('mysql://user:pass@localhost/sql_db') # session handler
names = Table('names', metadata,
Column('id', Integer),
Column('name', String(60))
)
metadata.create_all(engine) # create tables in case they do not exist
# ask user for id and name
_id = int(input('indicate id: ')) # use `_id`, as `id` is a reserved word in python
name = input('indicate name: ')
ins = names.insert().values(name=name, id=_id) # insert values in table
References
Books:
Talks:
- Introduction to SQLAlchemy - Mike Bayer - PyCon 2014
- Introduction to SQLAlchemy Core - Jason Myers - PyCon 2014
- SQLAlchemy ORM for Beginners - Jason Myers - PyGotham 2015
- SQLAlchemy as the backbone of a Data Science company - Petter Hoffmann - EuroPython 2016