Exports
An export writes a package and everything below it as a .farki file, as File › Export does in the app. It runs in the background, so it suits packages too large for /contents, or keeping a copy of a model. The file can be imported into Farkitect with File › Import.
| Call | Gives |
|---|---|
POST /v1/packages/{packageId}/exports |
Starts the export, and answers at once with the job (202) |
GET /v1/jobs/{jobId} |
The job’s status |
GET /v1/jobs/{jobId}/file |
The file, once the job is done |
Why a job?
Section titled “Why a job?”Exporting a large model can take minutes. A single request can’t wait that long, so an export works in three steps instead: start it, let it run, then collect the file. That way:
- Nothing times out. A request to the API is given at most a minute. The export itself runs in the background for as long as it needs, while each request your program makes (start, check, download) is quick.
- A dropped connection loses nothing. If your program’s connection fails while the export runs, the export carries on; check on the job again when you’re back.
- The file can be downloaded again. It’s kept for a day, so a download that fails part-way can simply be tried again, without exporting again.
- Everyone stays quick. Exports are the heaviest work the API does. Running them in the background, one at a time per organisation, keeps one program’s export from slowing Farkitect for others.
For a package small enough to read in one call, /contents is simpler: it answers straight away, as JSON in the API’s own shapes. An export gives a .farki file, for keeping, moving to another project, or importing again.
Start, wait, download
Section titled “Start, wait, download”- Start it.
POST /v1/packages/{packageId}/exportsanswers 202 with the job, and aLocationheader pointing at it. Give a model’s own id to export the whole model. - Wait. Ask
GET /v1/jobs/{jobId}every few seconds. Itsstatusgoesqueued,running, thendone, orfailedwith the reason inerror. - Download. When it’s
done,filegives the file’s name and size, andGET /v1/jobs/{jobId}/filereturns the file itself, with its name inContent-Disposition. Asked for sooner, it answers 409job_not_ready.
import os, time, requests
API = "https://api.farkitect.com/v1"HEADERS = {"Authorization": f"Bearer {os.environ['FARKITECT_API_KEY']}"}
def export(package_id, path): job = requests.post(f"{API}/packages/{package_id}/exports", headers=HEADERS) job.raise_for_status() job = job.json() while job["status"] in ("queued", "running"): time.sleep(3) job = requests.get(f"{API}/jobs/{job['id']}", headers=HEADERS).json() if job["status"] != "done": raise RuntimeError(job["error"]) file = requests.get(f"{API}/jobs/{job['id']}/file", headers=HEADERS) file.raise_for_status() with open(path, "wb") as out: out.write(file.content)Good to know
Section titled “Good to know”- One at a time. An organisation may have one export running at once. Starting another while one runs gets 429
rate_limited, naming the job that’s running: wait for it to finish. - Kept a day. A job and its file are deleted a day after it finishes (
expiresAt). Download the file before then. - Who can see a job. Any key of the same organisation that reaches the project; others get 404.
- Not yet: attachments inside the export (the app’s Export Package with Attachments…), and whole-project exports.