Implementation of RFC 6570 URI Templates
Reason this release was yanked:
Invalid python_requires and classifiers due to mistake
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file uritemplate-4.1.0.tar.gz
.
File metadata
- Download URL: uritemplate-4.1.0.tar.gz
- Upload date:
- Size: 273.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69387b2f904692c61e01acf38b72211fbe8a01d93ec9d5e6fd215c1346393b8d |
|
MD5 | 41a7400594e165838423ebf24f79cf0e |
|
BLAKE2b-256 | 2ba4c336e6a26a53fce0ab86f1c8ae5054e477bb0a42d88348d57e2136df036b |
File details
Details for the file uritemplate-4.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: uritemplate-4.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70c68e8613ca3448ccb4d8de6537f3c211748c7aa7ed8c9f1e7c87bf6cc56171 |
|
MD5 | 1b998c259c528765e818690c9e9ac371 |
|
BLAKE2b-256 | cacc15f56828f4feda8dacfd868f03c0d67c7fb5d0b4f069ac4c9d6ee0626a93 |