LaunchDarkly API Client for Python

22.0.0 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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.

import os
import launchdarkly_api
from launchdarkly_api.rest import ApiException

# Configure API key authorization: ApiKey
configuration = launchdarkly_api.Configuration(
    host="https://app.launchdarkly.com"
)
# Your LaunchDarkly API Key (NOT an SDK key)
configuration.api_key['ApiKey'] = os.environ.get('LAUNCHDARKLY_API_KEY', '')

# Create an instance of the API client
try:
    with launchdarkly_api.ApiClient(configuration) as api_client:
        # Create an instance of the Projects API class
        api_instance = launchdarkly_api.ProjectsApi(api_client)

        try:
            # List all projects
            projects = api_instance.get_projects()
            if projects and projects.items:
                print(f"Successfully retrieved {len(projects.items)} project(s):")
                for project in projects.items:
                    print(f"- {project.name} (Key: {project.key})")
            else:
                print("No projects found or API key may be invalid/lack permissions.")
        except ApiException as e:
            print(f"Exception when calling ProjectsApi->get_projects: {e}")
            if e.status == 401:
                print("Error 401: Unauthorized. Check your LAUNCHDARKLY_API_KEY and its permissions.")
            elif e.status == 403:
                print("Error 403: Forbidden. Your API key might not have permissions to list projects.")
except ValueError as e:
    print(f"Error initializing API client: {e}. Ensure LAUNCHDARKLY_API_KEY is set.")

view raw JSON →