Muffin-APIClient -- Its a plugin for Muffin framework which provides support for external APIs
- python >= 3.9
Muffin-APIClient should be installed using pip:
pip install muffin-apiclient
Initialize and setup the plugin:
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)
And etc
Name | Default value | Desctiption |
root_url | None |
Define general root URL for the client |
timeout | None |
Define client timeout |
backend_type | httpx |
APIClient backend (httpx|aiohttp) |
backend_options | {} |
Backend options |
raise_for_status | True |
Raise errors for HTTP statuses (300+) |
read_response_body | True |
Read responses |
parse_response_body | True |
Parse responses (load json, etc) |
client_defaults | {} |
Default client values (headers, auth, etc) |
You are able to provide the options when you are initiliazing the plugin:
apiclient.setup(app, root_url='https://api.github.com')
Or setup it inside Muffin.Application
config using the APICLIENT_
prefix:
APICLIENT_ROOT_URL = 'https://api.github.com'
Muffin.Application
configuration options are case insensitive
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin-apiclient/issues
Development of Muffin-APIClient happens at: https://github.com/klen/muffin-apiclient
- klen (Kirill Klenov)
Licensed under a MIT license.