Implementation of RFC 6570 URI Templates
Project Links
Meta
Author: Ian Stapleton Cordasco
Requires Python: >=3.9
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
Programming Language
- Python
- Python :: 3
- Python :: 3 :: Only
- Python :: Implementation :: CPython
Documentation – GitHub – Travis-CI
Simple python library to deal with URI Templates. The API looks like
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
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
Jun 02, 2025
4.2.0
Oct 13, 2021
4.1.1
Oct 13, 2021
4.1.0
Oct 10, 2021
4.0.0
Dec 19, 2019
3.0.1
Aug 30, 2016
3.0.0
Aug 30, 2016
2.0.0
Aug 23, 2016
2.0.0rc2
Aug 20, 2016
2.0.0rc1
Aug 28, 2013
0.6
Feb 14, 2013
0.5.2
May 11, 2012
0.5.1
May 11, 2012
0.5
Wheel compatibility matrix
Files in release
No dependencies