Skip to main content

SW360 Base Library for Python

License Python Version PyPI Static checks Unit tests Coverage REUSE status

This Python project implements the REST API of SW360 and allows an easy way to interact with SW360.

Documentation

Have a look at the documentation: https://sw360.github.io/sw360python/

Usage

Installation

This project is available as Python package on PyPi.org.
Install sw360 and required dependencies:

  pip install sw360 requests

Using the API

  • Get a REST API token from your SW360 server. In default configuration, tokens can be generated in your Preferences.

  • Starting with SW360 v20, tokens can also be generated using a Keycloak client_id and client_secret which you can request from your SW360 admin team. There's a special helper class to generate the access tokens:

    from sw360 import SW360Keycloak
    kc = SW360Keycloak(sw360_url)
    sw360_api_token = kc.get_keycloak_token(client_id, client_secret, write_access=False)
    
  • Start using the API:

    import sw360
    # oauth2=True is required for tokens created using client_id and client_secret.
    client = sw360.SW360(sw360_url, sw360_api_token, oauth2=True)
    client.login_api():
    r = client.get_release(release_id)
    
  • For long running operations the token may expire while the operation is still running. In that case you can use SW360KeycloakClient, which takes the Keycloak credentials instead of a token and renews the token shortly before it expires (five minutes by default, see refresh_before_seconds):

    from sw360 import SW360KeycloakClient
    client = SW360KeycloakClient(sw360_url, client_id, client_secret, write_access=False)
    client.login_api()
    r = client.get_release(release_id)
    

    The client uses its own session, so it does not affect clients created with a static token. If you need to hand the token to another component which creates its own client, use client.current_token to get a token that is valid now.

  • Starting with v1.12, most responses are wrapped in SW360Response, a dict subclass, so existing code keeps working unchanged, but you get new convenience methods for the _links and _embedded sections of the SW360 HAL responses:

    release = client.get_release(release_id)
    
    # get the component id from the release, instead of
    #   client.get_id_from_href(release["_links"]["sw360:component"]["href"])
    component_id = release.linked_id("component")
    component = client.get_component(component_id)
    
    # get the first attachment for the release, instead of
    #   client.get_id_from_href(release["_embedded"]["sw360:attachments"][0]["_links"]["self"]["href"])
    attachment_id = release.embedded_list("attachments")[0].linked_id()
    attachment = client.get_attachment(attachment_id)
    

    For now, the get_all_* and get_*_by_* methods (e.g. get_all_components or get_releases_by_external_id) still return a list of dicts, this is planned to be changed in a future release to also return a list of SW360Response objects.

Contribute

  • All contributions in form of bug reports, feature requests or merge requests!
  • Use proper docstrings to document
    functions and classes
  • Extend the testsuite poetry run pytest with the new functions/classes
  • The documentation website can automatically be generated by the Sphinx autodoc extension

Build

Building the Documentation

The documentation of the project is built using Sphinx:

poetry run sphinx-build ./docs-source/ ./docs/

Building Python package

For building the library, you need Poetry.
The build is then triggered using

poetry build

This creates the source and wheel files in dist/ subdirectory -- which can then be
uploaded or installed locally using pip.

Test

Start the complete test suite or a specific test case (and generate coverage report):

poetry run pytest

or

poetry run coverage run -m pytest
poetry run coverage report -m --omit "*/site-packages/*.py"
poetry run coverage html --omit "*/site-packages/*.py"

Demo

The script check_project.py shows how to use the library to retrieve some information
of a given project on SW360. This requires colorama>=0.4.1.

License

Copyright 2019-2026 Siemens

The project is licensed under the MIT license. SPDX-License-Identifier: MIT

SBOM

For an up-to-date CycloneDX SBOM, please have a look at the SBOM folder.

Metadata

Release files for sw360 1.13.0

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

Source distribution (sdist)

Source distribution for sw360 1.13.0
File Size Uploaded Provenance Actions
sw360-1.13.0.tar.gz 31.6 kB Without provenance Details for sw360-1.13.0.tar.gz

Built distribution (wheel)

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

Total release size: 76.6 kB

Release files / sw360-1.13.0.tar.gz

Download URL sw360-1.13.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bb0cf7da8b321952a9537a0b227c0b8375eefb2874fa50462b35efe5f03796bb
BLAKE2b-256 checksum
How to use checksums
04b44ae6cf7c81f3face1fd18ac28780d4b1cc5901e539208e2bc8a8075925e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.13.7 Windows/11

Release files / sw360-1.13.0-py3-none-any.whl

Download URL sw360-1.13.0-py3-none-any.whl
Size 45.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0a9c207c0fd18df27c75a37440eb40ad252045294c2fcb50a021caa437ad37a
BLAKE2b-256 checksum
How to use checksums
8cd9535dd460ba8dfd7d83459fc9ad883686f706ee96eb23a02dd36680a12b0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.13.7 Windows/11

Security for sw360 1.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.13.0 This release

2 release files No provenance

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