SDKs overview
PagerDuty provides a suite of Software Development Kits (SDKs) designed to simplify interactions with its REST API. These SDKs abstract away the complexities of HTTP requests, JSON parsing, and authentication, allowing developers to focus on integrating PagerDuty's incident management and on-call automation capabilities into their applications and workflows. The available SDKs support several popular programming languages, offering idiomatic interfaces for common PagerDuty operations like creating incidents, managing users, and configuring services.
The PagerDuty API itself adheres to RESTful principles, using standard HTTP methods for operations and returning JSON payloads. This design choice makes direct API interaction feasible for languages without official SDKs or for highly customized integration scenarios. For instance, a developer could use curl or a generic HTTP client library to interact with the PagerDuty API, as demonstrated in PagerDuty's guide to using the REST API. However, SDKs generally offer a more streamlined and less error-prone development experience by handling common patterns and edge cases.
Authentication for all PagerDuty API interactions, whether via SDK or direct API calls, relies on API tokens. These tokens are generated within the PagerDuty web application and must be included in the Authorization header of API requests, typically using a Token token=YOUR_API_TOKEN scheme. This method aligns with common practices for API security and access control, as detailed in OAuth 2.0 Bearer Token usage principles.
Official SDKs by language
PagerDuty maintains official SDKs for several programming languages, developed and supported by the PagerDuty engineering team. These SDKs are designed to provide a consistent and reliable interface for developers, ensuring compatibility with the latest API versions and features. Each SDK aims to reflect the native conventions and best practices of its respective language, making integration more intuitive for developers familiar with that ecosystem.
The following table outlines the officially supported SDKs, their typical package names, installation commands, and general maturity status:
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| Python | pagerdutyevents and pagerduty |
pip install pagerdutyevents pagerduty |
Stable, actively maintained |
| Ruby | pagerduty |
gem install pagerduty |
Stable, actively maintained |
| Go | go-pagerduty |
go get github.com/PagerDuty/go-pagerduty/pagerduty |
Stable, actively maintained |
| Java | pagerduty-api-client |
Maven: Add dependency to pom.xml; Gradle: Add dependency to build.gradle |
Stable, actively maintained |
| Node.js | pdjs |
npm install pdjs |
Stable, actively maintained |
For detailed documentation on each SDK, including specific class methods and example usage, developers should refer to the official PagerDuty SDKs and Libraries overview.
Installation
Installing PagerDuty SDKs typically follows the standard package management practices for each respective language. The process is designed to be straightforward, allowing developers to quickly integrate the libraries into their projects.
Python
For Python, the pagerdutyevents library is used for sending events to the PagerDuty Events API, while the pagerduty library provides access to the REST API. Both can be installed using pip:
pip install pagerdutyevents pagerduty
This command downloads and installs the necessary packages from the Python Package Index (PyPI).
Ruby
Ruby developers can install the official PagerDuty gem using Bundler or directly with gem install:
gem install pagerduty
For projects using Bundler, add gem 'pagerduty' to your Gemfile and run bundle install.
Go
Go modules are used to manage dependencies. The PagerDuty Go SDK can be added to your project with go get:
go get github.com/PagerDuty/go-pagerduty/pagerduty
This command will fetch the latest version and add it to your go.mod file.
Java
For Java projects, the PagerDuty API client is available via Maven Central. If you're using Maven, add the following dependency to your pom.xml:
<dependency>
<groupId>com.pagerduty</groupId>
<artifactId>pagerduty-api-client</artifactId>
<version>YOUR_VERSION_HERE</version>
</dependency>
Replace YOUR_VERSION_HERE with the latest stable version number. For Gradle users, the dependency would be added to build.gradle.
Node.js
The Node.js SDK, pdjs, is available on npm and can be installed using npm or yarn:
npm install pdjs
# or
yarn add pdjs
This command adds the package to your project's node_modules directory and updates package.json.
Quickstart example
This Python example demonstrates how to use the pagerduty SDK to create a new incident. This quickstart assumes you have installed the pagerduty library and have a PagerDuty API key (token) with appropriate permissions.
import os
from pagerduty.api import PagerDutyAPI
# --- Configuration ---
# It's recommended to store your API token securely, e.g., as an environment variable.
API_TOKEN = os.environ.get("PAGERDUTY_API_TOKEN")
FROM_EMAIL = "[email protected]" # Email of a user in your PagerDuty account
SERVICE_ID = "PXXXXXX" # The ID of the PagerDuty service to trigger the incident on
if not API_TOKEN or not SERVICE_ID:
print("Error: PAGERDUTY_API_TOKEN and SERVICE_ID must be set as environment variables.")
exit(1)
# Initialize the PagerDuty API client
pd_api = PagerDutyAPI(API_TOKEN, from_email=FROM_EMAIL)
try:
# Create an incident
incident_data = pd_api.incidents.create(
summary="High CPU Usage Detected on Production Server",
type="incident",
service_id=SERVICE_ID,
severity="critical",
details="CPU spiked above 90% for more than 5 minutes on app-server-01.",
# Optionally, add a custom payload or client information
client="Monitoring System X",
client_url="https://monitoring.example.com/alerts/12345"
)
print(f"Incident created successfully!")
print(f"Incident ID: {incident_data['incident']['id']}")
print(f"Incident URL: {incident_data['incident']['html_url']}")
except Exception as e:
print(f"Failed to create incident: {e}")
To run this example:
- Replace
[email protected]with an email associated with a PagerDuty user. - Replace
PXXXXXXwith the actual Service ID from your PagerDuty account. - Set your PagerDuty API token as an environment variable named
PAGERDUTY_API_TOKEN.
This code snippet initializes the API client and then calls the incidents.create method with the required parameters to generate a new incident. The response contains details about the newly created incident, including its unique ID and a direct link to the incident in the PagerDuty web application. Further examples for managing users, services, schedules, and more can be found in the PagerDuty API documentation.
Community libraries
While PagerDuty provides official SDKs for several major languages, the open-source nature of API development often leads to community-contributed libraries and tools. These libraries can offer support for additional languages, alternative approaches to API interaction, or specialized functionalities not present in the official SDKs. Community contributions are a common aspect of many API ecosystems, including those of platforms like AWS with its diverse community SDKs for Go.
Developers seeking PagerDuty integrations in languages not officially supported, or looking for specific features, may find community projects on platforms like GitHub. These can range from simple wrappers to comprehensive client libraries. When considering community-contdeveloped libraries, it is advisable to evaluate their:
- Maintenance status: Check the last commit date, open issues, and pull request activity.
- Documentation: Assess the clarity and completeness of the project's documentation.
- Community support: Look for active contributors and responsive issue management.
- Security: Review the code if possible, especially for projects handling sensitive API tokens.
Although PagerDuty does not officially endorse or support community-developed libraries, they can be valuable resources for extending the platform's reach. Developers are encouraged to explore community repositories or, if a suitable library doesn't exist, consider contributing their own, following the guidance in the PagerDuty guide to contributing to libraries.