• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 6.x
    2. Version 6.x
    3. Version 5.x
    4. Version 4.x
    5. Version 3.x
    6. Version 2.x
    7. Version 2.0
    8. Version 1.0
    9. Version 0.9
    10. Djblets Documentation
    11. Module and Class References
    12. djblets.protect.ratelimit
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Caching Guides
  • Caching Data
  • Working with Cache Keys
  • Cache Backends
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Dynamic Page Injections
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • Protection Guides
  • Rate Limiting Operations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.pagestate
  • djblets.pagestate.injectors
  • djblets.pagestate.middleware
  • djblets.pagestate.state
  • djblets.pagestate.templatetags.djblets_pagestate
  • djblets.extensions
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.requests
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.protect
  • djblets.protect.locks
  • djblets.protect.ratelimit
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • djblets.protect.ratelimit¶

    General support for rate limiting of operations.

    This can be used to impose rate limits on operations or access to resources, locked down to a user, IP, or any other criteria.

    New in version 6.0.

    class RateLimitUsage(count: int, limit: int | None = None, time_left_secs: int | None = None)[source]¶

    Bases: object

    Usage information for a rate limit key.

    This information can be used to determine if a user has any activity remaining before hitting a rate limit, or if they’ve hit the limit.

    New in version 6.0.

    count: int¶

    The number of attempts made against the rate limit key.

    limit: int | None = None¶

    The total number of attempts allowed.

    time_left_secs: int | None = None¶

    The time remaining in seconds before the rate limit resets.

    property is_limited: bool[source]¶

    Whether the usage has hit the rate limit.

    Type:

    bool

    __annotations__ = {'count': 'int', 'limit': 'int | None', 'time_left_secs': 'int | None'}¶
    __dataclass_fields__ = {'count': Field(name='count',type='int',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'limit': Field(name='limit',type='int | None',default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'time_left_secs': Field(name='time_left_secs',type='int | None',default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}¶
    __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)¶
    __eq__(other)¶

    Return self==value.

    __hash__ = None¶
    __init__(count: int, limit: int | None = None, time_left_secs: int | None = None) → None¶
    __match_args__ = ('count', 'limit', 'time_left_secs')¶
    __repr__()¶

    Return repr(self).

    class RateLimit(*, total_limit: int, period_secs: int)[source]¶

    Bases: object

    A rate limit applied to an operation or access.

    This represents the data behind a parsed rate limit imposed on an operation or access to a resource.

    New in version 6.0.

    PERIODS = {'d': 86400, 'h': 3600, 'm': 60, 's': 1}[source]¶

    Dictionary contains keys that represent different time periods.

    The time periods are represented in seconds for days, hours, minutes, and seconds.

    RATE_RE = re.compile('^(\\d+)/(\\d*)([smhd])?$')[source]¶

    Regular expression that interprets the rate string.

    classmethod parse(rate_str: str) → Self[source]¶

    Return a RateLimit parsed from the given rate string.

    Converts the given rate string into a Rate object, which contains the number of login attempts allowed (count) and the time period allotted for these attempts (seconds).

    Parameters:

    rate (str) – The number of attempts allowed within a period of time (can be seconds, minutes, hours, or days).

    Returns:

    The parsed rate limit information.

    Return type:

    RateLimit

    __init__(*, total_limit: int, period_secs: int) → None[source]¶

    Initialize attributes for the Rate object.

    This initializes the number of failed login attempts allowed, and the time period for the login attempts in seconds based on the data returned from the parse() function.

    Parameters:
    • total_limit (int) – The total number of failed attempts allowed.

    • period_secs (int) – The time period in seconds for a rate limit window.

    total_limit: int¶

    The total number of failed attempts allowed.

    period_secs: int¶

    The time period in seconds for a rate limit window.

    get_reset_timestamp(timestamp: int) → int[source]¶

    Return the timestamp until a rate limit is reset.

    This calculates the number of seconds from the given timestamp when a rate limit period will reset.

    Parameters:

    timestamp (int) – The time in seconds used as “now” for the calculation.

    Returns:

    The timestamp at which the rate limit will reset.

    Return type:

    int

    __eq__(other: object) → bool[source]¶

    Return whether the two Rate instances are equal.

    Parameters:

    other (object) – The object to compare to.

    Returns:

    Return true if the count and seconds match.

    Return type:

    bool

    __repr__() → str[source]¶

    Return a string representation of the instance.

    Returns:

    The string representation.

    Return type:

    str

    __annotations__ = {'period_secs': 'int', 'total_limit': 'int'}¶
    __hash__ = None¶
    check_rate_limit(*, rate_limit: RateLimit | str | None, key: str | Sequence[str], increment_count: bool = False) → RateLimitUsage[source]¶

    Return rate limit status for a given key.

    This fetches the rate limit status for a key, optionally incrementing the count towards the limit in the process.

    New in version 6.0.

    Parameters:
    • rate_limit (str or RateLimit) –

      The default limit for any new rate limits.

      This may be a rate limit string or a pre-parsed RateLimit.

      If None, then rate limiting will not be performed. A result with a count of 1 will be returned.

    • key (str or list of str) –

      The rate limit key associated with the rate limit.

      This key is used along with other state to form a cache key. It may be a string or a sequence of components for a key.

    • increment_count (bool, optional) – Whether to increment the count toward the rate limit.

    Returns:

    The resulting rate limit stats for the key.

    Return type:

    RateLimitUsage

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2026 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • RateLimitUsage
      • RateLimitUsage.count
      • RateLimitUsage.limit
      • RateLimitUsage.time_left_secs
      • RateLimitUsage.is_limited
      • RateLimitUsage.__annotations__
      • RateLimitUsage.__dataclass_fields__
      • RateLimitUsage.__dataclass_params__
      • RateLimitUsage.__eq__()
      • RateLimitUsage.__hash__
      • RateLimitUsage.__init__()
      • RateLimitUsage.__match_args__
      • RateLimitUsage.__repr__()
    • RateLimit
      • RateLimit.PERIODS
      • RateLimit.RATE_RE
      • RateLimit.parse()
      • RateLimit.__init__()
      • RateLimit.total_limit
      • RateLimit.period_secs
      • RateLimit.get_reset_timestamp()
      • RateLimit.__eq__()
      • RateLimit.__repr__()
      • RateLimit.__annotations__
      • RateLimit.__hash__
    • check_rate_limit()