class evennia.server.throttle.Throttle(**kwargs)[source]

Bases: object

Keeps a running count of failed actions per IP address.

Available methods indicate whether or not the number of failures exceeds a particular threshold.

This version of the throttle is usable by both the terminal server as well as the web server, imposes limits on memory consumption by using deques with length limits instead of open-ended lists, and uses native Django caches for automatic key eviction and persistence configurability.

error_msg = 'Too many failed attempts; you must wait a few minutes before trying again.'

Allows setting of throttle parameters.

Keyword Arguments
  • name (str) – Name of this throttle.

  • limit (int) – Max number of failures before imposing limiter. If None, the throttle is disabled.

  • timeout (int) – number of timeout seconds after max number of tries has been reached.

  • cache_size (int) – Max number of attempts to record per IP within a rolling window; this is NOT the same as the limit after which the throttle is imposed!

get_cache_key(*args, **kwargs)[source]

Creates a ‘prefixed’ key containing arbitrary terms to prevent key collisions in the same namespace.

touch(key, *args, **kwargs)[source]

Refreshes the timeout on a given key and ensures it is recorded in the key register.


key (str) – Key of entry to renew.


Convenience function that returns the storage table, or part of.


ip (str, optional) – IP address of requestor


storage (dict)

When no IP is provided, returns a dict of all

current IPs being tracked and the timestamps of their recent failures.

timestamps (deque): When an IP is provided, returns a deque of

timestamps of recent failures only for that IP.

update(ip, failmsg='Exceeded threshold.')[source]

Store the time of the latest failure.

  • ip (str) – IP address of requestor

  • failmsg (str, optional) – Message to display in logs upon activation of throttle.



remove(ip, *args, **kwargs)[source]

Clears data stored for an IP from the throttle.


ip (str) – IP to clear.

record_ip(ip, *args, **kwargs)[source]

Tracks keys as they are added to the cache (since there is no way to get a list of keys after-the-fact).


ip (str) – IP being added to cache. This should be the original IP, not the cache-prefixed key.

unrecord_ip(ip, *args, **kwargs)[source]

Forces removal of a key from the key registry.


ip (str) – IP to remove from list of keys.


This will check the session’s address against the storage dictionary to check they haven’t spammed too many fails recently.


ip (str) – IP address of requestor


throttled (bool)

True if throttling is active,

False otherwise.