# urnparse
Python library for generating and parsing [RFC 8141]( https://tools.ietf.org/html/rfc8141) compliant uniform
resource names (URN).
## Installation
To use this library in your project, install it with pip
```shell
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:
```python
from urnparse import URN8141
urn_string = 'urn:example:example.org:resources:'+\
'example%20resource?+res1=a'+\
'?=param1=test¶m2=test2#example.org'
urn = URN8141.from_string(urn_string)
````
You can then access the specific URN components:
```python
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:
````python
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¶m2=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¶m2=test2#example.org
````
Raw data
{
"_id": null,
"home_page": "https://github.com/oarepo/urnparse",
"name": "urnparse",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Miroslav Bauer @ CESNET",
"author_email": "bauer@cesnet.cz",
"download_url": "https://files.pythonhosted.org/packages/1d/f4/9f6440fd271892e00c963226a9c13b072bb75613354cdbb769ae2d885c16/urnparse-0.2.2.tar.gz",
"platform": "any",
"description": "# urnparse\nPython library for generating and parsing [RFC 8141]( https://tools.ietf.org/html/rfc8141) compliant uniform\nresource names (URN).\n\n## Installation\n\nTo use this library in your project, install it with pip\n\n```shell\npip install urnparse\n```\n\n## Usage\n\n### Create URN object from RFC 8141 formatted string\nTo validate a given URN string against the RFC 8141 specification and construct\nan URN object from it, use the `URN8141.from_string()` method:\n\n```python\nfrom urnparse import URN8141\n\nurn_string = 'urn:example:example.org:resources:'+\\\n 'example%20resource?+res1=a'+\\\n '?=param1=test¶m2=test2#example.org'\n\nurn = URN8141.from_string(urn_string)\n````\n\nYou can then access the specific URN components:\n```python\nprint(urn.namespace_id)\n# example\nprint(urn.specific_string.decoded)\n# example.org:resources:example resource\nprint(urn.specific_string.parts)\n# ['example.org', 'resources', 'example resource']\nprint(urn.rqf_component.resolution)\n# {'res1': 'a'}\nprint(urn.rqf_component.query)\n# {'param1': 'test', 'param2': 'test2'}\nprint(urn.rqf_component.fragment)\n# example.org\n```\n\n#### Create URN string from component objects \nTo create an RFC 8141 formatted URN string for a certain resource, construct the URN\nobject from the following components:\n\n````python\nfrom urnparse import URN8141, NSIdentifier, NSSString, RQFComponent\n\nnid = NSIdentifier('example')\nnss = NSSString('example.org:resources:example%20resource', encoded=True)\nrqf = RQFComponent(resolution_string='res1=a',\n query_string='param1=test¶m2=test2',\n fragment='example.org')\n\nurn = URN8141(nid=nid, nss=nss, rqf=rqf)\n\nprint(urn)\n# urn:example:example.org:resources:example%20resource?+res1=a?=param1=test¶m2=test2#example.org\n````\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library for generating and parsing and RFC 8141 compliant uniform resource names (URN).",
"version": "0.2.2",
"project_urls": {
"Homepage": "https://github.com/oarepo/urnparse"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d12cb3941ede58eb540cc00a2941d1e70aa16e0c7732ae56319b6aba366e3094",
"md5": "2f147348a7c3923818f5162c749533f6",
"sha256": "5bf3ce5ffbfcfbc7412c006c64eceb2531e2d91cf94d1103433684bb68913946"
},
"downloads": -1,
"filename": "urnparse-0.2.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "2f147348a7c3923818f5162c749533f6",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 5906,
"upload_time": "2024-05-13T08:47:43",
"upload_time_iso_8601": "2024-05-13T08:47:43.948344Z",
"url": "https://files.pythonhosted.org/packages/d1/2c/b3941ede58eb540cc00a2941d1e70aa16e0c7732ae56319b6aba366e3094/urnparse-0.2.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1df49f6440fd271892e00c963226a9c13b072bb75613354cdbb769ae2d885c16",
"md5": "da824e666c95056b56ade24e5e339dbb",
"sha256": "907b8f6365aa453368d27f2d62e5d18606c4148a6d8d0dec7d62439888da4b28"
},
"downloads": -1,
"filename": "urnparse-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "da824e666c95056b56ade24e5e339dbb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5915,
"upload_time": "2024-05-13T08:47:45",
"upload_time_iso_8601": "2024-05-13T08:47:45.529888Z",
"url": "https://files.pythonhosted.org/packages/1d/f4/9f6440fd271892e00c963226a9c13b072bb75613354cdbb769ae2d885c16/urnparse-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-13 08:47:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "oarepo",
"github_project": "urnparse",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "urnparse"
}