Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (48 sloc) 1.93 KB

agate-sql |release|

Install

To install:

pip install agate-sql

For details on development or supported platforms see the agate documentation.

Warning

You'll need to have the correct sqlalchemy drivers installed for whatever database you plan to access. For instance, in order to read/write tables in a Postgres database, you'll also need to pip install psycopg2.

Usage

agate-sql uses a monkey patching pattern to add SQL support to all :class:`agate.Table <agate.table.Table>` instances.

import agate
import agatesql

Importing :mod:`.agatesql` attaches new methods to :class:`agate.Table <agate.table.Table>`. For example, to import a table named doctors from a local postgresql database named hospitals you will use :meth:`.from_sql`:

new_table = agate.Table.from_sql('postgresql:///hospitals', 'doctors')

To save this table back to the database:

new_table.to_sql('postgresql:///hospitals', 'doctors')

The first argument to either function can be any valid sqlalchemy connection string. The second argument must be a database name. (Arbitrary SQL queries are not supported.)

That's all there is to it.

API

.. autofunction:: agatesql.table.from_sql

.. autofunction:: agatesql.table.from_sql_query

.. autofunction:: agatesql.table.to_sql

.. autofunction:: agatesql.table.to_sql_create_statement

.. autofunction:: agatesql.table.sql_query

Authors

Changelog

License

Indices and tables