Skip to main content

Rate limiting middleware for APIs

Project description

RateLimitAPI for Python

PyPI version License: MIT GitHub Actions publish workflow status

This package is currently in early development and not ready for production use.

Features, API, and documentation are subject to change. We are actively working to stabilize the package for a production release.

Overview

RateLimitAPI is a powerful rate limiting middleware for APIs, it is currently under development. It provides a simple yet robust solution for implementing industry-standard rate limiting to protect your endpoints from abuse.

Features (Planned)

  • Easy-to-use middleware for popular frameworks (Flask, Django, FastAPI)
  • Flexible rate limit configuration
  • Customizable response formats for rate limit headers
  • Detailed analytics and monitoring
  • Protection against common abuse patterns

Installation

pip install ratelimitapi

or

poetry add ratelimitapi

Documentation

Full documentation will be available at RateLimitAPI.com upon official release.

Usage Preview

Basic Usage

from ratelimitapi import is_rate_limited

def handle_request(request):
    limited_response = is_rate_limited(request, "rlimit_your_token_here")
    if limited_response:
        response_body, status_code, headers = limited_response
        # Return the 429 response if rate-limited
        return create_response(response_body, status_code, headers)
        
    # Continue with normal request handling if not rate-limited
    # ...

Flask Integration Example

from flask import Flask, request, jsonify
from ratelimitapi import is_rate_limited

app = Flask(__name__)

@app.route('/api/resource')
def api_resource():
    # Check for rate limiting
    limited_response = is_rate_limited(request, "rlimit_your_token_here")
    if limited_response:
        response_body, status_code, headers = limited_response
        return jsonify(response_body), status_code, headers
        
    # Process the request normally
    return jsonify({"message": "Request processed successfully"})

Django Integration Example

from django.http import JsonResponse
from ratelimitapi import is_rate_limited

def api_view(request):
    # Check for rate limiting
    limited_response = is_rate_limited(request, "rlimit_your_token_here")
    if limited_response:
        response_body, status_code, headers = limited_response
        response = JsonResponse(response_body, status=status_code)
        for key, value in headers.items():
            response[key] = value
        return response
        
    # Process the request normally
    return JsonResponse({"message": "Request processed successfully"})

License

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

Stay Updated

  • Star our GitHub repository
  • Follow our progress on Twitter (coming soon)
  • Join our community Discord (coming soon)

Contact

For more information, please visit RateLimitAPI.com when it's available.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ratelimitapi-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ratelimitapi-0.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file ratelimitapi-0.1.1.tar.gz.

File metadata

  • Download URL: ratelimitapi-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ratelimitapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c6aba2bc8a236c819cd07bbeed03d94d5fd73d6e3b956ec89272df21f4770db7
MD5 381d5ad44cf7188d01aeffd114ca181d
BLAKE2b-256 47c1185e1b7c5b7c50a8b6b9a77136e62b1c66d1cf6e7fd400bd0d44e5485535

See more details on using hashes here.

File details

Details for the file ratelimitapi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ratelimitapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ratelimitapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c35f1e2d560fde9a906060275aeb8e55b7dd9c21b43cd92cc67841bd74e64318
MD5 b252184cba401d276d0a6c0b97f7b56a
BLAKE2b-256 fb0f7b3b033221e6b00c7ca1f547a26775ae5dc009cb7644efda81e880eead8c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page