All Projects → yunstanford → Sanic Transmute

yunstanford / Sanic Transmute

Licence: mit
Easily document your Sanic API with Swagger UI, Plus param validation and model serialization.

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Sanic Transmute

Swagger Py Codegen
a Python web framework generator supports Flask, Tornado, Falcon, Sanic
Stars: ✭ 508 (+1109.52%)
Mutual labels:  swagger, sanic
Sanic Ms
基于sanic的微服务基础架构
Stars: ✭ 336 (+700%)
Mutual labels:  swagger, sanic
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+94157.14%)
Mutual labels:  swagger
Rhodddoobie
My little sandbox for playing around with the FP + OOP + DDD combination, in particular using Rho, doobie, Docker, testing, etc in a project.
Stars: ✭ 38 (-9.52%)
Mutual labels:  swagger
Openapi To Graphql
Translate APIs described by OpenAPI Specifications (OAS) into GraphQL
Stars: ✭ 973 (+2216.67%)
Mutual labels:  swagger
Immuni Backend Exposure Reporting
Repository for the Immuni's Exposure Reporting Service
Stars: ✭ 30 (-28.57%)
Mutual labels:  sanic
Blogmanageplatform
一个springboot项目的脚手架,追求简洁高速可扩展。
Stars: ✭ 34 (-19.05%)
Mutual labels:  swagger
Swagger2
Loading, parsing and validating requests to HTTP services based on Swagger v2.0 documents
Stars: ✭ 20 (-52.38%)
Mutual labels:  swagger
Generator Expressjs Rest
Project template for an ExpressJS application
Stars: ✭ 41 (-2.38%)
Mutual labels:  swagger
Suave.swagger
This is an extension for Suave.io with some REST tools and Swagger documentation helpers
Stars: ✭ 34 (-19.05%)
Mutual labels:  swagger
Api4s
Derive Scala code for your HTTP API from swagger!
Stars: ✭ 37 (-11.9%)
Mutual labels:  swagger
Rolodex
📇API Documentation Generator for Phoenix
Stars: ✭ 34 (-19.05%)
Mutual labels:  swagger
Cookiecutter Sanic Microservice
A template for rapid development of Sanic based RESTful Microservices
Stars: ✭ 32 (-23.81%)
Mutual labels:  sanic
Play26 Swagger Reactivemongo
A fully featured CRUD app built with Play 2.6, Swagger and ReactiveMongo
Stars: ✭ 36 (-14.29%)
Mutual labels:  swagger
Sanic Dispatcher
A Dispatcher extension for Sanic which also acts as a Sanic-to-WSGI adapter
Stars: ✭ 29 (-30.95%)
Mutual labels:  sanic
Spring Boot
spring-boot 项目实践总结
Stars: ✭ 989 (+2254.76%)
Mutual labels:  swagger
Ruoyi
(RuoYi)官方仓库 基于SpringBoot的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。直接运行即可用
Stars: ✭ 905 (+2054.76%)
Mutual labels:  swagger
Immuni Backend App Configuration
Repository for the backend app configuration
Stars: ✭ 33 (-21.43%)
Mutual labels:  sanic
Paw Swaggerimporter
Swagger/OpenAPI 2.0 Importer for Paw
Stars: ✭ 34 (-19.05%)
Mutual labels:  swagger
Egg Demo
一个使用eggjs做中间层的简单服务demo,引入了swagger并且支持swagmock,引入vue-ssr后端渲染
Stars: ✭ 41 (-2.38%)
Mutual labels:  swagger

sanic-transmute

.. start-badges

.. list-table:: :stub-columns: 1

* - Build
  - | |travis| |coverage|
* - Docs
  - |docs|
* - Package
  - | |version| |wheel| |supported-versions| |supported-implementations|

.. |travis| image:: https://travis-ci.org/yunstanford/sanic-transmute.svg?branch=master :alt: Travis-CI Build Status :target: https://travis-ci.org/yunstanford/sanic-transmute

.. |coverage| image:: https://coveralls.io/repos/github/yunstanford/sanic-transmute/badge.svg?branch=master :alt: coverage status :target: https://coveralls.io/github/yunstanford/sanic-transmute?branch=master

