API Guide
The forced photometry server has a REST API that makes it easy to script requests. In this example, we'll use Python.
First, let's import some useful packages and set the API URL:
import io
import sys
import time
import pandas as pd
import requests
BASEURL = "https://fallingstar-data.com/forcedphot"
Next, we need to obtain a secret token from our username and password. This step normally only has to be done once. You can also view your token, and replace or delete it if it becomes compromised, on the API token page.
resp = requests.post(url=f"{BASEURL}/api-token-auth/", data={'username': "__my_username__", 'password': "__my_password__"})
if resp.status_code == 200:
token = resp.json()['token']
print(f'Your token is {token}')
headers = {'Authorization': f'Token {token}', 'Accept': 'application/json'}
else:
print(f'ERROR {resp.status_code}')
print(resp.json())
Next, submit an RA and Dec coordinate to the server to obtain a URL for checking the status. Note that our request may be throttled if we make too many in a short time.
task_url = None
while not task_url:
with requests.Session() as s:
resp = s.post(f"{BASEURL}/queue/", headers=headers, data={
'ra': 44, 'dec': 22, 'mjd_min': 59248.})
if resp.status_code == 201: # successfully queued
task_url = resp.json()['url']
print(f'The task URL is {task_url}')
elif resp.status_code == 429: # throttled
message = resp.json()["detail"]
print(f'{resp.status_code} {message}')
# the server says how long to wait in the Retry-After header
waittime = int(resp.headers.get('Retry-After', 10))
print(f'Waiting {waittime} seconds')
time.sleep(waittime)
else:
print(f'ERROR {resp.status_code}')
print(resp.json())
sys.exit()
Now we can check if the task has completed, and if so, retrieve the results. Be aware that the result URL is for short term use and may expire in the future.
result_url = None
while not result_url:
with requests.Session() as s:
resp = s.get(task_url, headers=headers)
if resp.status_code == 200: # HTTP OK
if resp.json()['finishtimestamp']:
if resp.json()['error_msg']:
# the task finished without a result file, so there is nothing to download
print(f"Task failed with error: {resp.json()['error_msg']}")
sys.exit(1)
result_url = resp.json()['result_url']
print(f"Task is complete with results available at {result_url}")
break
elif resp.json()['starttimestamp']:
print(f"Task is running (started at {resp.json()['starttimestamp']})")
else:
print("Waiting for job to start. Checking again in 10 seconds...")
time.sleep(10)
else:
print(f'ERROR {resp.status_code}')
print(resp.json())
sys.exit()
with requests.Session() as s:
result = s.get(result_url, headers=headers)
# stop before the delete if the download failed: an error response also has a body
result.raise_for_status()
textdata = result.text
# keep a copy on disk before the delete removes the copy on the server
with open(f"result_{resp.json()['id']}.txt", "w", encoding="utf-8") as f:
f.write(textdata)
# a successful delete returns 204 with an empty body
deleted = s.delete(task_url, headers=headers)
if deleted.status_code != 204:
print(f"WARNING: could not delete {task_url}: HTTP {deleted.status_code}")
The raw text can be parsed into a pandas DataFrame for easy manipulation.
dfresult = pd.read_csv(io.StringIO(textdata.replace("###", "")), sep=r"\s+")
print(dfresult)
A complete Python example script for the API can be downloaded from apiexample.py.
Being notified instead of polling
Rather than polling the task URL until it finishes, a task can carry a callback_url. When the task completes, the server sends it a single POST with a JSON body. The URL must be https and must resolve to a public address. Redirects are not followed, and the callback is attempted once and not retried, so treat it as a hint to fetch the result rather than as the result itself.
resp = s.post(f"{BASEURL}/queue/", headers=headers, data={
'ra': 44, 'dec': 22, 'mjd_min': 59248.,
'callback_url': 'https://example.org/my-atlas-hook'})
The body posted to that URL looks like:
{
"task_id": 12345,
"task_url": "https://fallingstar-data.com/forcedphot/queue/12345/",
"request_type": "FP",
"finishtimestamp": "2026-07-31T12:00:00+00:00",
"error_msg": None,
"success": True,
}
Queue positions and machine-readable schema
To check where your queued tasks sit without fetching the whole task list, GET {BASEURL}/queuepositions.json with the same Authorization header. The JSON answer holds queuepositions, queuedtypes, and queueoffset. queuepositions is a mapping of task id to queue position, and queuedtypes is a mapping of task id to request type. The position of a task is the number of tasks that are before it in the queue order, and 0 is next to run. The position is the largest number of tasks that start before the task. Fewer tasks start before it when a user with tasks before it has the maximum number of slots. Your task then starts before the other tasks of that user. Only a task that waits for its start has a position. A task that has started is not in the two mappings, and its queuepos in the task list is null. queuedcount is the number of all your unfinished tasks. startedids is the list of the ids of your unfinished tasks that have started and have no position. Such a task runs, or its attempt failed and it waits for a new attempt. The field running_taskids of {BASEURL}/taskrunnerstatus.json has the ids of the tasks that run. startedtypes is a mapping of the id of each of those tasks to its request type. With ?usage=1 in the address, the answer also has usagehours: your usage in hours of run time, as the queue order uses it.
The queue gives each user a fair share of the run time. The usage of a user is the sum of the run times of the tasks of that user. Older run time counts less: the run time of 7 days ago counts half. A free slot goes to the next task of the user with the least usage. Each hour that a task waits has the same effect as 15 minutes less usage. The tasks of one user use a maximum of 8 slots at one time while a task of a different user can start. They use more slots when no other task can start. A task of a different user that arrives later can thus get a position before your task, and a position can increase. The FAQ page tells more about the queue. The tasks of a small group of users with high priority have the first positions.
An OpenAPI 3 schema for this API is generated from the server code and served at /api/schema/, with a browsable version at /api/docs/.
For plotting the output text files, David Young has provided a Python plot script.
If you notice any issues with the data or this website, please report an issue on GitHub or for urgent/security matters email Luke Shingles. This is an open-source volunteer project and feature requests may be considered as time allows.