slowapi icon indicating copy to clipboard operation
slowapi copied to clipboard

[Ehancement] Don't require `Request` parameter to be present in endpoint function signature.

Open notypecheck opened this issue 2 years ago • 5 comments

It's possible to modify function signature so it would always have a parameter with Request by assigning a new signature into function.__signature__, it should allow you to not use the request parameter explicitly (e.g.):

@limiter.limit("...")
async def endpoint():
    print("Should work")

Implementation is not that tricky or complex, would you be interested in a PR or just a demo of how it could work? @laurentS

notypecheck avatar Nov 07 '23 05:11 notypecheck

It would be a nice addition indeed. Have bumped into this issue when exploring solutions for rate limiting at work recently. Providing a reference implementation just in case. Can be extended to inject Depends-based dependencies relatively easily but I don't think that this library needs that anyway.

waterfountain1996 avatar Nov 10 '23 17:11 waterfountain1996

It was done? Can anyone create a PR or put the code here? Thanks.

paulocoutinhox avatar May 10 '24 05:05 paulocoutinhox

@paulocoutinhox I never received an answer from maintainer(s), so no 😓 If it as contributed somewhere, then I simply don't know about it

notypecheck avatar May 10 '24 06:05 notypecheck

Im using this with success: https://github.com/santunioni/ThrottledAPI

paulocoutinhox avatar May 10 '24 06:05 paulocoutinhox