Skip to main content

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

Release files for uritemplate 4.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uritemplate 4.2.0
File Size Uploaded
uritemplate-4.2.0.tar.gz 33.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uritemplate 4.2.0
File Interpreter ABI Platform
uritemplate-4.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.8 kB

Release files / uritemplate-4.2.0.tar.gz

Download URL uritemplate-4.2.0.tar.gz
Size 33.3 kB
Tags Source
SHA-256 checksum
How to use checksums
480c2ed180878955863323eea31b0ede668795de182617fef9c6ca09e6ec9d0e
BLAKE2b-256 checksum
How to use checksums
9860f174043244c5306c9988380d2cb10009f91563fc4b31293d27e17201af56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2025.

Transparency log

Release files / uritemplate-4.2.0-py3-none-any.whl

Download URL uritemplate-4.2.0-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
962201ba1c4edcab02e60f9a0d3821e82dfc5d2d6662a21abd533879bdb8a686
BLAKE2b-256 checksum
How to use checksums
a9993ae339466c9183ea5b8ae87b34c0b897eda475d2aec2307cae60e5cd4f29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

4.2.0 This release

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.0.1

2 release files

3.0.0

3 release files

2.0.0

2 release files

0.6

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page