Package: sanic-transmute
BuildDocsPackageEasily 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 ?Atransmuteframework forsanic. This
framework provides:declarative generation of http handler interfaces by parsing function annotationsvalidation and serialization to and from a variety of content types (e.g. json or yaml).validation and serialization to and from native python objects, usingattrsandschematics.autodocumentation of all handlers generated this way, viaswagger.Quick StartOverview:Find Examples here:example with attrs model.example with schematic model.Simple example with schematics model.fromsanicimportSanic,Blueprintfromsanic.responseimportjsonfromsanic_transmuteimportdescribe,add_route,add_swagger,APIExceptionfromsanic.exceptionsimportServerErrorfromschematics.modelsimportModelfromschematics.typesimportIntTypeclassUser(Model):points=IntType()app=Sanic()bp=Blueprint("test_blueprints",url_prefix="/blueprint")@describe(paths="/api/v1/user/{user}/",methods="GET")asyncdeftest_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")asyncdefhandle_exception(request)->User:"""
    API Description: Handle exception. This will show in the swagger page (localhost:8000/api/v1/).
    """raiseServerError("Something bad happened",status_code=500)@describe(paths="/api/v1/user/missing")asyncdefhandle_api_exception(request)->User:"""
    API Description: Handle APIException. This will show in the swagger page (localhost:8000/api/v1/).
    """raiseAPIException("Something bad happened",code=404)@describe(paths="/multiply")asyncdefget_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*rightreturn"{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 blueprintsadd_route(bp,get_blueprint_params)app.blueprint(bp)# add swaggeradd_swagger(app,"/api/v1/swagger.json","/api/v1/")app.run(host="0.0.0.0",port=8000)Simple example with attrs model.fromsanicimportSanic,Blueprintfromsanic.responseimportjsonfromsanic_transmuteimportdescribe,add_route,add_swagger,APIExceptionfromsanic.exceptionsimportServerErrorimportattr@attr.sclassUser:points=attr.ib(type=int)app=Sanic()bp=Blueprint("test_blueprints",url_prefix="/blueprint")@describe(paths="/api/v1/user/{user}/",methods="GET")asyncdeftest_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")asyncdeftest_transmute_post(request,user:User)->User:"""
    API Description: Transmute Post. This will show in the swagger page (localhost:8000/api/v1/).
    """returnuser@describe(paths="/killme")asyncdefhandle_exception(request)->User:"""
    API Description: Handle exception. This will show in the swagger page (localhost:8000/api/v1/).
    """raiseServerError("Something bad happened",status_code=500)@describe(paths="/api/v1/user/missing")asyncdefhandle_api_exception(request)->User:"""
    API Description: Handle APIException. This will show in the swagger page (localhost:8000/api/v1/).
    """raiseAPIException("Something bad happened",code=404)@describe(paths="/multiply")asyncdefget_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*rightreturn"{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 blueprintsadd_route(bp,get_blueprint_params)app.blueprint(bp)# add swaggeradd_swagger(app,"/api/v1/swagger.json","/api/v1/")app.run(host="0.0.0.0",port=8000)DevelopmentBuild../uraniumRun unit tests../uranium test