{"id":5986,"library":"launchdarkly-api","title":"LaunchDarkly API Client for Python","description":"The `launchdarkly-api` library is an auto-generated Python client for the LaunchDarkly REST API. It enables programmatic interaction for custom integrations, data export, or automating feature flag workflows. It is currently at version 22.0.0 and undergoes frequent major version releases to align with updates to the underlying REST API, often introducing breaking changes.","status":"active","version":"22.0.0","language":"en","source_language":"en","source_url":"https://github.com/launchdarkly/api-client-python","tags":["feature flags","API client","LaunchDarkly","automation"],"install":[{"cmd":"pip install launchdarkly-api","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The Configuration class is part of the top-level `launchdarkly_api` module.","symbol":"Configuration","correct":"import launchdarkly_api\nconfig = launchdarkly_api.Configuration(...)"},{"note":"The main API client is accessed directly from the `launchdarkly_api` module.","symbol":"ApiClient","correct":"import launchdarkly_api\napi_client = launchdarkly_api.ApiClient(config)"},{"note":"Specific API groups (e.g., Projects, Flags, Users) are classes within the `launchdarkly_api` module, initialized with an `ApiClient` instance.","symbol":"ProjectsApi","correct":"import launchdarkly_api\nprojects_api = launchdarkly_api.ProjectsApi(api_client)"},{"note":"Exceptions, such as API errors, are typically found in the `launchdarkly_api.rest` submodule.","symbol":"ApiException","correct":"from launchdarkly_api.rest import ApiException"}],"quickstart":{"code":"import os\nimport launchdarkly_api\nfrom launchdarkly_api.rest import ApiException\n\n# Configure API key authorization: ApiKey\nconfiguration = launchdarkly_api.Configuration(\n    host=\"https://app.launchdarkly.com\"\n)\n# Your LaunchDarkly API Key (NOT an SDK key)\nconfiguration.api_key['ApiKey'] = os.environ.get('LAUNCHDARKLY_API_KEY', '')\n\n# Create an instance of the API client\ntry:\n    with launchdarkly_api.ApiClient(configuration) as api_client:\n        # Create an instance of the Projects API class\n        api_instance = launchdarkly_api.ProjectsApi(api_client)\n\n        try:\n            # List all projects\n            projects = api_instance.get_projects()\n            if projects and projects.items:\n                print(f\"Successfully retrieved {len(projects.items)} project(s):\")\n                for project in projects.items:\n                    print(f\"- {project.name} (Key: {project.key})\")\n            else:\n                print(\"No projects found or API key may be invalid/lack permissions.\")\n        except ApiException as e:\n            print(f\"Exception when calling ProjectsApi->get_projects: {e}\")\n            if e.status == 401:\n                print(\"Error 401: Unauthorized. Check your LAUNCHDARKLY_API_KEY and its permissions.\")\n            elif e.status == 403:\n                print(\"Error 403: Forbidden. Your API key might not have permissions to list projects.\")\nexcept ValueError as e:\n    print(f\"Error initializing API client: {e}. Ensure LAUNCHDARKLY_API_KEY is set.\")","lang":"python","description":"This quickstart demonstrates how to initialize the LaunchDarkly API client, authenticate using an API key from an environment variable (`LAUNCHDARKLY_API_KEY`), and make a simple call to list all projects in your LaunchDarkly organization. It includes basic error handling for common API issues."},"warnings":[{"fix":"Pin your `launchdarkly-api` dependency version in your `requirements.txt` or `pyproject.toml` and review the changelog when upgrading.","message":"The `launchdarkly-api` client library undergoes frequent major version increments, typically indicating breaking changes in the underlying LaunchDarkly REST API. Always pin your dependency version (`launchdarkly-api==X.Y.Z`) and thoroughly review the changelog for migration instructions between versions.","severity":"breaking","affected_versions":"All versions with major increments (e.g., v17.x.x to v18.x.x, v21.x.x to v22.x.x)"},{"fix":"For feature flag evaluations, install and use `launchdarkly-server-sdk` (or other platform-specific SDKs). For REST API interactions, use `launchdarkly-api`.","message":"This `launchdarkly-api` client library is designed for programmatic interaction with the LaunchDarkly REST API (e.g., automation, data export, managing flag configurations). It is *not* for evaluating feature flags within your application. For feature flag evaluation, use the appropriate LaunchDarkly SDK (e.g., `launchdarkly-server-sdk` for Python applications).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Generate an API access token from your LaunchDarkly account's 'Authorization' settings and ensure it has the necessary permissions for the API calls you intend to make.","message":"Only LaunchDarkly API access tokens (personal or service tokens) are valid for authentication with this client. Using SDK keys, mobile keys, or client-side IDs (which are designed for SDKs) will result in authentication failures when using the `launchdarkly-api` client.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the release notes and API documentation for each major version upgrade to adapt your code to changes in data models, request/response structures, and available parameters.","message":"Frequent API updates lead to changes in data models and endpoint behaviors. For example, in v19.0.0, the `status` field in `IterationRep` objects changed from a string to an enum, and in v22.0.0, the `guardrail` type was removed for `POST /api/v2/projects/{projectKey}/metric-groups`. Code relying on specific string values or previously available fields/types may break.","severity":"breaking","affected_versions":"v19.0.0+, v22.0.0+ (and likely other versions due to frequent changes)"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}