{"id":8350,"library":"newrelic-api","title":"New Relic API Python Client","description":"The `newrelic-api` library provides a Python interface to interact with the New Relic API v2. It allows users to fetch application data, monitor metrics, and manage various New Relic entities programmatically. Currently at version 1.0.6, it is a community-maintained client that sees infrequent releases, primarily for maintenance and minor enhancements.","status":"maintenance","version":"1.0.6","language":"en","source_language":"en","source_url":"https://github.com/ambitioninc/newrelic-api","tags":["newrelic","monitoring","api","client","devops","observability"],"install":[{"cmd":"pip install newrelic-api","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The PyPI package name uses a hyphen, but the Python import name uses an underscore.","wrong":"from newrelic-api import NewRelicApi","symbol":"NewRelicApi","correct":"from newrelic_api import NewRelicApi"}],"quickstart":{"code":"import os\nfrom newrelic_api import NewRelicApi\n\n# Get your New Relic REST API Key (v2) from environment variable\n# Ensure it's not a License Key or Insights Key\nNEW_RELIC_API_KEY = os.environ.get('NEW_RELIC_API_KEY', '')\n\nif not NEW_RELIC_API_KEY:\n    print(\"Error: NEW_RELIC_API_KEY environment variable not set.\")\n    exit(1)\n\napi = NewRelicApi(api_key=NEW_RELIC_API_KEY)\n\ntry:\n    # Fetch all applications associated with the API key\n    applications = api.get_applications()\n    print(f\"Found {len(applications)} applications:\")\n    for app in applications:\n        print(f\"  ID: {app.get('id')}, Name: {app.get('name')}\")\n\n    # Example: Get a specific application by ID (replace with a real ID)\n    if applications:\n        first_app_id = applications[0]['id']\n        specific_app = api.get_application(first_app_id)\n        print(f\"\\nDetails for first application ({first_app_id}): {specific_app.get('name')}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart initializes the New Relic API client using an API key from an environment variable and fetches a list of applications. It demonstrates basic API interaction and error handling."},"warnings":[{"fix":"Generate or locate the correct 'New Relic REST API Key (v2)' in your New Relic account settings. Do not confuse it with other key types.","message":"The `newrelic-api` package specifically requires a 'New Relic REST API Key (v2)'. Using other New Relic keys, such as a License Key or an Insights Insert/Query Key, will result in authentication failures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement client-side rate limiting, exponential backoff, or introduce delays between API calls, especially when processing large datasets or making frequent requests.","message":"New Relic's APIs are subject to rate limiting. Making too many requests in a short period will result in `429 Too Many Requests` errors. The library does not implement automatic retry or backoff mechanisms.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `from newrelic_api import NewRelicApi` for imports, regardless of how you installed it via `pip install newrelic-api`.","message":"The Python package name for import is `newrelic_api` (with an underscore), while the PyPI installation name is `newrelic-api` (with a hyphen). This is a common source of `ImportError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change the import statement to use an underscore: `from newrelic_api import NewRelicApi`.","cause":"Attempting to import using a hyphen in the package name, which is incorrect for Python modules.","error":"ImportError: cannot import name 'NewRelicApi' from 'newrelic-api'"},{"fix":"Verify your API key for typos and ensure it is the correct type of New Relic REST API Key (v2). Regenerate it in New Relic if unsure.","cause":"The provided API key is either incorrect, malformed, or is not the specific 'New Relic REST API Key (v2)' required by the library.","error":"newrelic_api.exceptions.NewRelicApiException: Invalid API key"},{"fix":"Reduce the frequency of your API requests. Implement delays between calls or an exponential backoff strategy for retries.","cause":"You have exceeded the New Relic API rate limits for your account or endpoint.","error":"requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url:"}]}