Skip to main content

Python library for generating and parsing and RFC 8141 compliant uniform resource names (URN).

Project description

urnparse

Python library for generating and parsing RFC 8141 compliant uniform resource names (URN).

Installation

To use this library in your project, install it with pip

pip install urnparse

Usage

Create URN object from RFC 8141 formatted string

To validate a given URN string against the RFC 8141 specification and construct an URN object from it, use the URN8141.from_string() method:

from urnparse import URN8141

urn_string = 'urn:example:example.org:resources:'+\
             'example%20resource?+res1=a'+\
             '?=param1=test&param2=test2#example.org'

urn = URN8141.from_string(urn_string)

You can then access the specific URN components:

print(urn.namespace_id)
# example
print(urn.specific_string.decoded)
# example.org:resources:example resource
print(urn.specific_string.parts)
# ['example.org', 'resources', 'example resource']
print(urn.rqf_component.resolution)
# {'res1': 'a'}
print(urn.rqf_component.query)
# {'param1': 'test', 'param2': 'test2'}
print(urn.rqf_component.fragment)
# example.org

Create URN string from component objects

To create an RFC 8141 formatted URN string for a certain resource, construct the URN object from the following components:

from urnparse import URN8141, NSIdentifier, NSSString, RQFComponent

nid = NSIdentifier('example')
nss = NSSString('example.org:resources:example%20resource', encoded=True)
rqf = RQFComponent(resolution_string='res1=a',
                   query_string='param1=test&param2=test2',
                   fragment='example.org')

urn = URN8141(nid=nid, nss=nss, rqf=rqf)

print(urn)
# urn:example:example.org:resources:example%20resource?+res1=a?=param1=test&param2=test2#example.org

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

urnparse-0.2.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

urnparse-0.2.1-py2.py3-none-any.whl (5.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file urnparse-0.2.1.tar.gz.

File metadata

  • Download URL: urnparse-0.2.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for urnparse-0.2.1.tar.gz
Algorithm Hash digest
SHA256 15d0964c16388cb99bdd891e5ddfa2eeeb558dc16121f4bd7255f12f0b837777
MD5 5f49fdf8f6d877c7eea547f631b3d521
BLAKE2b-256 f979efbe5dd37b26368fef74e1adea0736ec59313f5fbd06efd5969404147327

See more details on using hashes here.

File details

Details for the file urnparse-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: urnparse-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for urnparse-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8af095760c5166b472be4ca570c1d71eb9b82bb722409d76fdcde564de844b23
MD5 394e55c29d63883cbe135c66e3a46f92
BLAKE2b-256 435f5bae73e4fe6d9da34d67e7f3c3e9519928a65d10554f96b61d2a82ad5912

See more details on using hashes here.

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