If you’re an application programmer you’ve probably run into a relational database at
some point in your professional career. Whether you’re writing enterprise client-server
applications or building the next Web 2.0 killer application, you need someplace to
put the persistent data for your application, and relational databases, accessed via SQL,
are some of the most common places to put that data.
SQL is a powerful language for querying and manipulating data in a database, but
sometimes it’s tough to integrate it with the rest of your application. You may have
used some language that tries to merge SQL syntax into your application’s programming
language, such as Oracle’s Pro*C/C++ precompiler, or you may have used string
manipulation to generate queries to run over an ODBC interface. If you’re a Python
programmer, you may have used a DB-API module. But there is a better way.
This book is about a very powerful and flexible Python library named SQLAlchemy
that bridges the gap between relational databases and traditional object-oriented programming.
While SQLAlchemy allows you to “drop down” into raw SQL to execute
your queries, it encourages higher-level thinking through a “pythonic” approach to
database queries and updates. It supplies the tools that let you map your application’s
classes and objects onto database tables once and then “forget about it,” or return to
your model again and again to fine-tune performance.
SQLAlchemy is powerful and flexible, but it can also be a little daunting. SQLAlchemy
tutorials expose only a fraction of what’s available in this excellent library, and though
the online documentation is extensive, it is often better as a reference than a way to
learn the library initially. This book is meant as both a learning tool and a handy reference
for when you’re in “implementation mode,” and need an answer fast.
This book covers the 0.4 release series of conservatively versioned SQLAlchemy.