It's a plugin for Muffin framework which provides support for external APIs
Project description
Muffin-APIClient – Its a plugin for Muffin framework which provides support for external APIs
Requirements
python >= 3.7
Installation
Muffin-APIClient should be installed using pip:
pip install muffin-apiclient
Usage
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
Options
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
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin-apiclient/issues
Contributing
Development of Muffin-APIClient happens at: https://github.com/klen/muffin-apiclient
Contributors
klen (Kirill Klenov)
License
Licensed under a MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file muffin-apiclient-3.6.0.tar.gz
.
File metadata
- Download URL: muffin-apiclient-3.6.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc8333e01670c4847d889dba65cafda13937fa6ba859cba8cb8d60e80bad0c3 |
|
MD5 | c55e453754edea7efa1c67a58d952458 |
|
BLAKE2b-256 | 606aa827626a6e2030242275cd183fe6499e4b6924591b0ec31eb29ccadc9ce4 |
File details
Details for the file muffin_apiclient-3.6.0-py3-none-any.whl
.
File metadata
- Download URL: muffin_apiclient-3.6.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bf229f5001c064b658e19b6b44207225d6cf7ab177bd76e4d82357e7469ed19 |
|
MD5 | 962972cd508cd9cee0cb4df7376894f8 |
|
BLAKE2b-256 | 606126e858f44e980c71d9bf16f8ac08d482038250c86794751003f2b055c578 |