它是Muffin框架的一个插件,提供了对外部API的支持
项目描述
Muffin-APIClient – 它是Muffin框架的一个插件,提供了对外部API的支持
需求
python >= 3.9
安装
Muffin-APIClient 应该使用pip安装
pip install muffin-apiclient
用法
初始化和设置插件
import muffin
import muffin_apiclient
# Create Muffin Application
app = muffin.Application('example')
# Initialize the plugin
# As alternative: apiclient = muffin_apiclient.Plugin(app, **options)
apiclient = muffin_apiclient.Plugin()
apiclient.setup(app, root_url='https://api.github.com')
Github API (https://developer.github.com/v4/)
github = muffin_apiclient.Plugin(app, name='github', root_url='https://api.github.com', defaults={
'headers': {
'Authorization': 'token OAUTH-TOKEN'
}
})
# Read information about the current repository
repo = await github.api.repos.klen['muffin-apiclient'].get()
print(repo) # dict parsed from Github Response JSON
Slack API (https://api.slack.com/web)
slack = muffin_apiclient.Plugin(app, name='slack', root_url='https://slack.com/api', defaults={
'headers': {
'Authorization': 'token OAUTH-TOKEN'
}
})
# Update current user status (we don't care about this response)
await client.api['users.profile.set'].post(json={
'profile': {
'status_text': 'working',
'status_emoji': ':computer:'
'status_expiration': 30,
}
}, read_response_body=False)
等等
选项
名称 |
默认值 |
描述 |
root_url |
None |
定义客户端的通用根URL |
timeout |
None |
定义客户端超时 |
backend_type |
httpx |
APIClient后端 (httpx|aiohttp) |
backend_options |
{} |
后端选项 |
raise_for_status |
True |
对于HTTP状态(300+)引发错误 |
read_response_body |
True |
读取响应 |
parse_response_body |
True |
解析响应(加载json等) |
client_defaults |
{} |
默认客户端值(标题,身份验证等) |
您可以在初始化插件时提供这些选项
apiclient.setup(app, root_url='https://api.github.com')
或在内置 Muffin.Application 配置中使用 APICLIENT_ 前缀来设置
APICLIENT_ROOT_URL = 'https://api.github.com'
Muffin.Application 配置选项不区分大小写
错误追踪器
如果您有任何建议、错误报告或烦恼,请向问题跟踪器提交报告 https://github.com/klen/muffin-apiclient/issues
贡献
Muffin-APIClient 的开发发生在这里: https://github.com/klen/muffin-apiclient
贡献者
klen (Kirill Klenov)
许可协议
许可协议为 MIT 协议。
项目详情
下载文件
下载适合您平台的应用程序。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分发
构建版本
muffin_apiclient-3.8.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c7eafaa16c47bf1c372a53ab7abdd04514f931d08234aa765d703a93b12ac846 |
|
MD5 | 35097f825f9342fd2936ebf4a832c7d5 |
|
BLAKE2b-256 | 6225f1c7ffb8f0893b1e677b1445003b3c86370a74f4123123259f8cc95e45db |
muffin_apiclient-3.8.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e2f7651dd0bfad6b01d91a8a358ded362c462c630a680948c33c6b619d707777 |
|
MD5 | 7e71911112a1198f3f84d2fc5016ca02 |
|
BLAKE2b-256 | 4e0763bdf754f1a6099f1cf76e82f7be04b2938a0f21df8c036d645c376f3d60 |