Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
docs/ | 23-Nov-2023 | - | 454 | 191 | ||
old/uritemplate.py/ | 23-Nov-2023 | - | 31 | 29 | ||
tests/ | 23-Nov-2023 | - | 1,933 | 1,736 | ||
uritemplate/ | 23-Nov-2023 | - | 771 | 549 | ||
.gitignore | D | 23-Nov-2023 | 93 | 13 | 12 | |
.mailmap | D | 23-Nov-2023 | 199 | 3 | 2 | |
.travis.yml | D | 23-Nov-2023 | 524 | 34 | 29 | |
AUTHORS.rst | D | 23-Nov-2023 | 233 | 16 | 12 | |
Android.bp | D | 23-Nov-2023 | 1.3 KiB | 40 | 37 | |
HISTORY.rst | D | 23-Nov-2023 | 1.6 KiB | 82 | 51 | |
LICENSE | D | 23-Nov-2023 | 196 | 4 | 3 | |
LICENSE.APACHE | D | 23-Nov-2023 | 11.1 KiB | 203 | 169 | |
LICENSE.BSD | D | 23-Nov-2023 | 1.3 KiB | 24 | 21 | |
MANIFEST.in | D | 23-Nov-2023 | 237 | 13 | 10 | |
METADATA | D | 23-Nov-2023 | 374 | 20 | 19 | |
MODULE_LICENSE_APACHE2 | D | 23-Nov-2023 | 0 | |||
MODULE_LICENSE_BSD | D | 23-Nov-2023 | 0 | |||
NOTICE | D | 23-Nov-2023 | 12.5 KiB | 231 | 194 | |
OWNERS | D | 23-Nov-2023 | 207 | 5 | 4 | |
README.rst | D | 23-Nov-2023 | 1.8 KiB | 64 | 43 | |
setup.cfg | D | 23-Nov-2023 | 28 | 3 | 2 | |
setup.py | D | 23-Nov-2023 | 1.6 KiB | 50 | 43 | |
tox.ini | D | 23-Nov-2023 | 407 | 32 | 27 |
README.rst
1uritemplate 2=========== 3 4Documentation_ -- GitHub_ -- Travis-CI_ 5 6Simple python library to deal with `URI Templates`_. The API looks like 7 8.. code-block:: python 9 10 from uritemplate import URITemplate, expand 11 12 # NOTE: URI params must be strings not integers 13 14 gist_uri = 'https://api.github.com/users/sigmavirus24/gists{/gist_id}' 15 t = URITemplate(gist_uri) 16 print(t.expand(gist_id='123456')) 17 # => https://api.github.com/users/sigmavirus24/gists/123456 18 19 # or 20 print(expand(gist_uri, gist_id='123456')) 21 22 # also 23 t.expand({'gist_id': '123456'}) 24 print(expand(gist_uri, {'gist_id': '123456'})) 25 26Where it might be useful to have a class 27 28.. code-block:: python 29 30 import requests 31 32 class GitHubUser(object): 33 url = URITemplate('https://api.github.com/user{/login}') 34 def __init__(self, name): 35 self.api_url = url.expand(login=name) 36 response = requests.get(self.api_url) 37 if response.status_code == 200: 38 self.__dict__.update(response.json()) 39 40When the module containing this class is loaded, ``GitHubUser.url`` is 41evaluated and so the template is created once. It's often hard to notice in 42Python, but object creation can consume a great deal of time and so can the 43``re`` module which uritemplate relies on. Constructing the object once should 44reduce the amount of time your code takes to run. 45 46Installing 47---------- 48 49:: 50 51 pip install uritemplate 52 53License 54------- 55 56Modified BSD license_ 57 58 59.. _Documentation: https://uritemplate.readthedocs.io/ 60.. _GitHub: https://github.com/python-hyper/uritemplate 61.. _Travis-CI: https://travis-ci.org/python-hyper/uritemplate 62.. _URI Templates: http://tools.ietf.org/html/rfc6570 63.. _license: https://github.com/python-hyper/uritemplate/blob/master/LICENSE 64