Repository navigation
Sync vs Async Compilation
Zouhair Fouiguira edited this page Feb 28, 2026
·
1 revision
Blocks until the PDF is ready.
result = client.compile(latex)
Path("out.pdf").write_bytes(result.pdf)Use sync when:
- Document compiles in < 30 seconds
- You want simple, sequential code
- Building a web endpoint that returns the PDF inline
Submit and get a job ID immediately. Poll separately.
# 1. Submit — returns instantly
job = client.async_compile(latex, engine="lualatex")
print(job.job_id, job.status) # "abc-123", "pending"
# 2. Wait (polls automatically every 2 seconds)
result = client.wait_for_job(job.job_id)
Path("out.pdf").write_bytes(result.pdf)Use async when:
- Large documents (books, theses)
- Batch processing many documents
- You want to show progress to the user
- You need to decouple submission from retrieval
import time
job = client.async_compile(latex)
while True:
status = client.get_job(job.job_id)
if status.status == "completed":
pdf = client.get_job_pdf(job.job_id) # one-time download
Path("out.pdf").write_bytes(pdf)
break
if status.status == "failed":
print(f"Failed: {status.error}")
print(f"Log: {status.log}")
break
print(f"Status: {status.status} — waiting...")
time.sleep(2)submitted → pending → processing → completed
→ failed
-
pending— queued, not yet started -
processing— engine is running -
completed— PDF ready for one-time download -
failed— LaTeX error or timeout; checkstatus.log
Skip the result object and write directly:
client.compile_to_file(latex, "output.pdf")
client.compile_to_file(latex, "output.pdf", engine="xelatex")
client.compile_to_file(latex, "output.pdf", smart=True) # auto-detect enginePDFs auto-delete after the first get_job_pdf() call. Explicit cleanup:
client.delete_job(job_id)compile() |
async_compile() |
|
|---|---|---|
| Returns | PDF immediately | Job ID immediately |
| Blocks caller | Yes | No |
| Best for | < 30s docs | Large / batch |
| Poll required | No | Yes |