Databases

Overview

Parsons offers support for a variety of popular SQL database dialects. The functionality is focused on the ability to query and upload data to SQL databases. Each database class also includes the ability to infer datatypes and data schemas from a Parsons table and automatically create new tables.

Similar to other classes in Parsons, the query methods for databases all return Parsons Table, which allow them to be easily converted to other data types.

There is also support for synchronization of tables between databases as part of the Database Sync framework.

Google BigQuery

See Google for documentation.

MySQL

MySQL is the world’s most popular open source database. The Parsons class leverages on the MySQLdb1 python package.

Quick Start

Authentication

from parsons import MySQL

# Instantiate MySQL from environmental variables
mysql = MySQL()

# Instantiate MySQL from passed variables
mysql = MySQL(username='me', password='secret', host='mydb.com', db='dev', port=3306)

Quick Start

# Query database
tbl = mysql.query('select * from my_schema.secret_sauce')

# Copy data to database
tbl = Table.from_csv('my_file.csv') # Load from a CSV or other source.
mysql.copy(tbl, 'my_schema.winning_formula')

Postgres

Postgres is popular open source SQL database dialect. The Parsons class leverages the psycopg2 python package.

Quick Start

Authentication

from parsons import Postgres

# Instantiate Postgres from environmental variables
pg = Postgres()

# Instantiate Postgres from passed variables
pg = Postgres(username='me', password='secret', host='mydb.com', db='dev', port=3306)

# Instantiate Postgres from a ~/.pgpass file
pg = Postgres()

Quick Start

# Query database
tbl = pg.query('select * from my_schema.secret_sauce')

# Copy data to database
tbl = Table.from_csv('my_file.csv') # Load from a CSV or other source.
pg.copy(tbl, 'my_schema.winning_formula')

Redshift

See Redshift for documentation.

Sqlite

SQLite is a performant flat-file database that’s often touted as the “zero-config” database. The Parsons class uses the python3 built-in sqlite3 connector.

Quick Start

Authentication

from parsons import Sqlite

# Instantiate Sqlite from passed variables
sqlite = Sqlite(db_path='local.db')

Quick Start

# Query database
tbl = sqlite.query('select * from my_table')

# Copy data to database
tbl = Table.from_csv('my_file.csv') # Load from a CSV or other source.
sqlite.copy(tbl, 'my_destination_table')