{"id":25061643,"url":"https://github.com/waro163/flask-restframework","last_synced_at":"2025-03-31T11:16:40.765Z","repository":{"id":57430661,"uuid":"396184078","full_name":"waro163/flask-restframework","owner":"waro163","description":"flask restframework, inspired by Django-rest-framework","archived":false,"fork":false,"pushed_at":"2022-01-02T07:44:53.000Z","size":53,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T07:47:19.059Z","etag":null,"topics":["flask","restframework"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waro163.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-15T01:48:32.000Z","updated_at":"2022-09-07T03:20:26.000Z","dependencies_parsed_at":"2022-08-27T22:30:32.490Z","dependency_job_id":null,"html_url":"https://github.com/waro163/flask-restframework","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waro163%2Fflask-restframework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waro163%2Fflask-restframework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waro163%2Fflask-restframework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waro163%2Fflask-restframework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waro163","download_url":"https://codeload.github.com/waro163/flask-restframework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246458009,"owners_count":20780678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","restframework"],"created_at":"2025-02-06T16:53:43.932Z","updated_at":"2025-03-31T11:16:40.721Z","avatar_url":"https://github.com/waro163.png","language":"Python","readme":"# Installation\n\n    pip install flask-rest-framework\n\n# Test\n\n    py.test .\n\n# Overview\nflask-rest-framework is inspired by [Django REST framework](https://github.com/encode/django-rest-framework)\n\nYou can use this extension to develop your rest api quickly based on flask, each view contains this:\n\n* Authentication policies\n* Permission\n* Throttle\n\nand each of them can be customized yourself, all of those are revolved around `User`, so you can define your own\nUser class.\n\n# Example\n\n```python\nfrom flask import Flask,jsonify\nfrom flask_restframework import RestFramework\n\napp = Flask(__name__)\nrf = RestFramework()\nrf.init_app(app)\n\nfrom flask_restframework.views import APIView\nfrom flask_restframework.authentication import BasicAuthentication,JWTAuthentication\nfrom flask_restframework.permissions import AllowAny,IsAuthenticated\n\nclass PingView(APIView):\n\n    authentication_classes=[BasicAuthentication, JWTAuthentication]\n    permission_classes=[IsAuthenticated,]\n    \n    def get(self, *args, **kwargs):\n        return jsonify({\"args\":args,\"kwargs\":kwargs,\"request.args\":request.args})\n\napp.add_url_rule(\"/ping/\u003cstring:name\u003e\",view_func=PingView.as_view('ping'))\n\nif __name__ == \"__main__\":\n    app.run()\n```\n\n# User\n\nif you define your own `User` class, must configure it in flask config env: `FLASK_RESTFRAMEWORK_USER_CLASS`\n\n```python\napp.config['FLASK_RESTFRAMEWORK_USER_CLASS] = 'your_user_class_path.YourUser'\n```\n\nand `User` class must has `is_authenticated` attribute, the type is boolean, this attribute will be used in permission.\n\nmore detail can see `flask_restframework.user.BaseUser`, i recomend your class inherit from it.\n\nwe use the `User` in authentication\n\n# Authenticaion\n\nwe offer `BasicAuthentication` and `JWTAuthentication` authentication class here, you could custom your authentication class or inherit them to complete auth\n\n# Permission\n\n`AllowAny` permission class allows anyone access your API without authentication;\n\n`IsAuthenticated` user must be authenticated before accessing API;\n\n`IsAuthenticatedOrReadOnly` allow anyone access API if request method is safe('get','head','options'), else must be authenticated.\n\n# Throttling\n\nbefore using throttle, we must configure cache to app, else it will not work:\n```\nfrom xxx import Cache\n...\napp = Flask(__name__)\ncache = Cache()\nrf = RestFramework()\nrf.init_app(app,cache)\n...\n```\nhere we offer `AnonRateThrottle` and `UserRateThrottle`.\n\nand the rate of throttling can be set by `second`,`minute`,`hour`,`day`.\n\n```\n...\nclass YourView(APIView):\n    authentication_classes=[BasicAuthentication, JWTAuthentication]\n    throttle_handlers = [{\"class\":AnonRateThrottle,\"rate\":\"1/hour\"},{\"class\":UserRateThrottle,\"rate\":\"10/minute\"}]\n...\n```\n\n### AnonRateThrottle\n\nthe `AnonRateThrottle` is for throttling anonymous user, namely permission class is `AllowAny`, if user is authenticated, it will not limit.\n\n### UserRateThrottle\n\nthe `UserRateThrottle` is for throttling authenticated user, if user is not authenticated, it also work.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaro163%2Fflask-restframework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaro163%2Fflask-restframework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaro163%2Fflask-restframework/lists"}