Licensing

The pyTooling.Licensing package provides auxiliary classes to represent commonly known licenses and mappings of their names, because some tools use differing names for the same license.

Background Information

There are several names, identifiers and (Python package) classifiers referring to the same license. E.g. package classifiers used by setuptools and displayed by PIP/PyPI are different from SPDX identifiers and sometimes they are not even identical to the official license names. Also some allegedly similar licenses got different SPDX identifiers.

The package pyTooling.Licensing provides license name and identifiers mappings to unify all these names and classifiers to and from SPDX identifiers.

Examples:

SDPX Identifier

Official License Name

License (short) Name

Python package classifier

Apache-2.0

Apache License, Version 2.0

Apache 2.0

License :: OSI Approved :: Apache Software License

BSD-3-Clause

The 3-Clause BSD License

BSD

License :: OSI Approved :: BSD License

Licenses

The License class represents of a license like Apache License, Version 2.0 (SPDX: Apache-2.0). It offers several information about a license as properties. Licenses can be compared for equality (==, !=) based on there SPDX identifier.

Condensed definition of class License:

@export
class License(metaclass=ExtendedType, slots=True):
  def __init__(self, spdxIdentifier: str, name: str, osiApproved: bool = False, fsfApproved: bool = False) -> None:

   @property
   def Name(self) -> str:

   @property
   def SPDXIdentifier(self) -> str:

   @property
   def OSIApproved(self) -> bool:

   @property
   def FSFApproved(self) -> bool:

   @property
   def PythonLicenseName(self) -> str:

   @property
   def PythonClassifier(self) -> str:

   def __eq__(self, other: Any) -> bool:
   def __ne__(self, other: Any) -> bool:
   # def __le__(self, other: Any) -> bool:
   # def __ge__(self, other: Any) -> bool:

   def __repr__(self) -> str:
   def __str__(self) -> str:

The licenses supported by this package are available as individual package variables.

Package variables of predefined licenses:

from pyTooling.Licensing import Apache_2_0_License

license = Apache_2_0_License
print(f"Python classifier: {license.PythonClassifier}")
print(f"SPDX:              {license.SPDXIdentifier}")
# Python classifier: License :: OSI Approved :: Apache Software License
# SPDX:              Apache-2.0

In addition a dictionary (SPDX_INDEX) maps from SPDX identified to License instances.

from pyTooling.License import SPDX_INDEX

licenseName = "MIT"
license = SPDX_INDEX[licenseName]
print(f"Python classifier: {license.PythonClassifier}")
print(f"SPDX:              {license.SPDXIdentifier}")
# Python classifier: License :: OSI Approved :: MIT License
# SPDX:              MIT

Mappings

PYTHON_LICENSE_NAMES offers a Python specific mapping from SPDX identifier to license names used by Python (setuptools). Each dictionary item contains a PythonLicenseNames instance which contains the license name and package classifier used by setuptools.

Currently the following licenses are listed in the Python specific name mapping:

  • Apache-2.0

  • BSD-3-Clause

  • MIT

  • GPL-2.0-or-later

Usage with Setuptools

The following examples demonstrates the usage with setuptools in a setup.py.

Usage Example

from setuptools import setup
from pyTooling.Licensing import Apache_2_0_License

classifiers = [
  "Operating System :: OS Independent",
  "Programming Language :: Python :: 3 :: Only"
]

license = Apache_2_0_License
classifiers.append(license.PythonClassifier)

# Assemble other parameters
# ...

# Handover to setuptools
setup(
  # ...
  license=license.SPDXIdentifier,
  # ...
  classifiers=classifiers,
  # ...
)