Skip to main content

No project description provided

Project description

build status coverage status

A Sanic extension that generates APIs from python function and classes.

You can find out more here:

http://sanic-transmute.readthedocs.io/en/latest/

What is sanic-transmute ?

A transmute framework for sanic. This framework provides:

  • declarative generation of http handler interfaces by parsing function annotations

  • validation and serialization to and from a variety of content types (e.g. json or yaml).

  • validation and serialization to and from native python objects, using schematics.

  • autodocumentation of all handlers generated this way, via swagger.

Quick Start

A simple example.

from sanic import Sanic, Blueprint
from sanic.response import json
from sanic_transmute import describe, add_route, add_swagger, APIException
from sanic.exceptions import ServerError
from schematics.models import Model
from schematics.types import IntType


class User(Model):
    points = IntType()


app = Sanic()
bp = Blueprint("test_blueprints", url_prefix="/blueprint")


@describe(paths="/api/v1/user/{user}/", methods="GET")
async def test_transmute(request, user: str, env: str=None, group: [str]=None):
    return {
        "user": user,
        "env": env,
        "group": group,
    }


@describe(paths="/killme")
async def handle_exception(request) -> User:
    raise ServerError("Something bad happened", status_code=500)


@describe(paths="/api/v1/user/missing")
async def handle_api_exception(request) -> User:
    raise APIException("Something bad happened", code=404)


@describe(paths="/multiply")
async def get_blueprint_params(request, left: int, right: int) -> str:
    res = left * right
    return "{left}*{right}={res}".format(left=left, right=right, res=res)


if __name__ == "__main__":
    add_route(app, test_transmute)
    add_route(app, handle_exception)
    add_route(app, handle_api_exception)
    # register blueprints
    add_route(bp, get_blueprint_params)
    app.blueprint(bp)
    # add swagger
    add_swagger(app, "/api/v1/swagger.json", "/api/v1/")
    app.run(host="0.0.0.0", 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

sanic-transmute-0.1.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

sanic_transmute-0.1.2-py2.py3-none-any.whl (10.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sanic-transmute-0.1.2.tar.gz.

File metadata

File hashes

Hashes for sanic-transmute-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a3973fc8505062119def2bf740a317104444928c2b00367498de8fa314f8b9c0
MD5 8c1b344c595a799ecec1dcbaf92fbeab
BLAKE2b-256 c47575ef596587955a8fd038250b474fd06efb0cab7cae13018f143ca363ad74

See more details on using hashes here.

File details

Details for the file sanic_transmute-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sanic_transmute-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ff7850980847c346450f2f23881360bc6118257418aa91e6e325bf9e8a8ae218
MD5 5d40bb724ef5eae9fbc264308b5c372e
BLAKE2b-256 003818f82a89ec52531ffbd6e18595b66c08f948845f9bd8309276475773c6de

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