人道主义者的http。
clients的Python项目详细描述
客户提供requests和 aiohttp鼓励最佳实践的包装, 尤其是始终使用会话连接到同一主机或api端点。
用法
典型的requests用法是多余和低效的, 不利用连接池。
r=requests.get('https://api.github.com/user',headers={'authorization':token})r=requests.get('https://api.github.com/user/repos',headers={'authorization':token})
使用会话是更好的方法, 但是,更详细和实际需要手动url连接。
s=requests.Session()s.headers['authorization']=tokenr=s.get('https://api.github.com/user')r=s.get('https://api.github.com/user/repos')
客户机
客户端通过隐式url连接使会话的使用变得更容易。
client=clients.Client('https://api.github.com/',headers={'authorization':token})r=client.get('user')r=client.get('user/repos')
资源将客户端扩展为隐式处理响应内容, 正确检查状态代码和内容类型。
github=clients.Resource('https://api.github.com/',headers={'authorization':token})forrepoingithub.get('user/repos',params={'visibility':'public'}):...
资源
资源还实现了对getattr和call等方法的语法支持, 为客户提供的大部分好处没有进一步的定义。
forrepoingithub.user.repos(visibility='public'):...
由于是基于会话的,客户机可以与其他requests适配器无缝地工作, 例如CacheControl。 所有客户机类型的异步变体都在Python 3中提供, 使用aiohttp而不是requests。 RPC的其他客户端, 还提供了{A17}和代理。
安装
$ pip install clients
依赖关系
- 请求>;=2.4.2
- aiohttp(如果是python 3)
测试
100%分行覆盖。
$ pytest [--cov]
更改
1.0
- 允许缺少内容类型
- 授权头中支持的OAuth访问令牌
0.5
AsyncClient
默认参数Remote
和AsyncRemote
过程调用Graph
和AsyncGraph
执行GraphQL查询Proxy
和AsyncProxy
客户端
0.4
- 异步客户端和资源
0.3
singleton
装饰器
0.2
- 资源属性向上转换回
client
iter
和download
使用流式内容实现get请求create
实现post请求并返回位置头update
使用json参数实现修补程序请求__call__
使用参数实现get请求