Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.634s · 23.1MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.0s · import 0.581s · 24MB
21MB installed
● package 21MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pypd
✓ import pypd
The primary import for accessing the client and its methods.
This quickstart demonstrates how to initialize the pypd client using environment variables for authentication and then fetch a PagerDuty incident by its ID. It highlights the recommended practice of configuring API keys securely via environment variables.
import pypd
import os
# Configure API key either directly or from environment variables
# It's recommended to use environment variables for security.
# export PD_API_KEY='YOUR_PAGERDUTY_API_KEY'
# export PD_API_URL='https://api.pagerduty.com'
# Option 1: Set directly (less secure for production)
# pypd.api_key = os.environ.get('PD_API_KEY', 'YOUR_PAGERDUTY_API_KEY')
# pypd.api_url = os.environ.get('PD_API_URL', 'https://api.pagerduty.com')
# Option 2: Initialize from environment variables (recommended)
pypd.from_env()
# Example: Fetch an incident by ID
try:
# Replace 'YOUR_INCIDENT_ID' with an actual incident ID
incident_id = os.environ.get('PAGERDUTY_TEST_INCIDENT_ID', 'YOUR_INCIDENT_ID')
if incident_id == 'YOUR_INCIDENT_ID':
print("Please set PAGERDUTY_TEST_INCIDENT_ID environment variable or replace 'YOUR_INCIDENT_ID' in code.")
else:
incident = pypd.Incident.fetch(id=incident_id)
print(f"Fetched incident: {incident['title']} (ID: {incident['id']})")
# Example: Print a few details
print(f"Status: {incident['status']}")
print(f"Urgency: {incident['urgency']}")
except Exception as e:
print(f"Error fetching incident: {e}")
print("Ensure PD_API_KEY and PD_API_URL are set correctly and the incident ID is valid.")
Upgrade
Version history
1.1.0latest on PyPI · released Mar 26, 2018
Audit
Dependencies
requestsrequiredUsed as the underlying HTTP client library for making API calls.