Skip to main content

A purl aka. Package URL parser and builder

Project description

Python library to parse and build “purl” aka. Package URLs. See https://github.com/package-url/purl-spec for details.

Join the discussion at https://gitter.im/package-url/Lobby or enter a ticket for support.

License: MIT

Tests and build status

Tests and build

CI Tests and build status

Install

pip install packageurl-python

Usage

>>> from packageurl import PackageURL

>>> purl = PackageURL.from_string("pkg:maven/org.apache.commons/io@1.3.4")
>>> print(purl.to_dict())
{'type': 'maven', 'namespace': 'org.apache.commons', 'name': 'io', 'version': '1.3.4', 'qualifiers': None, 'subpath': None}

>>> print(purl.to_string())
pkg:maven/org.apache.commons/io@1.3.4

>>> print(str(purl))
pkg:maven/org.apache.commons/io@1.3.4

>>> print(repr(purl))
PackageURL(type='maven', namespace='org.apache.commons', name='io', version='1.3.4', qualifiers={}, subpath=None)

Utilities

Django models

packageurl.contrib.django.models.PackageURLMixin is a Django abstract model mixin to use Package URLs in Django.

SQLAlchemy mixin

packageurl.contrib.sqlalchemy.mixin.PackageURLMixin is a SQLAlchemy declarative mixin to use Package URLs in SQLAlchemy models.

URL to PURL

packageurl.contrib.url2purl.get_purl(url) returns a Package URL inferred from an URL.

>>> from packageurl.contrib import url2purl
>>> url2purl.get_purl("https://github.com/package-url/packageurl-python")
PackageURL(type='github', namespace='package-url', name='packageurl-python', version=None, qualifiers={}, subpath=None)

PURL to URL

  • packageurl.contrib.purl2url.get_repo_url(purl) returns a repository URL inferred from a Package URL.

  • packageurl.contrib.purl2url.get_download_url(purl) returns a download URL inferred from a Package URL.

  • packageurl.contrib.purl2url.get_inferred_urls(purl) return all inferred URLs (repository, download) from a Package URL.

>>> from packageurl.contrib import purl2url

>>> purl2url.get_repo_url("pkg:gem/bundler@2.3.23")
"https://rubygems.org/gems/bundler/versions/2.3.23"

>>> purl2url.get_download_url("pkg:gem/bundler@2.3.23")
"https://rubygems.org/downloads/bundler-2.3.23.gem"

>>> purl2url.get_inferred_urls("pkg:gem/bundler@2.3.23")
["https://rubygems.org/gems/bundler/versions/2.3.23", "https://rubygems.org/downloads/bundler-2.3.23.gem"]

Run tests

Install test dependencies:

python3 thirdparty/virtualenv.pyz --never-download --no-periodic-update .
bin/pip install -e ."[test]"

Run tests:

bin/pytest tests

Make a new release

  • Start a new release branch

  • Update the CHANGELOG.rst, AUTHORS.rst, and README.rst if needed

  • Bump version in setup.cfg

  • Run all tests

  • Install restview and validate that all .rst docs are correct

  • Commit and push this branch

  • Make a PR and merge once approved

  • Tag and push that tag. This triggers the pypi-release.yml workflow that takes care of building the dist release files and upload those to pypi:

    VERSION=v0.x.x
    git tag -a $VERSION -m "Tag $VERSION"
    git push origin $VERSION
  • Review the GitHub release created by the workflow at https://github.com/package-url/packageurl-python/releases

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

packageurl_python-0.16.0.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

packageurl_python-0.16.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file packageurl_python-0.16.0.tar.gz.

File metadata

  • Download URL: packageurl_python-0.16.0.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for packageurl_python-0.16.0.tar.gz
Algorithm Hash digest
SHA256 69e3bf8a3932fe9c2400f56aaeb9f86911ecee2f9398dbe1b58ec34340be365d
MD5 7510a4ac5e76a176e0d2231b43f5321b
BLAKE2b-256 687d0bd319dc94c7956b4d864e87d3dc03739f125ce174671e3128edd566a63e

See more details on using hashes here.

Provenance

File details

Details for the file packageurl_python-0.16.0-py3-none-any.whl.

File metadata

File hashes

Hashes for packageurl_python-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3872638b177b0f1cf01c3673017b7b27ebee485693ae12a8bed70fa7fa7c35
MD5 60714b7eab3e24b416c7e236738d9934
BLAKE2b-256 c4473c197fb7596a813afef2e4198d507b761aed2c7150d90be64dff9fe0ea71

See more details on using hashes here.

Provenance

Supported by

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