Skip to main content
=====
django_bot_crawler_blocker
=====

This is a simple Django app to block the IP addresses which sends too many hits to your application.
You can decide the number of hits that are allowed per IP address in defined time.


Quick start
-----------

1. Add "django_bot_crawler_blocker" to your INSTALLED_APPS setting like this::

INSTALLED_APPS = [
...
'django_bot_crawler_blocker',
]


2. Add 'CrawlerBlockerMiddleware' to your middleware classes in settings.py file::

MIDDLEWARE = [
'django_bot_crawler_blocker.django_bot_crawler_middleware.CrawlerBlockerMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

'CrawlerBlockerMiddleware' can be and should be first middleware as we need to make sure IP check is the very first
thing in processing request.


3. If cache settings are not defined in your settings.py file, then you need to add below lines to your settings.py file::

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cache_table',
}
}

Make sure you have database settings configured. Run the below command to create cache_table in database::

'python manage.py createcachetable'

You may choose whatever cache backend you want to use.


4. (optional) Set variables in MAX_ALLOWED_HITS_PER_IP and IP_HITS_TIMEOUT in settings.py file::

MAX_ALLOWED_HITS_PER_IP = 2000 # max allowed hits per IP_TIMEOUT time from an IP. Default 2000.
IP_HITS_TIMEOUT = 60 # timeout in seconds for IP in cache. Default 60.

To test on local system, set these values to very low, e.g. IP_HITS_TIMEOUT = 30 and MAX_ALLOWED_HITS_PER_IP = 2.
Restart the server and send requests frequently. After two requests you will start receiving 403 error.
If not defined in settings file, default values will be used.


5. In case of any query or issue, please feel free to reach out to me. Email provided in MANIFEST file.

Release files for django-bot-crawler-blocker 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-bot-crawler-blocker 1.0
File Size Uploaded
django-bot-crawler-blocker-1.0.tar.gz 3.7 kB Details

Release files / django-bot-crawler-blocker-1.0.tar.gz

Download URL django-bot-crawler-blocker-1.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6d0af1a290f5d73199a8ead4a376f3e373c5c914aeb478118582f9269407427c
BLAKE2b-256 checksum
How to use checksums
5deafb7d4406a5fdb29798d62015df44fc2c3caf6e8e72348b6009e0685d3ff4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page