From 83ba72a3cc5f667835a47593a18df93a69a94a94 Mon Sep 17 00:00:00 2001 From: iklo Date: Mon, 21 Sep 2026 19:16:24 -0300 Subject: [PATCH] fix: make the rate limit example runnable The example could not start. Three problems, each fatal on its own: - `LightAPI` is not exported; the class is `LightApi`, so the import raised ImportError before anything ran. - `Meta.rate_limit` used the key `request`; the middleware reads `requests`, so every call to /books returned 500 with KeyError. - `run(reload=True)` needs an import string, so uvicorn refused to start and only printed a warning. Every other example passes `debug=True`. Verified by running the example and calling the endpoint: the first three requests return 200 with a decreasing X-RateLimit-Remaining and the fourth returns 429. --- examples/19_rate_limit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/19_rate_limit.py b/examples/19_rate_limit.py index 885c984..7e4a5fe 100644 --- a/examples/19_rate_limit.py +++ b/examples/19_rate_limit.py @@ -1,7 +1,7 @@ from sqlalchemy import create_engine from sqlalchemy.pool import StaticPool -from lightapi import EndpointRateLimitMiddleware, HttpMethod, LightAPI, RestEndpoint +from lightapi import EndpointRateLimitMiddleware, HttpMethod, LightApi, RestEndpoint from lightapi.fields import Field @@ -10,7 +10,7 @@ class BookEndpoint(RestEndpoint, HttpMethod.GET): author: str = Field(min_length=1) class Meta: - rate_limit = {"request": 3, "window": 60} + rate_limit = {"requests": 3, "window": 60} if __name__ == "__main__": @@ -19,6 +19,6 @@ class Meta: connect_args={"check_same_thread": False}, poolclass=StaticPool, ) - app = LightAPI(engine=engine, middlewares=[EndpointRateLimitMiddleware]) + app = LightApi(engine=engine, middlewares=[EndpointRateLimitMiddleware]) app.register({"/books": BookEndpoint}) - app.run(host="0.0.0.0", port=8000, reload=True) + app.run(host="0.0.0.0", port=8000, debug=True)