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.8

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.7.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

muffin_apiclient-3.7.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: muffin-apiclient-3.7.1.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

Hashes for muffin-apiclient-3.7.1.tar.gz
Algorithm Hash digest
SHA256 a8a351570ec7a2971a40a72a8a1a8168101ea030d4975a998e7b439209266e0b
MD5 bfbf952d5681ef3a8d314fbb5cf399c0
BLAKE2b-256 6acbb7014428d9051f0c5f62c55aebee271cdb797e834c6913932ae56d666cf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for muffin_apiclient-3.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0ee78cbc9f16829d21fa530d8886e5773b13aae7e550af2eaf46eb520fe954a
MD5 74313e6ffa672ddc42c9e84cc224bb6e
BLAKE2b-256 ba423c6475a37be4fef6079e396be1c1240f8fefe0792f742f1ec4b072d888a4

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