与restfulapi交互的一种简洁的表达方式。

chain-p的Python项目详细描述


Latest PyPI versionLatest Travis CI build status

与restfulapi交互的一种简洁的表达方式。它的灵感来自zmallen’s pygraylog

chain是流行的requests包的一个小增强。通过将端点引用为 属性,它有效地将端点“链接”在一起,构建目标url。

chain是通过删除 代码中硬编码的url字符串。

chain使用requests包作为其http客户端,保留其参数和响应对象。 如果您已经使用requests作为http客户端,那么采用chain将很容易。

用法

例如this API

# create a new client for the API
>>> importchain>>> blogs=chain.Client('http://jsonplaceholder.typicode.com')
# if you want the posts:
>>> response=blogs.get.posts()
# the response is the response object from the requests package
>>> printresponse.json()

数字和特殊字符也支持使用字典符号

# Get the first post
>>> response=blogs.get.posts[1]()>>> printresponse.json()

链参数是请求。请求参数:

# parameters are the same as requests.requests parameters
>>> response=blogs.get.comments(params={'postId':'1'})>>> printresponse.json()>>> comment={'postId':1,'id':501,'name':'chain','email':'chain@code.com','body':'meh.'}>>> response=blogs.post.comments(json=comment)

安装

pip install chain_py

测试

python setup.py test

或:

tox

兼容性

适用于Python 2.7、3.3、3.4、3.5和3.6版

许可证

麻省理工学院许可。请求由apache许可证授权。请参见完整的LICENSE

作者

chain是由Anfernee Jervis编写的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用split函数分割字符串,但没有得到期望的结果   未找到包含derby数据库嵌入架构的sql Java桌面应用程序错误   java elasticsearch vs solr用于定制全文搜索系统   java Android:创建没有startOffset的动画延迟?   java如何查看其他应用程序接收的数据?   java如何在Linux中使用D和classpath选项运行jar文件   java和域设计最佳实践   具有相同内存位置的java数组,将显示为输出   连接到java中的elasticsearch?   Java Playframework重定向到带有Json负载的外部url   java无法在Android平台上使用InputStream为蓝牙socket创建ObjectInputStream   使用POI将Excel日期转换为Java日期,年份未正确显示   oracle从数据库层还是Java层调用webservice?