query
query copied to clipboard
Interactive SQL database exploration in Python
query
Python module for quick, interactive exploration of SQL databases. Designed especially for use with IPython. Light wrapper on top of Pandas (>= 0.16) and SQLAlchemy (>= 0.9.9). The most recent release is available on PyPI and can be installed via pip install query
with the proper dependencies.
Quickstart
from query import QueryDb
db = QueryDb(demo=True)
But the real joy comes when using query interactively:
Key functionality
A few key functions to remember:
-
db
: The main database object. Print it in IPython to see a list of tables and their key attributes. -
db.inspect.*
: Tab-completion across the database's tables and columns. Print any table to see its columns and their types. -
db.query()
: Query the database with a raw SQL query. Returns apandas DataFrame
object by default, but can return asqlalchemy result
object if called withreturn_as="result"
.
Roadmap
Further improvements are planned, including some of the below. Please feel free to open an Issue with desired features or submit a pull request.
-
Plotting: Graphical display of queried data (some of this can easily be done off the current
DataFrame
object, but it could be better integrated) -
More Convenience Methods: Additional convenience methods, like
.tail()
and.where()
- DB Schemas: Direct output of database schema diagrams
-
Password Input via IPython: Currently entering a DB password uses
getpass
in the user's terminal. Being able to enter the password directly into IPython would be ideal (while also not writing it into any history) - More/Better Documentation: Enough said.