ALTADATA Python Library

ALTADATA Python library provides convenient access to the ALTADATA API from applications written in the Python language.

Get Data

  • YOUR_API_KEY stands for your Alta Data API key.

  • PRODUCT_CODE is a code created to use the Data Product with API.

You can find the product code in the API section of the data product page.

Get All Data

Firstly import library with the code below.

from altadata.altadata import *

You can get the entire data with the code below. get_data() returns list of dict by default.

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(PRODUCT_CODE).load()

If dataframe_functionality parameter is True get_data() returns pandas dataframe.

Note: This functionality requires pandas (v0.23 or above) to work.

client = AltaDataAPI(api_key=YOUR_API_KEY, dataframe_functionality=True)
data = client.get_data(PRODUCT_CODE).load()

Get Data with Conditions

You can get data with using various conditions.

The columns you can apply these filter operations to are limited to the filtered columns.

You can find the filtered columns in the data section of the data product page.

equal condition

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code = product_code)\
        .equal(condition_column="province_state", condition_value="Montana")\
        .load()

in condition

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
        .condition_in(condition_column="province_state", condition_value=["Montana", "Utah"])\
        .load()

not in condition

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
        .condition_not_in(condition_column="province_state", condition_value=["Montana", "Utah"])\
        .load()

sort operation

You can sort data based on a specific column and method.

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
        .sort(order_column="mortality_rate", order_method="desc")\
        .load()

select specific columns

You can get only selected columns.

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
        .select(selected_column=["reported_date", "province_state", "mortality_rate"])\
        .load()

get the specified amount of data

You can limit data.

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code, limit=20).load()

Get Data with Multiple Conditions

You can use multiple condition at same time.

product_code = "co_10_jhucs_03"

client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code, limit=100)\
            .condition_in(condition_column="province_state", condition_value=["Montana", "Utah"])\
            .sort(order_column="mortality_rate", order_method="desc")\
            .select(selected_column=["reported_date", "province_state", "mortality_rate"])\
            .load()

List Subscription

You can get your subscription info with the code below. list_subscription() returns list of dict by default.

Firstly import library with the code below.

from altadata.altadata import *
client = AltaDataAPI(YOUR_API_KEY)
product_list = client.list_subscription()

If dataframe_functionality parameter is True list_subscription() returns pandas dataframe.

Note: This functionality requires pandas (v0.23 or above) to work.

client = AltaDataAPI(api_key=YOUR_API_KEY, dataframe_functionality=True)
product_list = client.list_subscription()

Get Header

You can get your data header with the code below.

Firstly import library with the code below.

from altadata.altadata import *
client = AltaDataAPI(YOUR_API_KEY)
header = client.get_header(PRODUCT_CODE)

get_header() returns list.

altadata module

Python library for the ALTADATA API

This Python library allows a developer to build applications around the ALTADATA API without having to deal with accessing and managing the requests and responses.

class altadata.AltaDataAPI(api_key, dataframe_functionality=False)[source]

Bases: object

This is the main class of the API module. It contains all of the data API logic.

condition_in(condition_column=None, condition_value=None)[source]

‘In’ condition by given column and value list

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

condition_not_in(condition_column=None, condition_value=None)[source]

‘Not in’ condition by given column and value list

Parameters
  • condition_column (Optional[str]) – column to which the condition will be applied

  • condition_value – value to use with condition

equal(condition_column=None, condition_value=None)[source]

‘Equal’ condition by given column and value in the retrieve data process

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

get_data(product_code, limit=None)[source]

Initialize retrieve data process

Parameters
  • product_code (str) – Data product code

  • limit (Optional[int]) – Number of rows you want to retrieve

get_header(product_code)[source]

Get data header as a list

Parameters

product_code (str) – Data product code

Return type

list

greater_than(condition_column=None, condition_value=None)[source]

‘Greater than’ condition by given column and value

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

greater_than_equal(condition_column=None, condition_value=None)[source]

‘Greater than equal’ condition by given column and value

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

less_than(condition_column=None, condition_value=None)[source]

‘Less than’ condition by given column and value

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

less_than_equal(condition_column=None, condition_value=None)[source]

‘Less than equal’ condition by given column and value

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

list_subscription()[source]

List customer’s subscriptions

Returns

if dataframe_functionality parameter is False returns list of dict otherwise returns pandas dataframe.

load()[source]

Fetch data with configurations given before

Returns

if dataframe_functionality parameter is True returns pandas dataframe otherwise returns list of dict.

not_equal(condition_column=None, condition_value=None)[source]

‘Not equal’ condition by given column and value

Parameters
  • condition_column (Optional[str]) – Column to which the condition will be applied

  • condition_value – Value to use with condition

select(selected_column)[source]

Select specific columns in the retrieve data process

Parameters

selected_column (list) – List of columns to select

sort(order_column=None, order_method='asc')[source]

Sort data by given column and method in the retrieve data process

Parameters
  • order_column (Optional[str]) – Column to which the order is applied

  • order_method (str) – Sorting method. Posibble values: asc or desc

Indices and tables