Package: walmart-cloudsec-flask-restplus
Flask-RESTPlus is an extension forFlaskthat adds support for quickly building REST APIs.
Flask-RESTPlus encourages best practices with minimal setup.
If you are familiar with Flask, Flask-RESTPlus should be easy to pick up.
It provides a coherent collection of decorators and tools to describe your API
and expose its documentation properly usingSwagger.CompatibilityFlask-RestPlus requires Python 2.7 or 3.4+.InstallationYou can install Flask-Restplus with pip:$pipinstallflask-restplusor with easy_install:$easy_installflask-restplusQuick startWith Flask-Restplus, you only import the api instance to route and document your endpoints.fromflaskimportFlaskfromflask_restplusimportApi,Resource,fieldsapp=Flask(__name__)api=Api(app,version='1.0',title='TodoMVC API',description='A simple TodoMVC API',)ns=api.namespace('todos',description='TODO operations')todo=api.model('Todo',{'id':fields.Integer(readOnly=True,description='The task unique identifier'),'task':fields.String(required=True,description='The task details')})classTodoDAO(object):def__init__(self):self.counter=0self.todos=[]defget(self,id):fortodoinself.todos:iftodo['id']==id:returntodoapi.abort(404,"Todo{}doesn't exist".format(id))defcreate(self,data):todo=datatodo['id']=self.counter=self.counter+1self.todos.append(todo)returntododefupdate(self,id,data):todo=self.get(id)todo.update(data)returntododefdelete(self,id):todo=self.get(id)self.todos.remove(todo)DAO=TodoDAO()DAO.create({'task':'Build an API'})DAO.create({'task':'?????'})DAO.create({'task':'profit!'})@ns.route('/')classTodoList(Resource):'''Shows a list of all todos, and lets you POST to add new tasks'''@ns.doc('list_todos')@ns.marshal_list_with(todo)defget(self):'''List all tasks'''returnDAO.todos@ns.doc('create_todo')@ns.expect(todo)@ns.marshal_with(todo,code=201)defpost(self):'''Create a new task'''returnDAO.create(api.payload),201@ns.route('/<int:id>')@ns.response(404,'Todo not found')@ns.param('id','The task identifier')classTodo(Resource):'''Show a single todo item and lets you delete them'''@ns.doc('get_todo')@ns.marshal_with(todo)defget(self,id):'''Fetch a given resource'''returnDAO.get(id)@ns.doc('delete_todo')@ns.response(204,'Todo deleted')defdelete(self,id):'''Delete a task given its identifier'''DAO.delete(id)return'',204@ns.expect(todo)@ns.marshal_with(todo)defput(self,id):'''Update a task given its identifier'''returnDAO.update(id,api.payload)if__name__=='__main__':app.run(debug=True)ContributorsFlask-RESTPlus is brought to you by @noirbizarre. Since early 2019 @SteadBytes,
@a-luna, @j5awry, @ziirish volunteered to help @noirbizarre keep the project up
and running.
Of course everyone is welcome to contribute and we will be happy to review your
PR’s or answer to your issues.DocumentationThe documentation is hostedon Read the DocsContributionWant to contribute! That’s awesome! Check outCONTRIBUTING.rst!Changelog
=========CurrentEnsure that exceptions raised in error handler, including programming errors, are logged (#705,#706)Import the ABCs from ‘collections.abc’ instead of ‘collections’ by default as it is deprecated since Python3.7, and in 3.8 it will stop working. Python2.7 is still supported though.Fix illegal characters in JSON references to model names (#651)Supportenvelopeparameter in Swagger documentation (#390)0.13.0 (2019-08-12)Add newWildcardfields (#255)Fix ABC deprecation warnings (#580)Fix@api.expect(…, validate=False)decorators for anApiwherevalidate=Trueis set on the constructor (#609,#610)EnsurebasePathis always a pathHide Namespaces with all hidden Resources from Swagger documentationPer route Swagger documentation for multiple routes on aResourceFix Swaggerduplicate mapping keyproblem from conflicts between response codes given as string or integer (:issue`661`)0.12.1 (2018-09-28)Fix missing changelog inprevious releaseEnsure definitions with both$refand description (or other property) output is valid (usingallOf)Added initial specifications schemas and validation supportEnsure empty enums are not serialized (to have a valid specification)0.12.0 (2018-09-27)Fix Namespace decorators (#475)Do not serialize empty tags descriptionsEnsureconsumesis properly set when using form parameters on classesEnsure parameters are not duplicated (#164,#196,#234)Publish sources distribution (#500,#515)Fix late resources registeration (#483)Don’t include namespaces without resources to the SWAGGER documentation (#470)Add support for checkbox validation input + consistent behavior between inputs and fields. (#461)Fix missingenum34dependency (#444)0.11.0 (2018-05-16)Add authorizations parsing to namespace (#403)Add vendor extensions support (#97)RequestParserarguments now support thesplitactionEnsure default boolean value asFalseworks withRequestParser(#199)Schema errors are not longuer hidden byAttributeError: Api does not have __schema__ attribute(#194)Add a newURLvalidator, more flexible and precise.Fix error bundling (#175,#144)Help message is now added to source error message instead of string interpolation (#147)Use pytest instead of nosetestsUpgrade to Swagger-UI 3.4.0Fix typo in commentsAdd an optional key argument,skip_none, inmarshal_withandmarshalFix masks not working correctly with Python 2.7 (#217)Fixed typos in doc/scalingAdd docs forallow_nullandNestedAdd Namespace.payloadBreaking: everything is unordered by default because ordering has a serious impact on performances:ApiandNamespacenow accept an optionnalorderedparametermarshal_withandmarshalnow accept an optionnalorderedparameterBreaking changesDrop python 2.6 supportImprove header handling (#119):@api.headeronly document response headers on all responses@api.responseaccept an optionnalheadersargument to document response specific headersrequest header are handled by the@api.expectdecorator0.10.1 (2017-03-04)Fix a typo in__init__breakingfrom flask_restplus import *(#242)Basic support for custom URL converters (#243)Support custom response classes inheriting fromBaseResponse(#245)Allow models to preserve order (#135)0.10.0 (2017-02-12)Allows to specify a custom mount path on namespace registrationAllow to express models as raw schemasUpgraded to Swagger-UI 2.2.6Support Swagger-UI translationsFix prefix trailing slash stripping in Postman doc generation (#232)Add validation for lists in the expect decorator (#231)0.9.2 (2016-04-22)Same version but a PyPI bug force reupload.0.9.1 (2016-04-22)Added some Swagger-UI Oauth configurations:SWAGGER_UI_OAUTH_CLIENT_IDSWAGGER_UI_OAUTH_REALMSWAGGER_UI_OAUTH_APP_NAMEExposetype: objectin Swagger schemas (#157)Fix an issue with error handlers (#141)Fix an issue with Postman export when using OAuth (#151)Miscellenaous code and documentation fixesRemove last flask-restful references (unless needed) and add missing attributions0.9.0 (2016-02-22)MakeNamespacebehave likeBlueprintforFlaskDeprecatedparserandbodyparameters forexpectindocdecoratorDeprecatedModel.extendin favor ofModel.cloneAdded theparamdecoratorHonour method restrictions in Swagger documentation (#93)Improved documentation0.8.6 (2015-12-26)Handle callable on API infosHandle documentation on error handlersDrop/merge flask_restfulflask_restful.RequestParserHandleRequestParserintoexpectdecoratorHandle schema forinputsparsersAdded some inputs:emailipipv4ipv60.8.5 (2015-12-12)Handle mask onPolymorphfieldHandle mask on inherited modelsReplaceflask_restful.abortbyflask_restplus.errors.abortReplaceflask_restful.unpackbyflask_restplus.utils.unpackBreaking changes:RenamedApiModelintoModelRenamedApiNamespaceintoNamespace0.8.4 (2015-12-07)Drop/mergeflask_restful.Resourceresolving a recursion problemAllow anycallableas fielddefault,min,max…AddedDatefieldImprove error handling for inconsistent masksHandle model level default masksupport colons and dashes in mask field namesBreaking changes:Renamedexceptionsmodule intoerrorsRenamedRestExceptionintoRestErrorRenamedMarshallingExceptionintoMarshallingErrorDateTimefield always output datetime0.8.3 (2015-12-05)Drop/merge flask-restful fieldsDrop/merge flask-restplus inputsUpdate Swagger-UI to version 2.1.3Use minified version of Swagger-UI ifDEBUG=FalseBlueprint subdomain support (static only)Added support for default fields mask0.8.2 (2015-12-01)Skip unknown fields in mask when applied on a modelAdded*token to fields mask (all remaining fields)Ensure generated endpoints does not collideDrop/merge flask-restfulApi.handler_error()0.8.1 (2015-11-27)Refactor Swagger UI handling:allow to register a custom view with@api.documentationallow to register a custom URL with thedocparameterallow to disable documentation withdoc=FalseAdded fields mask support through header (see:Fields Masks Documentation)Exposeflask_restful.inputsmodule onflask_restplus.inputsAdded support for some missing fields and attributes:hostroot field (filed only ifSERVER_NAMEconfig is set)customtagsroot fieldexclusiveMinimumandexclusiveMaximumnumber field attributesmultipleOfnumber field attributeminLengthandmaxLengthstring field attributespatternstring field attributeminItemsandmaxItemslist field attributesuniqueItemslist field attributeAllow to override the default error handlerFixes0.8.0Added payload validation (initial implementation based on jsonschema)Added@api.deprecatedto mark resources or methods as deprecatedAdded@api.headerdecorator shortcut to document headersAdded Postman exportFix compatibility with flask-restful 0.3.4Allow to specify an exemple a custom fields with__schema_example__Added support forPATCHmethod in Swagger UIUpgraded to Swagger UI 2.1.2Handle enum as callableAllow to configuredocExpansionwith theSWAGGER_UI_DOC_EXPANSIONparameter0.7.2Compatibility with flask-restful 0.3.3Fix action=append handling in RequestParserUpgraded to SwaggerUI 2.1.8-M1Miscellaneous fixes0.7.1Fix@api.marshal_with_list()keyword arguments handling.0.7.0Expose models and fields schema through the__schema__attributeDrop support for model as classAdded@api.errorhandler()to register custom error handlersAdded@api.response()shortcut decoratorFix list nested models missing in definitions0.6.0Python 2.6 supportExperimental polymorphism support (single inheritance only)AddedPolymorphfieldAddeddiscriminatorattribute support onStringfieldsAddedapi.inherit()methodAddedClassNamefield0.5.1Fix for parameter with schema (do not set type=string)0.5.0Allow shorter syntax to set operation id:@api.doc('my-operation')Added a shortcut to specify the expected input model:@api.expect(my_fields)Addedtitleattribute to fieldsAdded@api.extend()to extend modelsEnsure coherence betweenrequiredandallow_nullforNestedFieldSupport list of primitive types and list of models as bodyUpgraded to latest version of Swagger UIFixes0.4.2Rename apidoc blueprint into restplus_doc to avoid collisions0.4.1AddedSWAGGER_VALIDATOR_URLconfig parameterAddedreadonlyfield parameterUpgraded to latest version of Swagger UI0.4.0Port to Flask-Restful 0.3+Use the default Blueprint/App mecanismAllow to hide some ressources or methods using@api.doc(False)or@api.hideAllow to globally customize the default operationId with thedefault_idcallable parameter0.3.0Switch to Swagger 2.0 (Major breakage)notesdocumentation is nowdescriptionnicknamedocumentation is nowidnew responses declaration formatAdded missingbodyparameter to documentbodyinputLast release before Flask-Restful 0.3+ compatibility switch0.2.4Handledescriptionandrequiredattributes onfields.List0.2.3Fix custom fields registeration0.2.2Fix model list in declaration0.2.1Allow to type custom fields withApi.modelHandle custom fields intofieds.List0.2Upgraded to SwaggerUI 0.2.22Support additional field documentation attributes:required,description,enum,min,maxanddefaultInitial support for model in RequestParser0.1.3FixApi.marshal()shortcut0.1.2AddedApi.marshal_with()andApi.marshal_list_with()decoratorsAddedApi.marshal()shortcut0.1.1Usezip_safe=Falsefor proper packaging.0.1Initial release