Skip to main content

No project description provided

Project description


pip install flask-rest-framework


py.test .


flask-rest-framework is inspired by Django REST framework

You can use this extension to develop your rest api quickly based on flask, each view contains this:

  • Authentication policies
  • Permission
  • Throttle

and each of them can be customized yourself, all of those are revolved around User, so you can define your own User class.


from flask import Flask,jsonify
from flask_restframework import RestFramework

app = Flask(__name__)
rf = RestFramework()

from flask_restframework.views import APIView
from flask_restframework.authentication import BasicAuthentication,JWTAuthentication
from flask_restframework.permissions import AllowAny,IsAuthenticated

class PingView(APIView):

    authentication_classes=[BasicAuthentication, JWTAuthentication]

    def get(self, *args, **kwargs):
        return jsonify({"args":args,"kwargs":kwargs,"request.args":request.args})


if __name__ == "__main__":


if you define your own User class, must configure it in flask config env: FLASK_RESTFRAMEWORK_USER_CLASS

app.config['FLASK_RESTFRAMEWORK_USER_CLASS] = 'your_user_class_path.YourUser'

and User class must has is_authenticated attribute, the type is boolean, this attribute will be used in permission.

more detail can see flask_restframework.user.BaseUser, i recomend your class inherit from it.

we use the User in authentication


we offer BasicAuthentication and JWTAuthentication authentication class here, you could custom your authentication class or inherit them to complete auth


AllowAny permission class allows anyone access your API without authentication;

IsAuthenticated user must be authenticated before accessing API;

IsAuthenticatedOrReadOnly allow anyone access API if request method is safe('get','head','options'), else must be authenticated.


before using throttle, we must configure cache to app, else it will not work:

from xxx import Cache
app = Flask(__name__)
cache = Cache()
rf = RestFramework()

here we offer AnonRateThrottle and UserRateThrottle.

and the rate of throttling can be set by second,minute,hour,day.

class YourView(APIView):
    authentication_classes=[BasicAuthentication, JWTAuthentication]
    throttle_handlers = [{"class":AnonRateThrottle,"rate":"1/hour"},{"class":UserRateThrottle,"rate":"10/minute"}]


the AnonRateThrottle is for throttling anonymous user, namely permission class is AllowAny, if user is authenticated, it will not limit.


the UserRateThrottle is for throttling authenticated user, if user is not authenticated, it also work.

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

flask-rest-framework-0.0.3.tar.gz (12.1 kB view hashes)

Uploaded Source

Built Distribution

flask_rest_framework-0.0.3-py3-none-any.whl (16.6 kB view hashes)

Uploaded Python 3

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