A CLI to manage rate limits.
Project description
Adding rate limits to your API
For more detailed documentation check out https://docs.ratelimit.xyz.
Quickstart
- Install the RateLimit CLI.
pip install ratelimitcli
- 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
- Request an API key. You'll be asked to enter credit card information.
ratelimitcli billing configure
- Check to see that the config file has been written to
$HOME/.ratelimit/config
cat ~/.ratelimit/config
- 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"}).
- 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
- 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")
- 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.1.tar.gz
(14.3 kB
view hashes)
Built Distribution
Close
Hashes for ratelimitcli-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 376eec8f78bd0d2525b9875686bd905e809970255c627d8f6b5445d3182a438a |
|
MD5 | dfe7d43eb1372abc16ca64ddacb35fd7 |
|
BLAKE2b-256 | d589d135e0c0feaaf93323a487ea375051d11b72158fb575fb831ab67f81afd6 |