RFC 6570 URI模板的实现
项目描述
一个简单的Python库,用于处理URI模板。API看起来像
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'}))
当需要此类的地方
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())
当加载包含此类的模块时,GitHubUser.url会被评估,因此模板只创建一次。在Python中,这往往不容易注意到,但对象的创建以及uritemplate所依赖的< span class="docutils literal">re模块都可能消耗大量的时间。构建对象一次可以减少你的代码运行所需的时间。
安装
pip install uritemplate
许可证
修改后的BSD许可协议
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
uritemplate-4.1.1.tar.gz (273.9 kB 查看哈希值)
构建分发
uritemplate-4.1.1-py2.py3-none-any.whl (10.4 kB 查看哈希值)
关闭
uritemplate-4.1.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4346edfc5c3b79f694bccd6d6099a322bbeb628dbf2cd86eea55a456ce5124f0 |
|
MD5 | 6a40709eb966d0a57fea08c3f11ff325 |
|
BLAKE2b-256 | d25a4742fdba39cd02a56226815abfa72fe0aa81c33bed16ed045647d6000eba |
关闭
uritemplate-4.1.1-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 830c08b8d99bdd312ea4ead05994a38e8936266f84b9a7878232db50b044e02e |
|
MD5 | a68f2279025a2610613efb2287eaf463 |
|
BLAKE2b-256 | 81c07461b49cd25aeece13766f02ee576d1db528f1c37ce69aee300e075b485b |