Skip to main content

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

Metadata

Release files for urnparse 0.2.2

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

Source distribution (sdist)

Source distribution for urnparse 0.2.2
File Size Uploaded
urnparse-0.2.2.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for urnparse 0.2.2
File Interpreter ABI Platform
urnparse-0.2.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.8 kB

Release files / urnparse-0.2.2.tar.gz

Download URL urnparse-0.2.2.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
907b8f6365aa453368d27f2d62e5d18606c4148a6d8d0dec7d62439888da4b28
BLAKE2b-256 checksum
How to use checksums
1df49f6440fd271892e00c963226a9c13b072bb75613354cdbb769ae2d885c16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / urnparse-0.2.2-py2.py3-none-any.whl

Download URL urnparse-0.2.2-py2.py3-none-any.whl
Size 5.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5bf3ce5ffbfcfbc7412c006c64eceb2531e2d91cf94d1103433684bb68913946
BLAKE2b-256 checksum
How to use checksums
d12cb3941ede58eb540cc00a2941d1e70aa16e0c7732ae56319b6aba366e3094
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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