REST API
STDWeb provides a REST API for programmatic access to image processing functionality.
For complete API documentation with examples, see the REST API Reference.
Authentication
The API uses token-based authentication. Obtain a token:
curl -X POST /api/auth/token/ \
-d "username=<username>&password=<password>"
Include the token in subsequent requests:
curl -H "Authorization: Token <your-token>" /api/tasks/
Creating API Tokens
# Via management command
python manage.py drf_create_token <username>
# Or via Django shell
python manage.py shell
>>> from rest_framework.authtoken.models import Token
>>> from django.contrib.auth.models import User
>>> user = User.objects.get(username='myuser')
>>> token, created = Token.objects.get_or_create(user=user)
>>> print(token.key)
Main Endpoints
Tasks
Endpoint |
Description |
|---|---|
|
List tasks for current user |
|
Create new task with file upload |
|
Get task details |
|
Update task configuration |
|
Delete task and files |
|
Duplicate task |
Processing
Endpoint |
Description |
|---|---|
|
Start processing steps |
|
Cancel running task |
Available processing steps: cleanup, inspect, photometry, simple_transients, subtraction
Files
Endpoint |
Description |
|---|---|
|
List task files |
|
Download file |
|
Upload file |
|
Delete file |
|
Generate FITS preview image |
Queue
Endpoint |
Description |
|---|---|
|
List Celery queue status |
|
Get task status |
|
Terminate task (staff only) |
Reference Data
Endpoint |
Description |
|---|---|
|
List all reference data |
|
Available photometric filters |
|
Available reference catalogs |
|
Available template sources |
|
List configuration presets |
Quick Example
# Get token
TOKEN=$(curl -s -X POST http://localhost:8000/api/auth/token/ \
-d "username=myuser&password=mypass" | jq -r .token)
# Upload and create task
TASK_ID=$(curl -s -X POST http://localhost:8000/api/tasks/ \
-H "Authorization: Token $TOKEN" \
-F "file=@image.fits" \
-F 'config={"filter":"R"}' | jq -r .id)
# Run processing
curl -X POST "http://localhost:8000/api/tasks/$TASK_ID/process/" \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-d '{"steps":["inspect","photometry"]}'
# Check status
curl "http://localhost:8000/api/tasks/$TASK_ID/" \
-H "Authorization: Token $TOKEN"
Python Client
import requests
BASE_URL = "http://localhost:8000/api"
# Authenticate
response = requests.post(f"{BASE_URL}/auth/token/",
data={"username": "myuser", "password": "mypass"})
token = response.json()["token"]
session = requests.Session()
session.headers["Authorization"] = f"Token {token}"
# Upload file
with open("image.fits", "rb") as f:
response = session.post(f"{BASE_URL}/tasks/",
files={"file": f},
data={"config": '{"filter": "R"}'})
task_id = response.json()["id"]
# Process
session.post(f"{BASE_URL}/tasks/{task_id}/process/",
json={"steps": ["inspect", "photometry"]})
# Get results
task = session.get(f"{BASE_URL}/tasks/{task_id}/").json()
print(f"Zero point: {task['config'].get('zp')}")