Skip to content

Commit 3cf7da0

Browse files
Expose public API via __init__ and add v0.2.0 migration guide
1 parent cc95615 commit 3cf7da0

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,49 @@ async def websocket_endpoint(websocket: WebSocket):
171171
await websocket.send_text("Hello again")
172172
```
173173

174-
## License
174+
---
175+
## Migration Guide (v0.1.x → v0.2.0)
176+
177+
### API Changes
178+
179+
In v0.2.0, the public API has been restructured.
180+
181+
- `FastAPILimiter` is not available in v0.2.0..
182+
- Redis-based initialization via `FastAPILimiter.init()` has been removed.
183+
- Rate limiting is now built around `pyrate_limiter.Limiter`.
184+
185+
### Import Changes
186+
187+
| v0.1.x | v0.2.0 |
188+
|--------|--------|
189+
| `from fastapi_limiter import FastAPILimiter` | `from fastapi_limiter import RateLimiter` |
190+
| `await FastAPILimiter.init(redis)` | Create a `Limiter` instance from `pyrate_limiter` |
191+
| `RateLimiter()` | `Depends(RateLimiter(limiter=limiter))` |
192+
193+
---
194+
195+
### Example – v0.1.x
175196

197+
```python
198+
from fastapi_limiter import FastAPILimiter
199+
200+
await FastAPILimiter.init(redis)
201+
```
202+
### Example – v0.2.0
203+
```python
204+
from fastapi import FastAPI, Depends
205+
from pyrate_limiter import Limiter, Rate, Duration
206+
from fastapi_limiter import RateLimiter
207+
208+
app = FastAPI()
209+
210+
limiter = Limiter(Rate(2, Duration.SECOND * 5))
211+
212+
@app.get("/", dependencies=[Depends(RateLimiter(limiter=limiter))])
213+
async def root():
214+
return {"msg": "Hello"}
215+
```
216+
---
217+
## License
176218
This project is licensed under the
177-
[Apache-2.0](https://github.com/long2ice/fastapi-limiter/blob/master/LICENCE) License.
219+
[Apache-2.0](https://github.com/long2ice/fastapi-limiter/blob/master/LICENCE) License.

fastapi_limiter/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .callback import default_callback
2+
from .depends import RateLimiter, WebSocketRateLimiter
3+
from .identifier import default_identifier
4+
from .middleware import RateLimiterMiddleware
5+
6+
__all__ = [
7+
"RateLimiter",
8+
"WebSocketRateLimiter",
9+
"RateLimiterMiddleware",
10+
"default_identifier",
11+
"default_callback",
12+
]

0 commit comments

Comments
 (0)