• Home
Name Date Size #Lines LOC

..--

docs/03-May-2024-454191

old/uritemplate.py/03-May-2024-3230

tests/03-May-2024-1,8861,691

uritemplate/03-May-2024-666478

.gitignoreD03-May-202493 1312

.travis.ymlD03-May-2024483 3227

AUTHORS.rstD03-May-202479 53

HISTORY.rstD03-May-20241.3 KiB6942

LICENSED03-May-2024199 43

LICENSE.APACHED03-May-202411.1 KiB203169

LICENSE.BSDD03-May-20241.3 KiB2421

MANIFEST.inD03-May-2024237 1310

METADATAD03-May-2024340 1715

MODULE_LICENSE_APACHE2D03-May-20240

MODULE_LICENSE_BSDD03-May-20240

NOTICED03-May-202412.5 KiB231194

OWNERSD03-May-2024207 54

README.rstD03-May-20241.8 KiB6544

setup.cfgD03-May-202428 32

setup.pyD03-May-20241.3 KiB4036

tox.iniD03-May-2024408 3227

README.rst

1uritemplate
2===========
3
4Documentation_ -- GitHub_ -- BitBucket_ -- 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.py
52
53License
54-------
55
56Modified 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