{"id":14832,"library":"pypd","title":"PagerDuty Python API Client","description":"pypd is a community-supported Python client for PagerDuty's v2 API, allowing developers to interact with PagerDuty services. It provides an interface for common API operations. The latest version is 1.1.0, released in March 2018, indicating a low release cadence.","status":"maintenance","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/PagerDuty/pagerduty-api-python-client","tags":["PagerDuty","API Client","DevOps","Incident Management","Alerting"],"install":[{"cmd":"pip install pypd","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used as the underlying HTTP client library for making API calls.","package":"requests","optional":false}],"imports":[{"note":"The primary import for accessing the client and its methods.","symbol":"pypd","correct":"import pypd"}],"quickstart":{"code":"import pypd\nimport os\n\n# Configure API key either directly or from environment variables\n# It's recommended to use environment variables for security.\n# export PD_API_KEY='YOUR_PAGERDUTY_API_KEY'\n# export PD_API_URL='https://api.pagerduty.com'\n\n# Option 1: Set directly (less secure for production)\n# pypd.api_key = os.environ.get('PD_API_KEY', 'YOUR_PAGERDUTY_API_KEY')\n# pypd.api_url = os.environ.get('PD_API_URL', 'https://api.pagerduty.com')\n\n# Option 2: Initialize from environment variables (recommended)\npypd.from_env()\n\n# Example: Fetch an incident by ID\ntry:\n    # Replace 'YOUR_INCIDENT_ID' with an actual incident ID\n    incident_id = os.environ.get('PAGERDUTY_TEST_INCIDENT_ID', 'YOUR_INCIDENT_ID')\n    if incident_id == 'YOUR_INCIDENT_ID':\n        print(\"Please set PAGERDUTY_TEST_INCIDENT_ID environment variable or replace 'YOUR_INCIDENT_ID' in code.\")\n    else:\n        incident = pypd.Incident.fetch(id=incident_id)\n        print(f\"Fetched incident: {incident['title']} (ID: {incident['id']})\")\n        # Example: Print a few details\n        print(f\"Status: {incident['status']}\")\n        print(f\"Urgency: {incident['urgency']}\")\nexcept Exception as e:\n    print(f\"Error fetching incident: {e}\")\n    print(\"Ensure PD_API_KEY and PD_API_URL are set correctly and the incident ID is valid.\")","lang":"python","description":"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."},"warnings":[{"fix":"Consider migrating to `python-pagerduty` for new development or if active maintenance and new features are required. The migration path from `pypd` may require code changes due to different API client design.","message":"The 'pypd' library is community-supported and has not been updated since March 2018. For new projects, PagerDuty itself recommends using the more actively maintained `python-pagerduty` library, which is a successor to other PagerDuty Python clients like `pdpyras`.","severity":"breaking","affected_versions":"<=1.1.0"},{"fix":"Store `PD_API_KEY` and `PD_API_URL` as environment variables and use `pypd.from_env()` for initialization. Never hardcode sensitive API keys directly in your source code.","message":"Authentication requires a PagerDuty API token (v2) and potentially an API URL. It is crucial to handle these credentials securely, ideally through environment variables (e.g., `PD_API_KEY`, `PD_API_URL`) rather than hardcoding them.","severity":"gotcha","affected_versions":"All"},{"fix":"Double-check `pip install pypd` and import statements (`import pypd`) to confirm you are using the PagerDuty client, and not inadvertently pulling in a PDF library.","message":"The library name 'pypd' can easily be confused with 'pypdf' or 'PyPDF2', which are popular Python libraries for PDF file manipulation. Ensure you are installing and importing the correct library for PagerDuty API interactions.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[],"ecosystem":"pypi"}