Black Duck Python API Client
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
- breaking The `HubInstance` interface, used in older versions, will break when connecting to Black Duck instances running v2022.2 or later due to the introduction of a max page size in the REST API. It does not provide automatic paging support.
- deprecated The `HubInstance` interface is deprecated and no longer maintained. Examples using it are not guaranteed to work and any related issues will be closed as 'Won't Fix'.
- gotcha While some examples or older scripts might use a `.restconfig.json` file for configuration (e.g., `baseurl`, `api_token`), it is generally recommended to use environment variables (`BLACKDUCK_URL`, `BLACKDUCK_TOKEN`) for consistency and security in automated environments, especially for the `Client` class.
- gotcha Despite version 1.1.3 being released on April 19, 2024, the PyPI package has not seen further updates in the last two years (as of April 15, 2026). Snyk reports the maintenance status as 'Inactive', suggesting a potentially low attention from maintainers for new releases, although the GitHub repository shows some recent activity and an upcoming v1.1.4.
- gotcha When integrating with Black Duck Detect (a separate scanning tool, often used in conjunction with this library), ensure that Python environments (e.g., virtualenvs) and package managers (pip, pipenv, poetry) are correctly configured and accessible by Detect. Incorrect setup can lead to incomplete or no results for Python project scans.
Install
-
pip install blackduck -
pip install blackduck[mcp]
Imports
- Client
from blackduck.HubRestApi import HubInstance
from blackduck import Client
Quickstart
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}")