Civis

Overview

The Civis Platform is a cloud-based data science platform. This Parsons connector utilizes the Civis API Python client to interact with the Civis Platform. It supports executing Civis SQL queries and writing Parsons Tables to a Civis Redshift cluster.

Note

Authentication

The CivisClient class requires your Redshift database ID or name, and an API Key. To obtain an API Key, log in to Civis and follow the instructions for Creating an API Key.

Quickstart

To instantiate the CivisClient class, you can either store your database identifier and API Key as environmental variables (CIVIS_DATABASE and CIVIS_API_KEY) or pass them as keyword arguments.

API

class parsons.CivisClient(db=None, api_key=None, **kwargs)[source]

Instantiate the Civis class.

Args:
db: str or int

The Civis Redshift database. Can be a database id or the name of the database.

api_key: str

The Civis api key.

**kwargs: args

Option settings for the client that are described in the documentation.

Returns:

Civis class

client

The Civis API client. Utilize this attribute to access to lower level and more advanced methods which might not be surfaced in Parsons. A list of the methods can be found by reading the Civis API client documentation.

query(sql, preview_rows=10, polling_interval=None, hidden=True, wait=True)[source]

Execute a SQL statement as a Civis query.

Run a query that may return no results or where only a small preview is required. To execute a query that returns a large number of rows, see read_civis_sql().

Args
sql: str

The SQL statement to execute.

preview_rows: int, optional

The maximum number of rows to return. No more than 100 rows can be returned at once.

polling_interval: int or float, optional

Number of seconds to wait between checks for query completion.

hidden: bool, optional

If True (the default), this job will not appear in the Civis UI.

wait: boolean

If True, will wait for query to finish executing before exiting the method. If False, returns the future object.

Returns
Parsons Table or civis.CivisFuture

See Parsons Table for output options.

table_import(table_obj, table, max_errors=None, existing_table_rows='fail', diststyle=None, distkey=None, sortkey1=None, sortkey2=None, wait=True, **civisargs)[source]

Write the table to a Civis Redshift cluster. Additional key word arguments can passed to civis.io.dataframe_to_civis() # noqa: E501

Args
table_obj: obj

A Parsons Table object

table: str

The schema and table you want to upload to. E.g., ‘scratch.table’. Schemas or tablenames with periods must be double quoted, e.g. ‘scratch.”my.table”’.

api_key: str

Your Civis API key. If not given, the CIVIS_API_KEY environment variable will be used.

max_errors: int

The maximum number of rows with errors to remove from the import before failing.

existing_table_rows: str

The behaviour if a table with the requested name already exists. One of ‘fail’, ‘truncate’, ‘append’ or ‘drop’. Defaults to ‘fail’.

diststyle: str

The distribution style for the table. One of ‘even’, ‘all’ or ‘key’.

distkey: str

The column to use as the distkey for the table.

sortkey1: str

The column to use as the sortkey for the table.

sortkey2: str

The second column in a compound sortkey for the table.

wait: boolean

Wait for write job to complete before exiting method. If False, returns the future object.

Returns

None or civis.CivisFuture