{"id":20915716,"url":"https://github.com/python-hyper/rfc3986","last_synced_at":"2025-04-11T03:28:12.864Z","repository":{"id":18127455,"uuid":"21205959","full_name":"python-hyper/rfc3986","owner":"python-hyper","description":"A Python Implementation of RFC3986 including validations","archived":false,"fork":false,"pushed_at":"2025-03-03T20:40:51.000Z","size":377,"stargazers_count":184,"open_issues_count":20,"forks_count":32,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-31T14:08:40.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rfc3986.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-hyper.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-25T14:25:11.000Z","updated_at":"2025-02-16T12:53:26.000Z","dependencies_parsed_at":"2023-01-13T19:40:02.403Z","dependency_job_id":"aa2e7b47-f0ca-4452-aec1-ec937e3193e1","html_url":"https://github.com/python-hyper/rfc3986","commit_stats":{"total_commits":253,"total_committers":25,"mean_commits":10.12,"dds":0.4031620553359684,"last_synced_commit":"b550db8aef2667be87a08e672636b10adfff802f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-hyper%2Frfc3986","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-hyper%2Frfc3986/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-hyper%2Frfc3986/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-hyper%2Frfc3986/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-hyper","download_url":"https://codeload.github.com/python-hyper/rfc3986/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248335082,"owners_count":21086507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T16:18:01.150Z","updated_at":"2025-04-11T03:28:12.841Z","avatar_url":"https://github.com/python-hyper.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"rfc3986\n=======\n\nA Python implementation of `RFC 3986`_ including validation and authority\nparsing.\n\nInstallation\n------------\n\nUse pip to install ``rfc3986`` like so::\n\n    pip install rfc3986\n\nLicense\n-------\n\n`Apache License Version 2.0`_\n\nExample Usage\n-------------\n\nThe following are the two most common use cases envisioned for ``rfc3986``.\n\nReplacing ``urlparse``\n``````````````````````\n\nTo parse a URI and receive something very similar to the standard library's\n``urllib.parse.urlparse``\n\n.. code-block:: python\n\n    from rfc3986 import urlparse\n\n    ssh = urlparse('ssh://user@git.openstack.org:29418/openstack/glance.git')\n    print(ssh.scheme)  # =\u003e ssh\n    print(ssh.userinfo)  # =\u003e user\n    print(ssh.params)  # =\u003e None\n    print(ssh.port)  # =\u003e 29418\n\nTo create a copy of it with new pieces you can use ``copy_with``:\n\n.. code-block:: python\n\n    new_ssh = ssh.copy_with(\n        scheme='https'\n        userinfo='',\n        port=443,\n        path='/openstack/glance'\n    )\n    print(new_ssh.scheme)  # =\u003e https\n    print(new_ssh.userinfo)  # =\u003e None\n    # etc.\n\nStrictly Parsing a URI and Applying Validation\n``````````````````````````````````````````````\n\nTo parse a URI into a convenient named tuple, you can simply:\n\n.. code-block:: python\n\n    from rfc3986 import uri_reference\n\n    example = uri_reference('http://example.com')\n    email = uri_reference('mailto:user@domain.com')\n    ssh = uri_reference('ssh://user@git.openstack.org:29418/openstack/keystone.git')\n\nWith a parsed URI you can access data about the components:\n\n.. code-block:: python\n\n    print(example.scheme)  # =\u003e http\n    print(email.path)  # =\u003e user@domain.com\n    print(ssh.userinfo)  # =\u003e user\n    print(ssh.host)  # =\u003e git.openstack.org\n    print(ssh.port)  # =\u003e 29418\n\nIt can also parse URIs with unicode present:\n\n.. code-block:: python\n\n    uni = uri_reference(b'http://httpbin.org/get?utf8=\\xe2\\x98\\x83')  # ☃\n    print(uni.query)  # utf8=%E2%98%83\n\nWith a parsed URI you can also validate it:\n\n.. code-block:: python\n\n    if ssh.is_valid():\n        subprocess.call(['git', 'clone', ssh.unsplit()])\n\nYou can also take a parsed URI and normalize it:\n\n.. code-block:: python\n\n    mangled = uri_reference('hTTp://exAMPLe.COM')\n    print(mangled.scheme)  # =\u003e hTTp\n    print(mangled.authority)  # =\u003e exAMPLe.COM\n\n    normal = mangled.normalize()\n    print(normal.scheme)  # =\u003e http\n    print(mangled.authority)  # =\u003e example.com\n\nBut these two URIs are (functionally) equivalent:\n\n.. code-block:: python\n\n    if normal == mangled:\n        webbrowser.open(normal.unsplit())\n\nYour paths, queries, and fragments are safe with us though:\n\n.. code-block:: python\n\n    mangled = uri_reference('hTTp://exAMPLe.COM/Some/reallY/biZZare/pAth')\n    normal = mangled.normalize()\n    assert normal == 'hTTp://exAMPLe.COM/Some/reallY/biZZare/pAth'\n    assert normal == 'http://example.com/Some/reallY/biZZare/pAth'\n    assert normal != 'http://example.com/some/really/bizzare/path'\n\nIf you do not actually need a real reference object and just want to normalize\nyour URI:\n\n.. code-block:: python\n\n    from rfc3986 import normalize_uri\n\n    assert (normalize_uri('hTTp://exAMPLe.COM/Some/reallY/biZZare/pAth') ==\n            'http://example.com/Some/reallY/biZZare/pAth')\n\nYou can also very simply validate a URI:\n\n.. code-block:: python\n\n    from rfc3986 import is_valid_uri\n\n    assert is_valid_uri('hTTp://exAMPLe.COM/Some/reallY/biZZare/pAth')\n\nRequiring Components\n~~~~~~~~~~~~~~~~~~~~\n\nYou can validate that a particular string is a valid URI and require\nindependent components:\n\n.. code-block:: python\n\n    from rfc3986 import is_valid_uri\n\n    assert is_valid_uri('http://localhost:8774/v2/resource',\n                        require_scheme=True,\n                        require_authority=True,\n                        require_path=True)\n\n    # Assert that a mailto URI is invalid if you require an authority\n    # component\n    assert is_valid_uri('mailto:user@example.com', require_authority=True) is False\n\nIf you have an instance of a ``URIReference``, you can pass the same arguments\nto ``URIReference#is_valid``, e.g.,\n\n.. code-block:: python\n\n    from rfc3986 import uri_reference\n\n    http = uri_reference('http://localhost:8774/v2/resource')\n    assert uri.is_valid(require_scheme=True,\n                        require_authority=True,\n                        require_path=True)\n\n    # Assert that a mailto URI is invalid if you require an authority\n    # component\n    mailto = uri_reference('mailto:user@example.com')\n    assert uri.is_valid(require_authority=True) is False\n\nAlternatives\n------------\n\n- `rfc3987 \u003chttps://pypi.python.org/pypi/rfc3987/1.3.4\u003e`_\n\n  This is a direct competitor to this library, with extra features,\n  licensed under the GPL.\n\n- `uritools \u003chttps://pypi.python.org/pypi/uritools/0.5.1\u003e`_\n\n  This can parse URIs in the manner of RFC 3986 but provides no validation and\n  only recently added Python 3 support.\n\n- Standard library's `urlparse`/`urllib.parse`\n\n  The functions in these libraries can only split a URI (valid or not) and\n  provide no validation.\n\nContributing\n------------\n\nThis project follows and enforces the Python Software Foundation's `Code of\nConduct \u003chttps://www.python.org/psf/codeofconduct/\u003e`_.\n\nIf you would like to contribute but do not have a bug or feature in mind, feel\nfree to email Ian and find out how you can help.\n\nThe git repository for this project is maintained at\nhttps://github.com/python-hyper/rfc3986\n\n.. _RFC 3986: https://datatracker.ietf.org/doc/html/rfc3986/\n.. _Apache License Version 2.0: https://www.apache.org/licenses/LICENSE-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-hyper%2Frfc3986","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-hyper%2Frfc3986","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-hyper%2Frfc3986/lists"}