Skip to main content

SPDX Model Python Bindings

Project description

spdx-python-model

PyPI - Version Apache-2.0 license

spdx-python-model is a Python library for working with the SPDX 3 data model.

Read the API documentation.

All bindings in this repository are auto-generated from the RDF and SHACL definitions of the SPDX specification version 3 using shacl2code during the package build process.

NOTE: The bindings are pretty low level, intended for more directly manipulating SPDX files. While they are fully functions, they lack higher level helper functions that may be useful for creating SPDX documents. If you want a higher level approach, please see the SPDX Python Tools (however, it doesn't yet support SPDX 3).

Installation

Install from PyPI

python3 -m pip install spdx-python-model

Install from Git

If you would like to pull the bindings directly from Git instead of using a released version from PyPI, the following command can be used:

python3 -m pip install git+https://github.com/spdx/spdx-python-model.git@main

Note that this will pull the latest version from the main branch. If you want a specific commit, replace main with the git commit SHA.

Install/build using local SPDX model files

Using local SPDX model files is ideal for testing pre-release versions or when official URLs are not yet live.

It is also required for build systems that prohibit network access during packaging, such as Debian or Yocto.

To build using local model files:

  1. Clone the repository:

    git clone https://github.com/spdx/spdx-python-model.git
    cd spdx-python-model
    
  2. Download model files:

    Run the following commands to download the necessary files for a specific SPDX version and keep it in a local directory:

    mkdir -p ~/spdx_models/v3.0.1
    cd ~/spdx_models/v3.0.1
    wget https://spdx.org/rdf/3.0.1/spdx-context.jsonld
    wget https://spdx.org/rdf/3.0.1/spdx-json-serialize-annotations.ttl
    wget https://spdx.org/rdf/3.0.1/spdx-model.ttl
    

    Or use your own model files.

    The local directory must be organized by SPDX version, with specific file names.

    <SHACL2CODE_SPDX_DIR>/
    └── v[VERSION]/
        ├── spdx-context.jsonld
        ├── spdx-json-serialize-annotations.ttl
        └── spdx-model.ttl
    
  3. Set the model directory:

    Point SHACL2CODE_SPDX_DIR environment variable to that local directory.

    export SHACL2CODE_SPDX_DIR=~/spdx_models
    
  4. Install/build:

    python3 -m pip install .
    

    or

    python3 -m build
    

Usage

Each version of the SPDX spec has a module named v{MAJOR}_{MINOR}_{MICRO} that contains the bindings for that version under the spdx_python_model top level. For example:

import spdx_python_model

p = spdx_python_model.v3_0_1.Person()

Alternatively, if a shorter name is desired, a specific version can be imported with another name:

from spdx_python_model import v3_0_1 as spdx_3_0

p = spdx_3_0.Person()

You can also have the bindings automatically detect the correct version to use using the load() API:

import spdx_python_model

path = Path("/path/to/file.spdx3.json")

model, objset = spdx_python_model.load(path)

p = model.Person()

Check out this short Python notebook tutorial to get started with spdx-python-model.

Testing

This repository has support for running tests against the bindings using pytest. To run the tests, first setup a virtual environment and install the development variant of the package in editable mode:

python3 -m venv .venv
. .venv/bin/activate
pip install -e '.[dev]'

Then the tests can be run with:

pytest -vx

Making a new release

To make a new release of this repository, bump the version number found in src/spdx_python_model/version.py, and merge it into the repo. After this, make a new release in GitHub with the name v + VERSION, where VERSION matches the version number specified in version.py (e.g. v1.0.0).

After this, GitHub actions will do the rest to build the package and publish it to PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spdx_python_model-0.0.6.tar.gz (91.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spdx_python_model-0.0.6-py3-none-any.whl (78.2 kB view details)

Uploaded Python 3

File details

Details for the file spdx_python_model-0.0.6.tar.gz.

File metadata

  • Download URL: spdx_python_model-0.0.6.tar.gz
  • Upload date:
  • Size: 91.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spdx_python_model-0.0.6.tar.gz
Algorithm Hash digest
SHA256 f1938eb08d08218278122849bba123b8993a0171e9b4f5ea6af7aeb71f3204d7
MD5 ed0a885deeeba3721fe104902f42a1cd
BLAKE2b-256 58f3c56b238b37de47f490d3e543ac64d648c460c4e83c41fbf90bc14d676c29

See more details on using hashes here.

Provenance

The following attestation bundles were made for spdx_python_model-0.0.6.tar.gz:

Publisher: publish.yaml on spdx/spdx-python-model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spdx_python_model-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for spdx_python_model-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dd793ce0176e53af05f9c0d8624196f38da45bc263ccee5ee532b1812b3113e2
MD5 bac10032d9b1d113e037ce4a183bd9f2
BLAKE2b-256 5b1cc3b3e131f97f21b55438161758f3d6b922889ae33746cf6059569f3265d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for spdx_python_model-0.0.6-py3-none-any.whl:

Publisher: publish.yaml on spdx/spdx-python-model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page