uritemplate


Nameuritemplate JSON
Version 4.1.1 PyPI version JSON
download
home_pagehttps://uritemplate.readthedocs.org
SummaryImplementation of RFC 6570 URI Templates
upload_time2021-10-13 11:15:14
maintainer
docs_urlNone
authorIan Stapleton Cordasco
requires_python>=3.6
licenseBSD 3-Clause License or Apache License, Version 2.0
keywords rfc 6570 uri template
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            uritemplate
===========

Documentation_ -- GitHub_ -- Travis-CI_

Simple python library to deal with `URI Templates`_. The API looks like

.. code-block:: python

    from uritemplate import URITemplate, expand

    # NOTE: URI params must be strings not integers

    gist_uri = 'https://api.github.com/users/sigmavirus24/gists{/gist_id}'
    t = URITemplate(gist_uri)
    print(t.expand(gist_id='123456'))
    # => https://api.github.com/users/sigmavirus24/gists/123456

    # or
    print(expand(gist_uri, gist_id='123456'))

    # also
    t.expand({'gist_id': '123456'})
    print(expand(gist_uri, {'gist_id': '123456'}))

Where it might be useful to have a class

.. code-block:: python

    import requests

    class GitHubUser(object):
        url = URITemplate('https://api.github.com/user{/login}')
        def __init__(self, name):
            self.api_url = url.expand(login=name)
            response = requests.get(self.api_url)
            if response.status_code == 200:
                self.__dict__.update(response.json())

When the module containing this class is loaded, ``GitHubUser.url`` is
evaluated and so the template is created once. It's often hard to notice in
Python, but object creation can consume a great deal of time and so can the
``re`` module which uritemplate relies on. Constructing the object once should
reduce the amount of time your code takes to run.

Installing
----------

::

    pip install uritemplate

License
-------

Modified BSD license_


.. _Documentation: https://uritemplate.readthedocs.io/
.. _GitHub: https://github.com/python-hyper/uritemplate
.. _Travis-CI: https://travis-ci.org/python-hyper/uritemplate
.. _URI Templates: https://tools.ietf.org/html/rfc6570
.. _license: https://github.com/python-hyper/uritemplate/blob/master/LICENSE



            

Raw data

            {
    "_id": null,
    "home_page": "https://uritemplate.readthedocs.org",
    "name": "uritemplate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "rfc 6570 uri template",
    "author": "Ian Stapleton Cordasco",
    "author_email": "graffatcolmingov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d2/5a/4742fdba39cd02a56226815abfa72fe0aa81c33bed16ed045647d6000eba/uritemplate-4.1.1.tar.gz",
    "platform": "",
    "description": "uritemplate\n===========\n\nDocumentation_ -- GitHub_ -- Travis-CI_\n\nSimple python library to deal with `URI Templates`_. The API looks like\n\n.. code-block:: python\n\n    from uritemplate import URITemplate, expand\n\n    # NOTE: URI params must be strings not integers\n\n    gist_uri = 'https://api.github.com/users/sigmavirus24/gists{/gist_id}'\n    t = URITemplate(gist_uri)\n    print(t.expand(gist_id='123456'))\n    # => https://api.github.com/users/sigmavirus24/gists/123456\n\n    # or\n    print(expand(gist_uri, gist_id='123456'))\n\n    # also\n    t.expand({'gist_id': '123456'})\n    print(expand(gist_uri, {'gist_id': '123456'}))\n\nWhere it might be useful to have a class\n\n.. code-block:: python\n\n    import requests\n\n    class GitHubUser(object):\n        url = URITemplate('https://api.github.com/user{/login}')\n        def __init__(self, name):\n            self.api_url = url.expand(login=name)\n            response = requests.get(self.api_url)\n            if response.status_code == 200:\n                self.__dict__.update(response.json())\n\nWhen the module containing this class is loaded, ``GitHubUser.url`` is\nevaluated and so the template is created once. It's often hard to notice in\nPython, but object creation can consume a great deal of time and so can the\n``re`` module which uritemplate relies on. Constructing the object once should\nreduce the amount of time your code takes to run.\n\nInstalling\n----------\n\n::\n\n    pip install uritemplate\n\nLicense\n-------\n\nModified BSD license_\n\n\n.. _Documentation: https://uritemplate.readthedocs.io/\n.. _GitHub: https://github.com/python-hyper/uritemplate\n.. _Travis-CI: https://travis-ci.org/python-hyper/uritemplate\n.. _URI Templates: https://tools.ietf.org/html/rfc6570\n.. _license: https://github.com/python-hyper/uritemplate/blob/master/LICENSE\n\n\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License or Apache License, Version 2.0",
    "summary": "Implementation of RFC 6570 URI Templates",
    "version": "4.1.1",
    "split_keywords": [
        "rfc",
        "6570",
        "uri",
        "template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "a68f2279025a2610613efb2287eaf463",
                "sha256": "830c08b8d99bdd312ea4ead05994a38e8936266f84b9a7878232db50b044e02e"
            },
            "downloads": -1,
            "filename": "uritemplate-4.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a68f2279025a2610613efb2287eaf463",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 10356,
            "upload_time": "2021-10-13T11:15:12",
            "upload_time_iso_8601": "2021-10-13T11:15:12.316885Z",
            "url": "https://files.pythonhosted.org/packages/81/c0/7461b49cd25aeece13766f02ee576d1db528f1c37ce69aee300e075b485b/uritemplate-4.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "6a40709eb966d0a57fea08c3f11ff325",
                "sha256": "4346edfc5c3b79f694bccd6d6099a322bbeb628dbf2cd86eea55a456ce5124f0"
            },
            "downloads": -1,
            "filename": "uritemplate-4.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6a40709eb966d0a57fea08c3f11ff325",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 273898,
            "upload_time": "2021-10-13T11:15:14",
            "upload_time_iso_8601": "2021-10-13T11:15:14.840878Z",
            "url": "https://files.pythonhosted.org/packages/d2/5a/4742fdba39cd02a56226815abfa72fe0aa81c33bed16ed045647d6000eba/uritemplate-4.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-10-13 11:15:14",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "uritemplate"
}
        
Elapsed time: 0.01878s