[IPython-User] SQL magic functions

Brian Granger ellisonbg@gmail....
Tue Jun 15 15:16:07 CDT 2010


This looks like an extremely useful magic function!  Currently we are
in the process of refactoring/organizing things in IPython.  In the
past, we accepted 3rd party magic functions almost without review and
included them with IPython.  Over time though, many of these
extensions developed bit rot.  To help us clean these things up, our
approach for now is to encourage users to maintain these things as
separate projects.  The idea is this:

* Put your extension up on launchpad, github, bitbucket, etc.
* Send us a link and we will create a wiki page that has links to all
the extensions.

Over time, we may merge some extensions back into IPython proper, but only if:

* They are well tested (test suite).
* Many people want to use them.
* We have people willing to maintain them.



On Sun, Jun 13, 2010 at 6:59 PM, Christopher Brooks
<cab938@mail.usask.ca> wrote:
> Often I need to insert and remove things from a DB while doing data
> analysis.  I use normal python db apis for this, but I recently wrapped a
> couple in magic functions within ipython to make it a bit more natural.
>  Nothing too fancy here, but it makes the simple routines of retrieving and
> inserting data easy...
> Script attached for those interested (mysql only atm), examples below...
> Chris
> Definition:     sql(self, arg)
> Docstring:
>    Provides simplified syntax for operating with databases.  Query
> types supported include SELECT, INSERT, and DELETE.  Initialization of SQL
> connection must be done first, for instance:
>        sql_db=MySQLdb.connect("host","user","pass","schema")
>    Usage examples:
>        %sql select * from data
>        %sql describe data
>        %sql insert into data values ("a","b","c")
>        %sql insert into data myvar
>            if myvar is a dict this expands to "insert into data
> (key1...keyn) values (val1...valn)
>        %sql create table data myvar"
>          if myvar is a dict this creates the table with columns as keys and
> datatypes as values
>          e.g. myvar = {'col1': 'VARCHAR(255)', 'col2': 'INT'}
>    See also:
>        %raw_sql
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo

More information about the IPython-User mailing list