Use the sched module, which implements a general purpose event scheduler.
import sched, time
s = sched.scheduler(time.time, time.sleep)
def do_something(sc):
print "Doing stuff..."
# do your stuff
s.enter(60, 1, do_something, (sc,))
s.enter(60, 1, do_something, (s,))
s.run()
EDIT 1 : My answer wasn't enough specific so here is the answer for django.
In views.py :
import sched, time
s = sched.scheduler(time.time, time.sleep)
def do_something(sc):
print "Doing stuff..."
# Call your API HERE
s.enter(10, 1, do_something, (sc,))
return your_value or your template
s.enter(10, 1, do_something, (s,))
s.run()
def home(request, sc):
api_value = do_something(sc)
return rendertemplate(request, 'template.html', {'api_value': api_value}