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 using sensor_index
result = write_api.post_create_member(group_id=1234, sensor_index=12345)
API Reference¶
Copyright 2024 carlkidcrypto, All rights reserved. A python3 class designed to send write requests to Purple Air’s API. This class will handle all write requests https://api.purpleair.com/#api-welcome
- class PurpleAirWriteAPI.PurpleAirWriteAPI(api_write_key=None)¶
Bases:
objectThe 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.
- Return dict | None:
A dictionary containing the created group data.
- post_create_member(group_id, sensor_index=None, sensor_id=None, owner_email=None, location_type=None)¶
Add a sensor as a member of a group. The group must be owned by the api_key used. Supports three parameter combinations:
Option 1 — public sensor by
sensor_id(as printed on the label): providegroup_idandsensor_id.Option 2 — sensor by
sensor_index(from the API): providegroup_idandsensor_index.Option 3 — private sensor by
sensor_idwith owner verification: providegroup_id,sensor_id,owner_email, and optionallylocation_type.
- 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.
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 (int) – (optional) The expected location_type of the new member. Possible values are: 0 = Outside or 1 = Inside. Required when the target sensor is marked as ‘private’.
- Return dict | None:
A dictionary containing the created member data.
- Raises:
PurpleAirAPIError – If an invalid combination of parameters is provided or the API request fails.
- 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
- Return dict | None:
A dictionary containing the deletion response.
- post_delete_member(group_id, member_id)¶
Delete a member from a group.
- Parameters:
group_id (int) – The group_id of the group in which member_id is in.
member_id (int) – The member_id to delete.
- Return dict | None:
A dictionary containing the deletion response.