Closed theveloped closed 5 years ago
It seems that Flask-Limiter should just work fine.
Awesome! Will give it a go and report back on how it turns out.
It seems simply adding it straight to the extensions __init__.py
file will get the job done. Here is a snippet from my init file:
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
limiter = Limiter(key_func=get_remote_address, default_limits=["1 per minute"])
from . import api
def init_app(app):
"""
Application extensions initialization.
"""
for extension in (
logging,
cross_origin_resource_sharing,
login_manager,
marshmallow,
api,
oauth2,
limiter,
):
extension.init_app(app)
I'm however still having trouble on getting it to run with route or resource specific limits using the limiter decorators.
@theveloped what specific issue are you having ?
After adding limiter through extension as you did, a simple snippet like follow works for me for what flask-limiter promised:
note: set limiter decorator via decorator variable
from app.extensions import limiter
// .... ignore all other resources
@api.route('/account/verify')
class IdentityVerify(Resource):
"""
Handle identity verification.
"""
decorators = [limiter.limit("10/second")] # Notice this is different from the simple example
@api.parameters(parameters.SomeParameters())
@api.response(schemas.SomeSchema())
def post(self, args):
return {"verified": True}
Reference this for more details why decorating functions or class won't work: https://flask-limiter.readthedocs.io/en/stable/#using-flask-pluggable-views
@theveloped can you confirm if the way demonstrated in the snippet above work for you ?
@frol We might as well include the example into main README for people who might be interested in integrating flask-limiter with this project :)
@10000TB There is "Q&A about this project" link at the end of the README, which points to the issues tagged as "question".
Hi @10000TB, Indeed this is how I've added it and it works exactly as promised!
@theveloped Thanks to @10000TB effort, there is now a section in the README about Flask-* integration
I'm wondering or anyone has implemented a form of rate limiting that works with a
flask-restplus-patched
project? Flask-Limiter looks like a really nice project but will probably need some work getting it to work with this project.