PDI

Overview

PDI is a political data provider that is primarily active in California. This class allows you to interact with the PDI API .

This Parsons connector provides methods to fetch lists of acquisition types, flag IDs, questions, universes, and flags given start and end dates.

Note

Authentication

A user name, password, and API token are required to instantiate the PDI class. To obtain log in credentials, request a PDI API account from support@politicaldata.com. The administrative process usually takes a couple of hours.

Quickstart

To instantiate the PDI class, you can either store your PDI API username, password, and API token as environmental variables (PDI_USERNAME, PDI_PASSWORD, and PDI_API_TOKEN, respectively) or pass them in as arguments:

from parsons import PDI

# First approach: Use API credentials via environmental variables
pdi = PDI()

# Second approach: Pass API credentials as arguments
pdi = PDI(username='my_username', password='my_password', api_token='my_token')

# Get all contacts (flag IDs) available from PDI
pdi.get_flag_ids()

# Get all flags since the beginning of 2020
pdi.get_flags(start_date='2020-01-01')

PDI Class

class parsons.PDI(username=None, password=None, api_token=None, qa_url=False)[source]
create_flag_id(flag_id, is_default, flag_description=None, compile=None)

Save a new flag id.

Args:
flag_id: str

The flag id type. One of: “AMM”, “BNH”, “BNM”, “DEAD”, “DNC”, “DNR”, “ENDR”, “GTD”, “HH”, “L2VT”, “LBO”, “LM”, “LO”, “LS”, “LSD”, “LSR”, “MAYBE”, “MOV”, “NAH”, “NO”, “REF”, “SO”, “SS”, “SUP”, “U”, “UL2VT”, “VL2VT”, “VOL”, “VTD”.

is_default: bool

The default.

flag_description: str

(Optional) The flag id description.

compile: str

(Optional) The compile.

Returns:
str

The identifier for the new flag id.

delete_flag_id(id)

Delete a flag id.

NOTE: The function returns True (even if the id doesn’t exist) unless there is an error.

Args:
id: str

The flag id identifier.

Returns:
bool

True if the operation is successful.

get_acquisition_types(limit=None)

Get a list of Acquisition Types.

Args:
limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_flag_id(id)

Get a specified flag id.

Args:
id: str

The flag id identifier.

Returns:
dict

FlagID object.

get_flag_ids(limit=None)

Get a list of flag ids.

Args:
limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_flags(start_date, end_date, limit=None)

Get a list of flags.

Args:
start_date: str

A start date formatted like yyyy-MM-dd.

end_date: str

An end date formatted like yyyy-MM-dd.

limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_questions(limit=None)

Get a list of Questions.

Args:
limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_universes(limit=None)

Get a list of Universes.

Args:
limit: int

The number of universes to return.

Returns:
parsons.Table

A Parsons table of all the data.

update_flag_id(id, flag_id, is_default, flag_description=None, compile=None)

Update a flag id.

Args:
id: str

The flag id identifier.

flag_id: str

The flag id type. One of: “AMM”, “BNH”, “BNM”, “DEAD”, “DNC”, “DNR”, “ENDR”, “GTD”, “HH”, “L2VT”, “LBO”, “LM”, “LO”, “LS”, “LSD”, “LSR”, “MAYBE”, “MOV”, “NAH”, “NO”, “REF”, “SO”, “SS”, “SUP”, “U”, “UL2VT”, “VL2VT”, “VOL”, “VTD”.

is_default: bool

The default.

flag_description: str

(Optional) The flag id description.

compile: str

(Optional) The compile.

Returns:
str

The identifier for the udpated flag id.