PurpleAirWriteAPI module

Provides write access to the PurpleAir API for managing sensors, members, and configurations. Requires a write API key with appropriate permissions.

Usage Example

from purpleair_api.PurpleAirWriteAPI import PurpleAirWriteAPI

# Initialize with write key
write_api = PurpleAirWriteAPI(api_write_key="your_write_key")

# Create a new member
result = write_api.post_create_member(sensor_index=12345)

API Reference

Copyright 2024 carlkidcrypto, All rights reserved. A python3 class designed to fetch data from Purple Air’s new API. This class will handle all write requests https://api.purpleair.com/#api-welcome

class PurpleAirWriteAPI.PurpleAirWriteAPI(api_write_key=None)

Bases: object

The PurpleAirWriteAPI class designed to send valid write requests.

post_create_group_data(name)

A method to create a group for sensors.

Parameters:

name (str) – The name of the group to create.

post_create_member(group_id, sensor_index=None, sensor_id=None, owner_email=None, location_type=None)

Using a sensor_id (Parameters Option 1) The sensor_id should be exactly as printed on the label on the sensor. When no owner_email is provided, the sensor has to be marked as public.

Parameters:
  • group_id (int) – The group_id of the group to add a member to. This group must be owned by the api_key.

  • sensor_id (str) – The sensor_id of the new member sensor. This must be AS PRINTED on the sensor’s label.

Using a sensor_index (Parameters Option 2) The sensor_index can be found in lists for example from a /sensors api call. When no owner_email is provided, the sensor has to be marked as public.

Parameters:
  • group_id (int) – The group_id of the group to add a member to. This group must be owned by the api_key.

  • sensor_index (int) – The sensor_index of the new member as found in the JSON for this specific sensor.

Using sensor_id with a private sensor by specifying owner_email and optionally location_type. (Parameters Option 3) This example will produce an error if any provided value does not match the current configuration of the sensor. Note, too many incorrect attempts may disable your API key, so do not try guessing the email!!

Parameters:
  • group_id (int) – The group_id of the group to add a member to. This group must be owned by the api_key.

  • sensor_id (str) – The sensor_id of the new member sensor. This must be AS PRINTED on the sensor’s label.

  • owner_email (str) – An email address that matches the Owner email as set by previously completing the PurpleAir registration form at www.purpleair.com/register.

  • location_type ((optional) int) – The expected location_type of the new member. Possible values are: 0 = Outside or 1 = Inside. If the target member is not of this type, an error will result. NOTE: This value is required if the sensor in question is marked as ‘private’ on the registration form.

post_delete_group(group_id)

A method to delete a group for sensors.

Parameters:

group_id (int) – The group_id of the group to delete

post_delete_member(group_id, member_id)
Parameters:
  • group_id (int) – The group_id of the group in which member_id is in.

  • member_id (int) – The member_id to delete.