Skip to main content

Overview

The hub-rest-api-python provides Python bindings for Hub REST API.

Paging and Black Duck v2022.2

In v2022.2 of Black Duck the REST API introduced a max page size to protect system resource usage. See the Black Duck release notes on Synopsys Community for the details of which API endpoints are affected. Users of the the python bindings here should leverage the Client interface which provides automatic paging support to make best use of these endpoints.

The old HubInstance interface and many of the examples using it do not perform paging and will break as a result of the changes in v2022.2.

Any issues related to the HubInstance Interface will be closed as Won't Fix

Any PRs with new or modified example scripts/utilities must use the client interface.

New in 1.0.0

Introducing the new Client class.

In order to provide a more robust long-term connection, faster performance, and an overall better experience a new Client class has been designed.

It is backed by a Requests session object. The user specifies a base URL, timeout, retries, proxies, and TLS verification upon initialization and these attributes are persisted across all requests.

At the REST API level, the Client class provides a consistent way to discover and traverse public resources, uses a generator to fetch all items using pagination, and automatically renews the bearer token.

See Client versus HubInstance Comparison and also read the Client User Guide on the Hub REST API Python Wiki.

Important Notes

The old HubInstance (in HubRestApi.py) keeps its existing functionality for backwards compatibility and therefore does not currently leverage any of the new features in the Client class.

We believe that the new features are compelling enough to strongly encourage users to consider moving from HubInstance to Client. See Client versus HubInstance Comparison.

Please give it a try and let us know what you think!

To use

pip3 install blackduck
from blackduck import Client
import logging
import os

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

bd = Client(
    token=os.environ.get('blackduck_token'),
    base_url="https://your.blackduck.url",
    # verify=False  # TLS certificate verification
)

for project in bd.get_resource(name='projects'):
    print(project.get('name'))

Examples

Example code showing how to work with the new Client can be found in the examples/client folder.

Examples which use the old HubInstance interface -which is not maintained- are not guaranteed to work. Use at your own risk.

Version History

Including a version history on a go-forward basis.

v1.1.0

Retries will be attempted for all HTTP verbs, not just GET.

Test

Using pytest

git clone https://github.com/blackducksoftware/hub-rest-api-python.git
cd hub-rest-api-python
# optional but advisable: create/use virtualenv
# you should have 3.x+, e.g. Python 3.8.0+

pip3 install -r requirements.txt
pip3 install .
cd test
pytest

Install package locally

Do this when testing a new version.

git clone https://github.com/blackducksoftware/hub-rest-api-python.git
cd hub-rest-api-python
pip3 install -r requirements.txt
pip3 install .

To uninstall:

pip3 uninstall blackduck

Where can I get the latest release?

This package is available on PyPi:

pip3 install blackduck

Documentation

Documentation for hub-rest-api-python can be found on the base project: Hub REST API Python Wiki

Metadata

Release files for blackduck 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blackduck 1.1.3
File Size Uploaded
blackduck-1.1.3.tar.gz 33.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blackduck 1.1.3
File Interpreter ABI Platform
blackduck-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 72.3 kB

Release files / blackduck-1.1.3.tar.gz

Download URL blackduck-1.1.3.tar.gz
Size 33.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0ca5f16ae7d9e755c92d29b90efa5ed2d519ed8695c0e20229f9c0a0603beef9
BLAKE2b-256 checksum
How to use checksums
2bb9eda55de60d78cd77985368203b55ccb8c1282319163c81fd10c87b45b5ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Release files / blackduck-1.1.3-py3-none-any.whl

Download URL blackduck-1.1.3-py3-none-any.whl
Size 39.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b40f05232f4318576c230a751960700a5517ac83d5cf443f1f4a8f3fa633ca14
BLAKE2b-256 checksum
How to use checksums
1a30e2943394d61cf57f978175ff8cdd1a45790c7065894495089ab1e5268fbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.0

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.54

2 release files

0.0.53

2 release files

0.0.52

2 release files

0.0.51

2 release files

0.0.50

2 release files

0.0.49

2 release files

0.0.48

2 release files

0.0.47

2 release files

0.0.46

2 release files

0.0.45

2 release files

0.0.44

2 release files

0.0.43

2 release files

0.0.42

2 release files

0.0.41

2 release files

0.0.40

2 release files

0.0.39

2 release files

0.0.37

2 release files

0.0.35

2 release files

0.0.33

2 release files

0.0.32

2 release files

0.0.31

2 release files

0.0.30

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page