Registry / communication / pygerduty

pygerduty

JSON →
library0.38.3pypypi✓ verified 24d ago

Pygerduty is a Python client library for interacting with PagerDuty's REST API and Events API. Originally designed for PagerDuty API v1, it includes some updates for v2 compatibility in a separate module. The latest version is 0.38.3, released in April 2020.

pip install pygerduty
INSTALL
IMPORT
SIG · PYGERDUTY
P
pygerduty
communicationpythonv0.38.3
Install
1.6s avg
Import
21ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.38.3 · 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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.022s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.020s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PagerDuty
import pygerduty pager = pygerduty.PagerDuty("your_subdomain", "your_api_key")
from pygerduty import PagerDuty
The PagerDuty class is typically accessed via the top-level package namespace after a simple import.
PagerDuty (V2 API)
import pygerduty.v2 pager_v2 = pygerduty.v2.PagerDuty("your_subdomain", "your_api_key")
For PagerDuty API v2 interactions, the client is exposed through the `v2` submodule.

This quickstart demonstrates how to instantiate a `pygerduty` client for the PagerDuty v1 API (default behavior) and fetch a list of schedules. It uses environment variables for authentication credentials.

import os import pygerduty # Ensure your PagerDuty subdomain and API key are set as environment variables PD_SUBDOMAIN = os.environ.get('PD_SUBDOMAIN', 'your_subdomain_here') PD_API_KEY = os.environ.get('PD_API_KEY', 'YOUR_API_KEY_HERE') if not PD_SUBDOMAIN or not PD_API_KEY: print("Please set PD_SUBDOMAIN and PD_API_KEY environment variables.") else: try: # Instantiate a PagerDuty client (targets v1 API by default) pager = pygerduty.PagerDuty(PD_SUBDOMAIN, PD_API_KEY) # List schedules (example using v1 API pattern) print(f"Fetching schedules for subdomain: {PD_SUBDOMAIN}") for schedule in pager.schedules.list(): print(f" - ID: {schedule.id}, Name: {schedule.name}") # For PagerDuty API v2 interactions (if implemented in your version/fork) # import pygerduty.v2 # pager_v2 = pygerduty.v2.PagerDuty(PD_SUBDOMAIN, PD_API_KEY) # print("\nFetching users via v2 API (if supported by your client config):") # for user in pager_v2.users.list(): # print(f" - ID: {user.id}, Name: {user.name}, Email: {user.email}") except Exception as e: print(f"An error occurred: {e}") print("Please check your PagerDuty subdomain, API key, and network connectivity.")
pygerduty --version
Debug
Known issues
breakingThe PagerDuty API v1, which `pygerduty` primarily targets, was officially deprecated by PagerDuty in July 2017 and is no longer supported. The library's `v2` submodule (introduced later) might provide limited v2 compatibility, but the library is largely unmaintained for modern PagerDuty API usage.
fix
Consider migrating to an actively maintained PagerDuty Python client that fully supports API v2, such as `python-pagerduty` (official PagerDuty library) or `pypd`.
affects: <= 0.38.3
deprecatedThe library lacks recent maintenance. The last PyPI release was in April 2020, and the GitHub repository shows no significant activity since then. It is effectively unmaintained.
fix
No direct fix for this library. Users should transition to alternative, actively maintained PagerDuty Python clients for new development and ongoing support.
affects: All versions
breakingPython 2 support is no longer relevant as Python 2 reached end-of-life. While older versions of `pygerduty` claimed Python 2.5+ compatibility, modern Python applications should use Python 3.6+.
fix
Ensure your environment uses Python 3.6 or newer. If you must interact with legacy PagerDuty API v1 endpoints and this specific library, be aware of potential compatibility issues with very recent Python 3 versions due to lack of updates.
affects: <= 0.38.3 (regarding Python 2 compatibility)
gotchaAuthentication for the PagerDuty API requires both a subdomain (e.g., 'yourcompany' from 'yourcompany.pagerduty.com') and an API key. For PagerDuty API v2, the `From` header (an email address of a PagerDuty user) is often required for certain actions if an account-level API key is used.
fix
Always provide the correct subdomain and API key. When using PagerDuty API v2 (if using `pygerduty.v2`), ensure you understand the requirements for the `From` header and API key types as per PagerDuty's official API documentation.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pygerduty.v2'
The Python interpreter cannot find the 'v2' submodule within 'pygerduty', likely because pygerduty is not installed, or the import statement is incorrect when trying to access PagerDuty API v2 features.
fix
Ensure `pygerduty` is installed (`pip install pygerduty`) and that you are importing the `v2` submodule correctly, typically as `import pygerduty.v2` or `from pygerduty import v2`.
AttributeError: 'PagerDuty' object has no attribute 'incidents'
This typically occurs when attempting to access PagerDuty API v2 resources (like 'incidents') using a `pygerduty` client instantiated for PagerDuty API v1. The `pygerduty.PagerDuty` class in the main `__init__.py` file is for v1, while v2 API interactions require `pygerduty.v2.PagerDuty`.
fix
To interact with PagerDuty API v2 resources, import and instantiate the `v2` client explicitly. For example: `import pygerduty.v2; pager = pygerduty.v2.PagerDuty(api_key='YOUR_API_KEY')` instead of `import pygerduty; pager = pygerduty.PagerDuty('subdomain', 'api_key')`.
pagerduty.HttpError: 401 Unauthorized
Your PagerDuty API token is invalid, expired, or has insufficient permissions for the requested action, or the PagerDuty API host/region is incorrectly configured.
fix
Verify your PagerDuty API key (token) is correct, active, and has the necessary permissions for the operation. If your PagerDuty account is in the EU or another non-US region, ensure you set the `base_url` parameter during client instantiation (e.g., `pagerduty.v2.PagerDuty(api_key='YOUR_API_KEY', base_url='https://api.eu.pagerduty.com')`).
pagerduty.HttpError: 400 Bad Request (related to 'From' header)
When using an account-level PagerDuty API key for certain actions (e.g., resolving or acknowledging incidents) in PagerDuty API v2, the API requires a 'From' header containing the email address of a valid PagerDuty user to attribute the action. This error indicates that this header was missing or the email address was invalid.
fix
Provide the `default_from` parameter (the email address of a PagerDuty user) when instantiating the `pygerduty.v2.PagerDuty` client: `pager = pygerduty.v2.PagerDuty(api_key='YOUR_API_KEY', default_from='user@example.com')`.
Upgrade
Version history
0.38.3latest on PyPI · released Apr 22, 2020
Audit
Dependencies
requestsrequiredHTTP client for API communication.
simplejsonoptionalRequired for Python versions < 2.6 (e.g., Python 2.5).
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
pygerduty — pip install pygerduty · libregistry