A CLI to manage rate limits.
Project description
Adding rate limits to your API
For more detailed documentation check out 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.0.tar.gz
(14.3 kB
view hashes)
Built Distribution
Close
Hashes for ratelimitcli-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 661e793bad5c7a24e3610930745e24ae2c8480fdae55e5c60cf558ded17b1eeb |
|
MD5 | 18ec1e9e9e357ab190138566f847d710 |
|
BLAKE2b-256 | dabe111cd2c04729651004ff121d0f802d02d3cc014ee6174c961dabbb8ae72f |