跳转到主要内容

它是Muffin框架的一个插件,提供了对外部API的支持

项目描述

Muffin-APIClient – 它是Muffin框架的一个插件,提供了对外部API的支持

Tests Status PYPI Version Python Versions

需求

  • 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 (4.3 kB 查看哈希值)

上传时间 源代码

构建版本

muffin_apiclient-3.8.1-py3-none-any.whl (4.6 kB 查看哈希值)

上传时间 Python 3

支持者