API Rate limiting Python - Design

Viewed 27

I am currently trying to create a throttler decorator to limit my api calls accross all my app.

My idea is to use threading.semaphore and/or threading.timer to track and block the request which are above the rate limit.

I already have something working, however my concern is that with this solution i will start a thread per request. So lets say i'm making 5000 calls per minute, could this cause any issue / is bad practice ?

1 Answers

Good practice is to use something that already exists in the framework you are using. There are ready-made solutions for Django and DRF, for example. Something similar is bound to exist for the framework you are using. If you are developing a web api, that is.

Related