Skip to Main Content
Essential SQLAlchemy
book

Essential SQLAlchemy

by Rick Copeland
June 2008
Intermediate to advanced content levelIntermediate to advanced
230 pages
6h 29m
English
O'Reilly Media, Inc.
Content preview from Essential SQLAlchemy

Chapter 1. Introduction to SQLAlchemy

What Is SQLAlchemy

SQLAlchemy is a Python Library created by Mike Bayer to provide a high-level, Pythonic (idiomatically Python) interface to relational databases such as Oracle, DB2, MySQL, PostgreSQL, and SQLite. SQLAlchemy attempts to be unobtrusive to your Python code, allowing you to map plain old Python objects (POPOs) to database tables without substantially changing your existing Python code. SQLAlchemy includes a database server-independent SQL expression language and an object-relational mapper (ORM) that lets you use SQL to persist your application objects automatically. This chapter will introduce you to SQLAlchemy, illustrating some of its more powerful features. Later chapters will provide more depth for the topics covered here.

If you have used lower-level database interfaces with Python, such as the DB-API, you may be used to writing code such as the following to save your objects to the database:

sql="INSERT INTO user(user_name, password) VALUES (%s, %s)"
cursor = conn.cursor()
cursor.execute(sql, ('rick', 'parrot'))

Although this code gets the job done, it is verbose, error-prone, and tedious to write. Using string manipulation to build up a query as done here can lead to various logical errors and vulnerabilities such as opening your application up to SQL injection attacks. Generating the string to be executed by your database server verbatim also ties your code to the particular DB-API driver you are currently using, making migration ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PostgreSQL

Learning PostgreSQL

Salahaldin Juba, Achim Vannahme, Andrey Volkov
Practical PostgreSQL

Practical PostgreSQL

Joshua D. Drake, John C. Worsley
PostgreSQL

PostgreSQL

Korry Douglas, Susan Douglas
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov

Publisher Resources

ISBN: 9780596516147Supplemental ContentErrata Page