- Software Degeneracy
- Posts
- Automating Data pulling with Python using the APScheduler library
Automating Data pulling with Python using the APScheduler library
Pulling data from an API Endpoint and manually updating said data can be a pain, but you can schedule this instead.
When using Python’s AP Scheduler library, you can automate data pulling every X seconds/hours/days, and it’s really simple (Under 30 lines of code).
Let’s say you’re using a FastAPI Set up. you’re code would look like this at the bottom:
Before setting this up, obviously you need the APScheduler library installed.
our call_endpoint function does one thing: Hit an endpoint and print the data. In the case above I used a mock endpoint I created, you can replace with whatever endpoint you want to pull from. Then where I put #Insert data base update logic, you would add what you want to do with that data after.
This code above runs the scheduler when the API Itself is ran. it’ll add the job and you can select what interval/what function you want to run. In my case I did 10 seconds.
Hope you found this helpful!