Skip to main content

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

Tests Status PYPI Version Python Versions

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

muffin-apiclient-3.4.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

muffin_apiclient-3.4.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file muffin-apiclient-3.4.0.tar.gz.

File metadata

  • Download URL: muffin-apiclient-3.4.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for muffin-apiclient-3.4.0.tar.gz
Algorithm Hash digest
SHA256 7d0b77b9a3f809a9b8a51b4f958b31cb3d79a2914fd4f9f9887ad5995699c928
MD5 e4ca782892b7e9cfb6a6c88871b6acb2
BLAKE2b-256 ae2a16fd4a5c4348647ff1c3cefa7b87d7c72fd0d708b2728427a8fddfd27d92

See more details on using hashes here.

File details

Details for the file muffin_apiclient-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: muffin_apiclient-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for muffin_apiclient-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12aa570d16c47c286d8feb16faea0d144d35ee99ecbaba6fb44f1bd1e2b41d54
MD5 b131e1b43f1f152c4d0c611ba862fcf2
BLAKE2b-256 6b6eee2d0d5491f4a75104df8c4af8cda548bf23d262588aee32a48f2162b850

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page