Install & Compatibility
Where this runs
tested against v2.1.5 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.486s · 22.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.4s · import 0.452s · 23MB
24MB installed
● package 24MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Configuration
✓ from opsgenie_sdk import Configuration
ApiClient
✓ from opsgenie_sdk import ApiClient
AlertApi
✓ from opsgenie_sdk import AlertApi
CreateAlertRequest
✓ from opsgenie_sdk import CreateAlertRequest
IncidentApi
✓ from opsgenie_sdk import IncidentApi
CreateIncidentRequest
✓ from opsgenie_sdk import CreateIncidentRequest
AlertResponder
✓ from opsgenie_sdk import AlertResponder
ApiException
✓ from opsgenie_sdk.rest import ApiException
✗ from opsgenie_sdk import ApiException
ApiException is located within the opsgenie_sdk.rest submodule.
This quickstart demonstrates how to initialize the Opsgenie SDK, configure API key authentication, and create a basic alert. Ensure you have an Opsgenie API key set as an environment variable `OG_API_KEY` or replace 'YOUR_API_KEY' directly in the code.
import opsgenie_sdk
import os
configuration = opsgenie_sdk.Configuration()
# Configure API key authorization: OpsgenieAPIKey
# Replace 'YOUR_API_KEY' or set OG_API_KEY environment variable
configuration.api_key['Authorization'] = os.environ.get('OG_API_KEY', 'YOUR_API_KEY')
configuration.api_key_prefix['Authorization'] = 'GenieKey'
# create an instance of the API client
api_client = opsgenie_sdk.ApiClient(configuration)
alert_api = opsgenie_sdk.AlertApi(api_client)
# Create an alert request body
body = opsgenie_sdk.CreateAlertRequest(
message='Test Alert from Python SDK Checklist.day',
description='This is a test alert created via the Python SDK quickstart.',
priority='P3',
alias='checklist_sdk_test_alert',
entity='Test Service',
tags=['checklist', 'sdk'],
details={'source': 'python-sdk-quickstart'},
source='Python SDK Quickstart'
)
try:
api_response = alert_api.create_alert(body=body)
print('Alert created successfully:')
print(f' ID: {api_response.alert.id}')
print(f' Alias: {api_response.alert.alias}')
print(f' Status: {api_response.status}')
except opsgenie_sdk.rest.ApiException as e:
print(f"Exception when calling AlertApi->create_alert: {e}")
Debug
Known issues
breakingThe SDK underwent a complete re-implementation with version 2.0.1. All imports, class names, and API interaction patterns changed significantly from the 0.x.x series.fixRewrite integration code following the new API documentation (e.g., https://docs.opsgenie.com/docs/opsgenie-python-api-v2-1) and upgrade to version 2.0.1 or newer.
affects: All versions prior to 2.0.1
gotchaOlder versions of the SDK (prior to 2.1.5) may depend on vulnerable versions of `urllib3` (below 1.26.5), which is susceptible to Denial Of Service (DoS) issues. The SDK itself fixed this by updating its `urllib3` dependency.fixUpgrade to opsgenie-sdk version 2.1.5 or newer to ensure you are using a patched `urllib3` dependency.
affects: < 2.1.5
gotchaWhen working with the Incident API in early 2.x versions (e.g., 2.0.x), there were inconsistencies in field names. For example, `teamId` was required to be `ownerTeam`, and `details` should be `extraProperties` in some contexts.fixRefer to the official documentation or API schema for exact field names in specific API calls, especially for the Incident API. Newer patch releases might have addressed some of these inconsistencies.
affects: 2.0.x
gotchaThe `numpy` dependency was removed in version 2.1.1. While this is generally a positive change for reducing dependencies, users upgrading from earlier `2.x.x` versions might notice `numpy` is no longer installed automatically.fixNo action required unless your application explicitly relied on `numpy` being installed as a transitive dependency of `opsgenie-sdk`. Ensure your project's `requirements.txt` explicitly lists any direct dependencies.
affects: < 2.1.1
Errors
Common errors & fixes
opsgenie_sdk.rest.ApiException: (401) Reason: Unauthorized: apiKey is invalid or integration is disabled
The provided API key is either incorrect, lacks the necessary permissions, or is sourced from an 'API key management' section rather than an 'API Integration'. For European accounts, an incorrect host configuration can also lead to this error.
fixEnsure you are using an API key generated from an 'API Integration' within Opsgenie (not a personal API key) and verify it has the required 'Create and Update' permissions. If your Opsgenie account is on the EU instance, explicitly set `configuration.host = 'https://api.eu.opsgenie.com'`.
ModuleNotFoundError: No module named 'opsgenie_sdk'
The `opsgenie-sdk` package is not installed in the current Python environment or the import statement uses an incorrect module name.
fixInstall the package using pip: `pip install opsgenie-sdk`. Ensure your virtual environment is activated if applicable, and verify import statements match the package structure, e.g., `import opsgenie_sdk`.
AttributeError: 'Configuration' object has no attribute 'apikey'
The code is attempting to access an outdated attribute named `apikey` on the `Configuration` object. The correct attribute name in recent SDK versions is `api_key`.
fixUpdate your code to use `configuration.api_key['Authorization']` instead of `configuration.apikey`. For example: `configuration = opsgenie_sdk.Configuration(); configuration.api_key['Authorization'] = 'YOUR_API_KEY'`.
Upgrade
Version history
2.1.5latest on PyPI · released Aug 2, 2021
Audit
Dependencies
urllib3requiredHTTP client for API requests; critical for network communication and has had security updates.