Skip to content

Expose Limit dataclasses in public API #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025
Merged

Conversation

alisaifee
Copy link
Owner

Description

This change exposes the internal dataclasses used to define rate limiting rules for default, application, per-route or blueprint & meta limits for use cases that require more fine grained configuration of the rate limiter.

Some of the use cases this unlocks are:

  • Different key_functions for different default limits
  • Different exemption rules for different default limits
  • Per limit meta limit(s) including decorated limits

Copy link

hyperlint-ai bot commented Apr 23, 2025

PR Change Summary

Exposed internal dataclasses for rate limiting configuration in the public API.

  • Exposed Limit, ApplicationLimit, MetaLimit, and RouteLimit dataclasses in the public API.
  • Enabled more granular configuration options for rate limiting rules.
  • Facilitated different key functions and exemption rules for various default limits.

Modified Files

  • doc/source/api.rst

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

@alisaifee alisaifee linked an issue Apr 23, 2025 that may be closed by this pull request
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (af85cf6) to head (93b7cbb).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #471   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          967       995   +28     
=========================================
+ Hits           967       995   +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alisaifee alisaifee force-pushed the public-limit-definition branch from f047297 to 9619479 Compare April 23, 2025 16:58
The internal wrappers.LimitGroup and the LimitDecorator
exposed by the Limiter.limit & Limit.shared_limit decorators
had a lot of overlapping functionality and by collapsing them
into flask_limiter.Limit, flask_limiter.RouteLimit,
flask_limiter.ApplicationLimit & flask_limiter.MetaLimit.

Limit (and it's subclasses) can now be used to pass in definitions for default,
application & meta limits.

RouteLimit can be constructed with an additional limiter parameter and
then used to decorate routes or blueprints directly, instead of going
through Limiter.limit or Limiter.shared_limit

Additionally, meta_limits can now be passed in to decorated limits and
also configured on default & application limits individiually instead of
globally.
@alisaifee alisaifee force-pushed the public-limit-definition branch from 9619479 to ed416d6 Compare April 23, 2025 16:59
@alisaifee alisaifee merged commit 6fbd592 into master Apr 23, 2025
45 checks passed
@alisaifee alisaifee deleted the public-limit-definition branch April 23, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved limiter config and dynamic limits
1 participant