Gotenberg API Client
A modern, fully-typed Python client for the Gotenberg PDF generation API, with sync and async support.
Quick Start
pip install "gotenberg-client[httpx]"
from gotenberg_client import GotenbergClient
from pathlib import Path
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index(Path("my-index.html")).run()
response.to_file(Path("my-index.pdf"))
Four lines (excluding imports) to convert HTML to PDF.
Why gotenberg-client?
Gotenberg is a powerful, Docker-based API for PDF generation and manipulation using Chromium and LibreOffice under the hood. This client gives you a clean, Pythonic interface to all of its capabilities, so you can skip the multipart form-data boilerplate and focus on your documents.
Features
- Fully typed with concrete return types and full
py.typedsupport - Sync and async APIs with identical interfaces
- Pluggable HTTP backends -- httpx (with HTTP/2), niquests, or requests — install whichever you prefer
- Pathlib-native -- pass
Pathobjects directly, no manual file handling - Thoroughly tested against a real Gotenberg server across multiple Python versions
- Broad route coverage including Chromium, LibreOffice, PDF merge/convert/split, health checks, and more
- If there's a route you need, just ask!
Installation
An HTTP backend is required. Pick the one that suits your project:
pip install "gotenberg-client[httpx]" # recommended — HTTP/2 and async support
pip install "gotenberg-client[niquests]" # alternative — HTTP/2 and async support
pip install "gotenberg-client[requests]" # sync-only
If you need MIME-type detection for automatic content-type headers, add the magic extra:
pip install "gotenberg-client[httpx,magic]"
Examples
HTML to PDF
from gotenberg_client import GotenbergClient
from pathlib import Path
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index(Path("my-index.html")).run()
response.to_file(Path("my-index.pdf"))
Async support
from gotenberg_client import AsyncGotenbergClient
from pathlib import Path
async with AsyncGotenbergClient("http://localhost:3000") as client:
async with client.chromium.html_to_pdf() as route:
response = await route.index(Path("my-index.html")).run()
response.to_file(Path("my-index.pdf"))
HTML with additional resources
from gotenberg_client import GotenbergClient
from pathlib import Path
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = (
route.index(Path("my-index.html"))
.resource("image.png")
.resource("style.css")
.run()
)
response.to_file(Path("my-index.pdf"))
URL to PDF in landscape
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PageOrientation
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.url_to_pdf() as route:
response = route.url("https://hello.world").orient(PageOrientation.Landscape).run()
response.to_file(Path("my-world.pdf"))
PDF/A output format
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PdfAFormat
from pathlib import Path
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = (
route.index(Path("my-index.html"))
.resources(["image.png", "style.css"])
.pdf_format(PdfAFormat.A2b)
.run()
)
response.to_file(Path("my-index.pdf"))
PDF metadata
from gotenberg_client import GotenbergClient
from datetime import datetime
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = (
route.index("my-index.html")
.metadata(
title="My Document",
author="John Doe",
subject="Example PDF",
keywords=["sample", "document", "test"],
creation_date=datetime.now(),
)
.run()
)
response.to_file(Path("my-index.pdf"))
Choosing an HTTP backend
Install the backend you want, then select it explicitly (or rely on auto-detection):
from gotenberg_client import GotenbergClient
# httpx — pip install "gotenberg-client[httpx]"
with GotenbergClient("http://localhost:3000", backend="httpx") as client:
...
# niquests — pip install "gotenberg-client[niquests]"
with GotenbergClient("http://localhost:3000", backend="niquests") as client:
...
# requests (sync-only) — pip install "gotenberg-client[requests]"
with GotenbergClient("http://localhost:3000", backend="requests") as client:
...
# auto — tries httpx first, then niquests (default)
with GotenbergClient("http://localhost:3000") as client:
...
Basic authentication
from gotenberg_client import GotenbergClient
with GotenbergClient("http://localhost:3000", auth=("user", "secret")) as client:
with client.chromium.html_to_pdf() as route:
response = route.index(Path("my-index.html")).run()
response.to_file(Path("my-index.pdf"))
How It Works
All routes follow the same pattern:
- Add the file(s) you want to process
- Configure options the route supports
- Call
.run()and receive your result
Responses are either a SingleFileResponse or ZipFileResponse, each providing:
to_file(path)-- write the result to diskextract_to(directory)-- extract a ZIP result into a directory (ZipFileResponse only)- Access to
headers,status_code, andcontentfrom the underlying response
Resource cleanup
Both the client and routes should be used as context managers for proper cleanup.
If that isn't possible, call .close() explicitly:
from gotenberg_client import GotenbergClient
from pathlib import Path
client = GotenbergClient("http://localhost:3000")
try:
route = client.merge.merge()
try:
response = route.merge([Path("myfile.pdf"), Path("otherfile.pdf")]).run()
response.to_file(Path("merged.pdf"))
finally:
route.close()
finally:
client.close()
Documentation
For the full API reference and more examples, see the documentation.
License
gotenberg-client is distributed under the terms of the MPL 2.0 license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gotenberg_client-1.0.0.tar.gz.
File metadata
- Download URL: gotenberg_client-1.0.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
871b339ed98911279f94f3aaa6403ca7c59aaa695d8663249be6314ccd46719c
|
|
| MD5 |
8a007c5c511324979fc9a1f4e37f9dd6
|
|
| BLAKE2b-256 |
68a348b438bded1a514289b8b92fa5f29077712702cda8c01f923b930f80cff8
|
Provenance
The following attestation bundles were made for gotenberg_client-1.0.0.tar.gz:
Publisher:
ci.yml on stumpylog/gotenberg-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gotenberg_client-1.0.0.tar.gz -
Subject digest:
871b339ed98911279f94f3aaa6403ca7c59aaa695d8663249be6314ccd46719c - Sigstore transparency entry: 2365281518
- Sigstore integration time:
-
Permalink:
stumpylog/gotenberg-client@0903c4f7bf106983b6b5e137ada1db36fa49912f -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/stumpylog
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0903c4f7bf106983b6b5e137ada1db36fa49912f -
Trigger Event:
push
-
Statement type:
File details
Details for the file gotenberg_client-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gotenberg_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 67.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
458669231d972f7328fa84fb3085fed8a8052d7d26263aa5bf8a0edd1d06cd0a
|
|
| MD5 |
09e0f1d3503ae0ab225165ba87efd098
|
|
| BLAKE2b-256 |
7e5f8a2d984e3c45162124d57541a7ad6bf67cd9707a4e49ef9562abc58c3255
|
Provenance
The following attestation bundles were made for gotenberg_client-1.0.0-py3-none-any.whl:
Publisher:
ci.yml on stumpylog/gotenberg-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gotenberg_client-1.0.0-py3-none-any.whl -
Subject digest:
458669231d972f7328fa84fb3085fed8a8052d7d26263aa5bf8a0edd1d06cd0a - Sigstore transparency entry: 2365281531
- Sigstore integration time:
-
Permalink:
stumpylog/gotenberg-client@0903c4f7bf106983b6b5e137ada1db36fa49912f -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/stumpylog
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0903c4f7bf106983b6b5e137ada1db36fa49912f -
Trigger Event:
push
-
Statement type: