Skip to main content

django-ratelimit-middleware

codecov Python - >=3.12 Django - >=5.2 Style - Black

🌟 Overview

Django Rate Limit Middleware is a simple, lightweight Django middleware for rate limiting requests based on user identity or IP address.
It helps prevent abuse, brute force attacks, and excessive traffic with minimal configuration.

✨ Features

  • 🔑 Supports anonymous and authenticated users
  • ⏱ Configurable request count and time window
  • 🧠 Uses Django’s cache framework
  • 🪶 Lightweight, dependency-free

📦 Installation

pip install django-ratelimit-middleware

⚙️ Configuration

Add to your MIDDLEWARE:

MIDDLEWARE = [
    ...
    "django_ratelimit_middleware.middleware.RateLimitMiddleware",
]

Add settings:

RATE_LIMIT_REQUESTS = 100       # Number of requests allowed
RATE_LIMIT_WINDOW = 60          # Window in seconds

🚀 Usage

After installation and config, all views are automatically rate-limited.
Example response when exceeding the limit:

HTTP/1.1 429 Too Many Requests
Retry-After: 60

🧪 Running Tests

pytest

📊 Coverage

Coverage reports are uploaded to Codecov

🤝 Contributing

Contributions are welcome! 🎉

See CONTRIBUTING.md for details.

📌 Roadmap

  • Custom rate limit strategies (e.g., per endpoint)
  • Redis backend example
  • Admin dashboard for monitoring blocked IPs
  • Configurable responses (JSON, HTML)
  • Turnstile feature

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement.
In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Use at your own risk.

👨‍💻 Author

Maintained with ❤️ by K3y5tr0k3.

Metadata

Release files for django-ratelimit-middleware 0.1.1

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-ratelimit-middleware 0.1.1
File Size Uploaded Provenance Actions
django_ratelimit_middleware-0.1.1.tar.gz 8.7 kB Without provenance Details for django_ratelimit_middleware-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-ratelimit-middleware 0.1.1
File Interpreter ABI Platform Actions
django_ratelimit_middleware-0.1.1-py3-none-any.whl Python 3 none any Details for django_ratelimit_middleware-0.1.1-py3-none-any.whl

Total release size: 14.0 kB

Release files / django_ratelimit_middleware-0.1.1.tar.gz

Download URL django_ratelimit_middleware-0.1.1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eb0b35002864469306feca371cf52248ca31f79d8b97fa7280ded4865834c380
BLAKE2b-256 checksum
How to use checksums
0a644f32623d481b64cc2740667335db6f09284fe05b04739a2d049287aacf2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / django_ratelimit_middleware-0.1.1-py3-none-any.whl

Download URL django_ratelimit_middleware-0.1.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd295193bb7de7eb590b1ac0b0fb7f57c8e8029baab0945797b0aded4e71f26e
BLAKE2b-256 checksum
How to use checksums
e7944056620c9d324300da561c5746f2d5d082f548dc6407b949463f0c910ad7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for django-ratelimit-middleware 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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