ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
SQLPARSE
5 years of parsing and
formatting SQL statements
/
PythonCamp, Cologne
May 2013
Andi Albecht @andialbrecht
sqlparse - Usage
Purpose
Give a little insight into SQL statements in Python.
Simple top-level API
Known Use Cases
Make generated statements readable
Give it a string, get a list of separate statements
Extract table and column names
sqlparse.parse(sql,encoding=None)
sqlparse.split(sql,encoding=None)
sqlparse.format(sql,**options)
sqlparse - History
Basic needBasic need Get at least a little knowledge of statements
in CrunchyFrog.
Basic ideaBasic idea Can't be validating since it should work while
editing SQL statements. "If highlighting is
right, parsing couldn't be so wrong." ¡ú use
as a base!
Sep. 2008Sep. 2008 First pieces of code in CrunchyFrog
Apr. 2009Apr. 2009 First official release (0.1.0)
Pygments
appear
sqlparse - History
Immediate reply (sorry, couldn't find the original tweet):
"This is just script kiddy stuff. I won't give a shit."
Challenge accepted.
sqlparse - History
Apr. 2013Apr. 2013 Current release (0.1.7)
It's still here.
sqlparse - some
numbers
about 2.300 LOC (~3.300 total)
88% test coverage, > 120 tests
single code base for Python 2.4, 2.5, 2.6, 2.7, 3.2, 3.3,
PyPy
version 0.1.6 had > 10.000 downloads from PyPI
licensed under BSD
development happens on Github
sqlparse - example
projects
RunSQLRun - Database query tool for Linux
Successor of CrunchyFrog, based on Gtk3 / Python 3
http://runsqlrun.org
sqlparse - example
projects
SQLFormat - Online service to format SQL statements
Serves as a testbed for sqlparse, formats ~1.000 statements / day
http://sqlformat.org
sqlparse - example
projects
Django Debug Toolbar - Lists debug information for
Django projects
Used for pretty printing statements when running debugsqlshell(optional requirement).
https://github.com/django-debug-toolbar/django-debug-toolbar
sqlparse - example
projects
Calendar and Contacts Server - Standards compliant
CalDAV and CardDAV server.
Not sure for what it's used there, most likely debugging ;)
http://www.calendarserver.org/
Thanks!
Links
Project homepage:
Documentation:
Try it:
Contact
Homepage:
Twitter:
Mail:
github.com/andialbrecht/sqlparse
sqlparse.readthedocs.org
sqlformat.org
andialbrecht.de
@andialbrecht
albrecht.andi@gmail.com

More Related Content

sqlparse Lightning Talk