Skip to main content

Basic Sanic API Key plugin.

Project description

Sanic Api Key

Basic support for API Keys. Support form, args, header.


pip install sanicapikey

Example Usage

from sanic import Sanic
from sanic.response import text, json
from SanicApiKey import SanicApiKey

app = Sanic('test')

async def test(request):
    return json({ "error": 'invalid api key' })

auth = SanicApiKey(app, 'api_key', keys=['hello', 'world'], error=test)

# Header:
# auth = SanicApiKey(app, header='api_key', keys=['hello', 'world'], error=test)

# Form
# auth = SanicApiKey(app, form='api_key', keys=['hello', 'world'], error=test)

async def test(request):
    return json({'success': True, 'key': auth.get_token()})

if __name__ == '__main__':'localhost', port=8000)

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

SanicApiKey-1.0.1.tar.gz (2.4 kB view hashes)

Uploaded source

Built Distribution

SanicApiKey-1.0.1-py3-none-any.whl (2.4 kB view hashes)

Uploaded py3

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