Black Duck Python API Client

1.1.3 · maintenance · verified Wed Apr 15

The `blackduck` library provides Python bindings for interacting with the Synopsys Black Duck Hub REST API. It allows users to automate tasks such as fetching project information, managing vulnerabilities, and integrating with Black Duck's security and compliance features. The current version is 1.1.3, released on April 19, 2024. While functionally stable, the project's release cadence appears to be slow, with no new PyPI versions in the past two years, suggesting a maintenance-focused status.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Client` and fetch a list of projects. It expects `BLACKDUCK_URL` and `BLACKDUCK_TOKEN` to be set as environment variables for secure authentication. The `Client` automatically handles API pagination.

import os
from blackduck import Client
import logging

logging.basicConfig(
    level=logging.INFO,
    format="[%(asctime)s] {%(module)s:%(lineno)d} %(levelname)s - %(message)s"
)

# Ensure BLACKDUCK_URL and BLACKDUCK_TOKEN environment variables are set
bd_url = os.environ.get('BLACKDUCK_URL', '')
bd_token = os.environ.get('BLACKDUCK_TOKEN', '')

if not bd_url or not bd_token:
    print("Error: BLACKDUCK_URL and BLACKDUCK_TOKEN environment variables must be set.")
    # In a real application, you might raise an exception or exit
    exit(1)

try:
    # Initialize the Black Duck Client
    bd = Client(
        token=bd_token,
        base_url=bd_url,
        # verify=False # Uncomment to disable TLS certificate verification (use with caution)
    )

    print(f"Successfully connected to Black Duck at {bd_url}")
    print("Listing first 5 projects:")

    # Fetch and print project names (Client handles pagination automatically)
    projects = bd.get_resource(name='projects', limit=5)
    for project in projects:
        print(f"- {project.get('name')}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →