Skip to content

Instantly share code, notes, and snippets.

@Armster15
Created January 11, 2024 00:14
Flask app with rate limits
from flask import Flask, jsonify
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
app = Flask(__name__)
# Configure rate limiting with in-memory storage
limiter = Limiter(
get_remote_address,
app=app,
storage_uri="memory://",
application_limits=["50 per 5 seconds"]
)
# API route with rate limit
@app.route('/', methods=['GET'])
@limiter.limit("50 per 5 seconds")
def get_resource():
return jsonify({'message': 'This is your resource!'})
if __name__ == '__main__':
app.run(debug=True, port=5050)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment