Skip to main content

forgefile-python

Python client for the ForgeFile REST API — translate, transcribe, convert, OCR, summarize and rewrite files.

Requires Python 3.11+.

Install

pip install forgefile

Quick start

from forgefile import ForgeFile

with ForgeFile("your-token") as api:
    job = api.jobs.translate("contract.pdf", target_language="es")
    api.files.wait(job.uuid)
    api.files.download(job.uuid, "contract.es.pdf")

The token is read from FORGEFILE_API_KEY when the first argument is omitted. Public endpoints need no token at all:

with ForgeFile() as api:
    for language in api.public.languages():
        print(language.code, language.name)

Processing a file

Every job endpoint uploads the file and starts the work in one call, returning a FileJob whose uuid identifies it from then on.

api.jobs.translate("contract.pdf", target_language="de")  # source_language is optional
api.jobs.transcribe("interview.mp3")
api.jobs.convert("report.docx", to_format="pdf")
api.jobs.ocr("receipt.jpg")
api.jobs.summarize("paper.pdf")
api.jobs.rewrite("draft.docx")
api.jobs.compress("scan.pdf")

Uploads are capped at 10 MB. The client checks the size first and raises FileTooLargeError rather than sending the bytes to be refused.

Waiting for the result

wait() blocks until the job reaches a terminal state and raises JobTimeoutError if it does not. The job keeps running server-side, so calling again resumes waiting.

finished = api.files.wait(job.uuid, timeout=900, interval=5)

if finished.succeeded:
    transcript = api.files.result(job.uuid)  # structured output
    api.files.download(job.uuid, "interview.srt")

The gap between polls grows from interval up to max_interval, so an hour-long transcription costs tens of requests, not hundreds.

track() yields every observed state instead, for progress reporting:

for state in api.files.track(job.uuid, interval=5):
    print(state.status)

Cancelling

A running job can be stopped, and the API refunds the credits it did not consume. Each job type has its own route, and the client knows which verb each one needs:

api.translation.cancel(file_uuid)  # also .resume(file_uuid)
api.transcription.cancel(job_id)
api.ocr.cancel(job_id)

Translation addresses files by UUID; conversion and summarization use the numeric job id the API returns. Passing the wrong shape is rejected by the API before it reaches the handler.

Branch on job.is_finished and job.succeeded rather than comparing status strings — a status this client does not recognise is never treated as finished, so a wait loop cannot end early on a state it has not seen.

Errors

Every failure raises a subclass of ForgeFileError carrying the API's stable error_code, so you can branch on the code rather than on message text.

from forgefile import RateLimitError, ValidationError

try:
    api.jobs.translate("contract.pdf", target_language="es")
except ValidationError as exc:
    print(exc.context)  # field errors
except RateLimitError as exc:
    print(f"retry in {exc.retry_after}s")
Exception Raised when
AuthenticationError 401 — no token, or rejected
ForbiddenError 403 — token lacks the right
NotFoundError 404
ValidationError 422 — field errors in context
RateLimitError 429 — retry_after in seconds
ServerError 5xx — safe to retry with backoff
TransportError no response at all: DNS, TLS, timeout
JobTimeoutError wait() gave up; the job still runs
FileTooLargeError the upload exceeds 10 MB; refused before sending

Retries

Transient failures are retried automatically with exponential backoff:

  • 429 is always retried, on any method, honouring Retry-After — the request was refused before it ran, so nothing happened.
  • 5xx and connection failures are retried only for GET, HEAD, PUT and DELETE. A POST that timed out may already have created a job, and jobs cost credits.
  • Uploads are never retried: the file handle is consumed by the first attempt and cannot be replayed.
from forgefile import ForgeFile, RetryPolicy

ForgeFile(retries=RetryPolicy(attempts=5, backoff=1.0))
ForgeFile(retries=RetryPolicy(attempts=1))  # off

The API allows 60 requests per minute.

Configuration

Argument Environment variable Default
api_key FORGEFILE_API_KEY none — public endpoints only
base_url FORGEFILE_BASE_URL https://forgefile.com/api/v1
timeout 60 seconds
retries 3 attempts, 0.5 s backoff

Examples

Runnable scripts in examples/:

File Shows
01_public_data.py reference data without a token
02_translate_document.py submit, wait, download
03_transcribe_with_progress.py streaming progress with track()
04_convert_a_folder.py batching — submit all, then collect
05_handling_errors.py every failure mode and its remedy
06_custom_transport.py replacing the HTTP layer
07_cancel_a_job.py cancelling a job that runs over budget

Architecture

Module Responsibility
config where to connect and with what headers
envelope the API's {success, message, data} wrapper — the only place that knows it
errors turning a failed response into the right exception
transport HTTP, as a Protocol plus an httpx implementation
resources/ one class per endpoint group: system, public, account, files, jobs, translation, transcription, ocr, conversion

Resources depend on the HTTPTransport protocol, never on httpx, so the HTTP layer can be replaced with a recorded fixture, a proxy or a different library — see examples/06_custom_transport.py.

Response models accept unknown fields, which stay reachable through model_extra. Only fields observed against the live API are typed explicitly; authenticated endpoints could not be inspected without a token while this client was written, so their payloads are permissive rather than guessed.

The package ships a py.typed marker, so your type checker sees these signatures.

Development

git clone https://github.com/ForgeFile/forgefile-python
cd forgefile-python
uv sync

uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest

Tests make no network calls: the resource layer runs against a fake transport, the httpx layer against respx. CI runs these commands on Python 3.11, 3.12 and 3.13.

Links

MIT licensed. See LICENSE.

Release files for forgefile 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for forgefile 0.2.0
File Size Uploaded
forgefile-0.2.0.tar.gz 81.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for forgefile 0.2.0
File Interpreter ABI Platform
forgefile-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size:104.0 kB

Release files / forgefile-0.2.0.tar.gz

Download URL forgefile-0.2.0.tar.gz
Size 81.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9692f4729f8bf7efce863e9e02f9ce19f729ebf59ddce5487a46325e064c0fef
BLAKE2b-256 checksum
How to use checksums
8f1f3acf8ac2c2ef9fc96e7c846eaf1464ea5474dcfc77bf421273f32782b03c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Release files / forgefile-0.2.0-py3-none-any.whl

Download URL forgefile-0.2.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22646a8c0e7185514321ce9263bcf5a55f11c0fef467f6c48879623aabf17eac
BLAKE2b-256 checksum
How to use checksums
3f1e3df19574dba193ab9def771e1ea702e526422abb6f848149aa68ca04750d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page