slowapi
slowapi copied to clipboard
Support for aioredis
Since FastAPI and Starlette are ASGI and are built on asyncio
, it would be nice for slowapi to support aioredis
as a storage backend. I imagine that it might require some playing around with the limits
library, but would be a cool feature.
@thearchitector thanks for opening this issue. I think it relates to #3
What you're suggesting makes complete sense in my mind, I initially wanted to make slowapi
fully async, just haven't found the time to do so. There's a PR on limits
that I opened a while back to make it support async code, and I believe converting the slowapi
code to async wouldn't be a huge endeavour.
If you feel like you can help with this, please don't hesitate!
@laurentS cool! if you cannot manage to get your PR merged, and its been a year so that might not be likely, another option would just be to just include that custom storage backend here or via a different package?
@laurentS hey, i threw together a draft PR for migrating the library over to async/await. Obviously limits
is still blocking, but its wrapped in a threaded executor so it doesn't block the event loop (same style as starlette).
there's a note about the decorator wrapper that may be a bit contentious, so let me know what you think. in the future, hopefully whenever limits
implements your PR, the threaded call to limits can be changed to be conditional on the storage backend used.
@laurentS @thearchitector what is the current status?
I've bumped version of limits
up to 2.1 and have tried to use async+redis://localhost:6379/0
with limits[async-redis]
extension, but seems it doesn't work out of the box
Error relates to this assertion