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

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file muffin_apiclient-3.9.0.tar.gz.

File metadata

  • Download URL: muffin_apiclient-3.9.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1012-azure

File hashes

Hashes for muffin_apiclient-3.9.0.tar.gz
Algorithm Hash digest
SHA256 aa2918bb37455895a69e7a3d39b880996bf436d3368ec8e16ef702f264364c30
MD5 448d1c4aaf06a4a22646de2f00e8cc54
BLAKE2b-256 25d9479d0c57805c0791c35a9006e7f81ee88dc57bfbfe7dc9d99015da02f850

See more details on using hashes here.

File details

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

File metadata

  • Download URL: muffin_apiclient-3.9.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1012-azure

File hashes

Hashes for muffin_apiclient-3.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5448f0da9283880b0ad227868c6a0fdc3c6e122e146d853f262685b2d28f63f
MD5 fb9292dec6974e2537411d8b7969adfb
BLAKE2b-256 4d736c39471bc9f4d661ca027c530fb20a6d6d95b27bd8296b84ff2742233c20

See more details on using hashes here.

Supported by

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