Skip to main content

Djano-Anti-Crawler

PyPI version

A light weight anti crawler Django app which blocks 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.

Installation

  1. Install via pip

    pip install django-anti-crawler
    

Quick start

  1. Add django_anti_crawler to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        ...
        'django_anti_crawler',
    ]
    
  2. Add 'DjangoAntiCrawlerMiddleware' to your middleware classes in settings.py file::

    MIDDLEWARE = [
        'django_anti_crawler.middlewares.DjangoAntiCrawlerMiddleware',
        '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',
    ]
    

    DjangoAntiCrawlerMiddleware 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.

  5. (optional) Set variable ANTI_CRAWLER_WHITELIST_BOTS and IP_HITS_TIMEOUT in settings.py file to whitelist specific bots or Ips::

    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.

Authors

Licensing

The project is MIT Licenced.

Metadata

Release files for django-anti-crawler 0.5

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-anti-crawler 0.5
File Size Uploaded Provenance Actions
django_anti_crawler-0.5.tar.gz 3.1 kB Without provenance Details for django_anti_crawler-0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-anti-crawler 0.5
File Interpreter ABI Platform Actions
django_anti_crawler-0.5-py3-none-any.whl Python 3 none any Details for django_anti_crawler-0.5-py3-none-any.whl

Total release size: 7.6 kB

Release files / django_anti_crawler-0.5.tar.gz

Download URL django_anti_crawler-0.5.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bfa0d26e1b1345cd495a3abf35957fc0226284059fc7c30b7857f4a3e0bc12ee
BLAKE2b-256 checksum
How to use checksums
8d78edd8aced388ffc7ef23f4ca34ad7250b820d98da15937ef618ed44488119
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.5

Release files / django_anti_crawler-0.5-py3-none-any.whl

Download URL django_anti_crawler-0.5-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bd3e12dbd2dd963416c84940e74d966f8cf725362b46499832914c59298eff3
BLAKE2b-256 checksum
How to use checksums
c85d3c01f56b4385a9a785af66c514502bb0a2711c527f0e9325073e45273f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.5

Security for django-anti-crawler 0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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