Skip to main content

A CLI to manage rate limits.

Project description

Adding rate limits to your API

For more detailed documentation check out docs.ratelimit.xyz.

Quickstart

  1. Install the RateLimit CLI.
pip install ratelimitcli
  1. Configure the RateLimit CLI and follow the interactive prompts. You won't have an API key yet so you can just press [ENTER] when asked for a value.
ratelimitcli configure
  1. Request an API key. You'll be asked to enter credit card information.
ratelimitcli billing configure
  1. Check to see that the config file has been written to $HOME/.ratelimit/config
cat ~/.ratelimit/config
  1. Create your first rate limit.
ratelimitcli limits upsert --throttling-burst-limit 2 --throttling-rate-limit 0

Returns

Ok: API response ({"limit_id": "a9f9f31b-2c0b-321b-b398-f9d36kd30820"}).
  1. Test your first rate limit.
ratelimitcli limits record a9f9f31b-2c0b-321b-b398-f9d36kd30820  # ok
ratelimitcli limits record a9f9f31b-2c0b-321b-b398-f9d36kd30820  # ok
ratelimitcli limits record a9f9f31b-2c0b-321b-b398-f9d36kd30820  # error
  1. Test rate limits in an interpreter shell.
>>> from ratelimitcli.client.client import RatelimitClient
>>> client = RatelimitClient(client_id="<email>", api_key="<api_key>")
>>> client.sync_record_request("a9f9f31b-2c0b-321b-b398-f9d36kd30820")
  1. Use your rate limit in your code.
from fastapi import FastAPI
from ratelimitcli.client.client import APIRateLimitException, RatelimitClient as ratelimitclient

app = FastAPI()

def on_error_callback(_: APIRateLimitException):
    return "Goodbye, World!"


@app.get("/")
@ratelimitclient(
    id="a9f9f31b-2c0b-321b-b398-f9d36kd30820",
    callback=on_error_callback,
)
async def hello():
    return "Hello, World!"

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

ratelimitcli-0.1.0.tar.gz (14.3 kB view hashes)

Uploaded Source

Built Distribution

ratelimitcli-0.1.0-py3-none-any.whl (18.1 kB view hashes)

Uploaded Python 3

Supported by

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