.. |docs| image:: https://readthedocs.org/projects/sanic-transmute/badge/?style=flat :target: https://readthedocs.org/projects/sanic-transmute :alt: Documentation Status

.. |version| image:: https://img.shields.io/pypi/v/sanic-transmute.svg :alt: PyPI Package latest release :target: https://pypi.python.org/pypi/sanic-transmute

.. |wheel| image:: https://img.shields.io/pypi/wheel/sanic-transmute.svg :alt: PyPI Wheel :target: https://pypi.python.org/pypi/sanic-transmute

.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/sanic-transmute.svg :alt: Supported versions :target: https://pypi.python.org/pypi/sanic-transmute

.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/sanic-transmute.svg :alt: Supported implementations :target: https://pypi.python.org/pypi/sanic-transmute

.. end-badges

Easily document your Sanic API with Swagger UI, Plus param validation and model serialization.

You can find out more here:

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


What is sanic-transmute ?

A transmute <http://transmute-core.readthedocs.io/en/latest/index.html>_ framework for sanic <http://sanic.readthedocs.io/en/latest/>_. 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 attrs <https://www.attrs.org/>_ and schematics <http://schematics.readthedocs.org/en/latest/>_.
  • autodocumentation of all handlers generated this way, via swagger <http://swagger.io/>_.

Quick Start

Overview:

.. figure:: ./examples/code-to-ui.png :align: center :alt: code-to-ui.png

Find Examples here:

  • example with attrs model <https://github.com/yunstanford/sanic-transmute/blob/master/examples/example_attrs_model.py>_.
  • example with schematic model <https://github.com/yunstanford/sanic-transmute/blob/master/examples/example_schematics_model.py>_.

Simple example with schematics model.

.. code-block:: python

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):
    """
    API Description: Transmute Get. This will show in the swagger page (localhost:8000/api/v1/).
    """
    return {
        "user": user,
        "env": env,
        "group": group,
    }


@describe(paths="/killme")
async def handle_exception(request) -> User:
    """
    API Description: Handle exception. This will show in the swagger page (localhost:8000/api/v1/).
    """
    raise ServerError("Something bad happened", status_code=500)


@describe(paths="/api/v1/user/missing")
async def handle_api_exception(request) -> User:
    """
    API Description: Handle APIException. This will show in the swagger page (localhost:8000/api/v1/).
    """
    raise APIException("Something bad happened", code=404)


@describe(paths="/multiply")
async def get_blueprint_params(request, left: int, right: int) -> str:
    """
    API Description: Multiply, left * right. This will show in the swagger page (localhost:8000/api/v1/).
    """
    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)

Simple example with attrs model.

.. code-block:: python

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
import attr


@attr.s
class User:
    points = attr.ib(type=int)


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


@describe(paths="/api/v1/user/{user}/", methods="GET")
async def test_transmute_get(request, user: str, env: str=None, group: [str]=None):
    """
    API Description: Transmute Get. This will show in the swagger page (localhost:8000/api/v1/).
    """
    return {
        "user": user,
        "env": env,
        "group": group,
    }


@describe(paths="/api/v1/user/", methods="POST")
async def test_transmute_post(request, user: User) -> User:
    """
    API Description: Transmute Post. This will show in the swagger page (localhost:8000/api/v1/).
    """
    return user


@describe(paths="/killme")
async def handle_exception(request) -> User:
    """
    API Description: Handle exception. This will show in the swagger page (localhost:8000/api/v1/).
    """
    raise ServerError("Something bad happened", status_code=500)


@describe(paths="/api/v1/user/missing")
async def handle_api_exception(request) -> User:
    """
    API Description: Handle APIException. This will show in the swagger page (localhost:8000/api/v1/).
    """
    raise APIException("Something bad happened", code=404)


@describe(paths="/multiply")
async def get_blueprint_params(request, left: int, right: int) -> str:
    """
    API Description: Multiply, left * right. This will show in the swagger page (localhost:8000/api/v1/).
    """
    res = left * right
    return "{left}*{right}={res}".format(left=left, right=right, res=res)


if __name__ == "__main__":
    add_route(app, test_transmute_get)
    add_route(app, test_transmute_post)
    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)

Development

Build.

.. code::

./uranium

Run unit tests.

.. code::

./uranium test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].