Home | History | Annotate | only in /external/python/uritemplates
Up to higher level directory
NameDateSize
.travis.yml22-Oct-2020483
AUTHORS.rst22-Oct-202079
docs/22-Oct-2020
HISTORY.rst22-Oct-20201.3K
LICENSE22-Oct-2020199
LICENSE.APACHE22-Oct-202011.1K
LICENSE.BSD22-Oct-20201.3K
MANIFEST.in22-Oct-2020237
METADATA22-Oct-2020340
MODULE_LICENSE_APACHE222-Oct-20200
MODULE_LICENSE_BSD22-Oct-20200
NOTICE22-Oct-202012.5K
old/22-Oct-2020
OWNERS22-Oct-2020207
README.rst22-Oct-20201.8K
setup.cfg22-Oct-202028
setup.py22-Oct-20201.3K
tests/22-Oct-2020
tox.ini22-Oct-2020408
uritemplate/22-Oct-2020

README.rst

      1 uritemplate
      2 ===========
      3 
      4 Documentation_ -- GitHub_ -- BitBucket_ -- Travis-CI_
      5 
      6 Simple 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 
     26 Where 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 
     40 When the module containing this class is loaded, ``GitHubUser.url`` is 
     41 evaluated and so the template is created once. It's often hard to notice in 
     42 Python, 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 
     44 reduce the amount of time your code takes to run.
     45 
     46 Installing
     47 ----------
     48 
     49 ::
     50 
     51     pip install uritemplate.py
     52 
     53 License
     54 -------
     55 
     56 Modified BSD license_
     57 
     58 
     59 .. _Documentation: http://uritemplate.rtfd.org/
     60 .. _GitHub: https://github.com/sigmavirus24/uritemplate
     61 .. _BitBucket: https://bitbucket.org/icordasc/uritemplate
     62 .. _Travis-CI: https://travis-ci.org/sigmavirus24/uritemplate
     63 .. _URI Templates: http://tools.ietf.org/html/rfc6570
     64 .. _license: https://github.com/sigmavirus24/uritemplate/blob/master/LICENSE
     65