Skip to main content

Implementation of RFC 6570 URI Templates

Project description

DocumentationGitHubTravis-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uritemplate-4.2.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

uritemplate-4.2.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file uritemplate-4.2.0.tar.gz.

File metadata

  • Download URL: uritemplate-4.2.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uritemplate-4.2.0.tar.gz
Algorithm Hash digest
SHA256 480c2ed180878955863323eea31b0ede668795de182617fef9c6ca09e6ec9d0e
MD5 c1b679033e9be398232e75ad9e09e8e8
BLAKE2b-256 9860f174043244c5306c9988380d2cb10009f91563fc4b31293d27e17201af56

See more details on using hashes here.

Provenance

The following attestation bundles were made for uritemplate-4.2.0.tar.gz:

Publisher: release.yml on python-hyper/uritemplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uritemplate-4.2.0-py3-none-any.whl.

File metadata

  • Download URL: uritemplate-4.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uritemplate-4.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 962201ba1c4edcab02e60f9a0d3821e82dfc5d2d6662a21abd533879bdb8a686
MD5 9de1bba5e7bffd8c77388ae3b62fee87
BLAKE2b-256 a9993ae339466c9183ea5b8ae87b34c0b897eda475d2aec2307cae60e5cd4f29

See more details on using hashes here.

Provenance

The following attestation bundles were made for uritemplate-4.2.0-py3-none-any.whl:

Publisher: release.yml on python-hyper/uritemplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page