gotenberg-client


Namegotenberg-client JSON
Version 0.4.1 PyPI version JSON
download
home_page
SummaryA Python client for interfacing with the Gotenberg API
upload_time2023-12-11 23:12:51
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords api client html pdf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Gotenberg API Client

[![PyPI - Version](https://img.shields.io/pypi/v/gotenberg-client.svg)](https://pypi.org/project/gotenberg-client)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/gotenberg-client.svg)](https://pypi.org/project/gotenberg-client)
[![codecov](https://codecov.io/gh/stumpylog/gotenberg-client/graph/badge.svg?token=PH25G91Q6J)](https://codecov.io/gh/stumpylog/gotenberg-client)

---

## Table of Contents

- [Installation](#installation)
- [What](#what)
- [Why](#why)
  - [Features](#features)
- [How](#how)
  - [Examples](#examples)
- [License](#license)

## Installation

```console
pip install gotenberg-client
```

## What

This is a Python client for interfacing with [Gotenberg](https://gotenberg.dev/), which in turn is a wrapper around
powerful tools for PDF generation and creation in various ways, using a stateless API. It's a very powerful tool
to generate and manipulate PDFs.

## Why

As far as I can tell, no active Python library exists to interface with the Gotenberg API.

### Features

- HTTP/2 enabled by default
- Abstract away the handling of multi-part/form-data and deal with `Path`s instead
- Based on the modern [httpx](https://github.com/encode/httpx) library
- Full support for type hinting and concrete return types as much as possible
- Nearly full test coverage run against an actual Gotenberg server for multiple Python and PyPy versions

## How

All the routes and options from the Gotenberg routes are implemented, with the exception of the Prometheus metrics
endpoint. All the routes use the same format and general idea.

1. First, you add the file or files you want to process
1. Then, configure the endpoint with its various options the route supports
1. Finally, run the route and receive your resulting file

- Files will be PDF or ZIP, depending on what endpoint and its configuration. Endpoints which handle
  multiple files, but don't merge them, return a ZIP archive of the resulting PDFs

### Examples

Converting a single HTML file into a PDF:

```python
from gotenberg_client import GotenbergClient

with GotenbergClient("http://localhost:3000") as client:
    with client.chromium.html_to_pdf() as route:
      response = route.index("my-index.html").run()
      Path("my-index.pdf").write_bytes(response.content)
```

Converting an HTML file with additional resources into a PDF:

```python
from gotenberg_client import GotenbergClient

with GotenbergClient("http://localhost:3000") as client:
    with client.chromium.html_to_pdf() as route:
      response = route.index("my-index.html").resource("image.png").resource("style.css").run()
      Path("my-index.pdf").write_bytes(response.content)
```

Converting an HTML file with additional resources into a PDF/A1a format:

```python
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PdfAFormat

with GotenbergClient("http://localhost:3000") as client:
    with client.chromium.html_to_pdf() as route:
      response = route.index("my-index.html").resources(["image.png", "style.css"]).pdf_format(PdfAFormat.A1a).run()
      Path("my-index.pdf").write_bytes(response.content)
```

Converting a URL into PDF, in landscape format

```python
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PageOrientation

with GotenbergClient("http://localhost:3000") as client:
    with client.chromium.html_to_pdf() as route:
      response = route.url("https://hello.world").orient(PageOrientation.Landscape).run()
      Path("my-world.pdf").write_bytes(response.content)
```

To ensure the proper clean up of all used resources, both the client and the route(s) should be
used as context manager. If for some reason you cannot, you should `.close` the client and any
routes:

```python
from gotenberg_client import GotenbergClient

try:
  client = GotenbergClient("http://localhost:3000")
  try:
    route = client.merge(["myfile.pdf", "otherfile.pdf"]).run()
  finally:
    route.close()
finally:
  client.close()
```

## License

`gotenberg-client` is distributed under the terms of the [MPL 2.0](https://spdx.org/licenses/MPL-2.0.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "gotenberg-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "api,client,html,pdf",
    "author": "",
    "author_email": "Trenton H <rda0128ou@mozmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f2/27/3067785b2f0e92a2b9aa60c080e3d7a64ef2d554dc066e7cc654f880611d/gotenberg_client-0.4.1.tar.gz",
    "platform": null,
    "description": "# Gotenberg API Client\n\n[![PyPI - Version](https://img.shields.io/pypi/v/gotenberg-client.svg)](https://pypi.org/project/gotenberg-client)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/gotenberg-client.svg)](https://pypi.org/project/gotenberg-client)\n[![codecov](https://codecov.io/gh/stumpylog/gotenberg-client/graph/badge.svg?token=PH25G91Q6J)](https://codecov.io/gh/stumpylog/gotenberg-client)\n\n---\n\n## Table of Contents\n\n- [Installation](#installation)\n- [What](#what)\n- [Why](#why)\n  - [Features](#features)\n- [How](#how)\n  - [Examples](#examples)\n- [License](#license)\n\n## Installation\n\n```console\npip install gotenberg-client\n```\n\n## What\n\nThis is a Python client for interfacing with [Gotenberg](https://gotenberg.dev/), which in turn is a wrapper around\npowerful tools for PDF generation and creation in various ways, using a stateless API. It's a very powerful tool\nto generate and manipulate PDFs.\n\n## Why\n\nAs far as I can tell, no active Python library exists to interface with the Gotenberg API.\n\n### Features\n\n- HTTP/2 enabled by default\n- Abstract away the handling of multi-part/form-data and deal with `Path`s instead\n- Based on the modern [httpx](https://github.com/encode/httpx) library\n- Full support for type hinting and concrete return types as much as possible\n- Nearly full test coverage run against an actual Gotenberg server for multiple Python and PyPy versions\n\n## How\n\nAll the routes and options from the Gotenberg routes are implemented, with the exception of the Prometheus metrics\nendpoint. All the routes use the same format and general idea.\n\n1. First, you add the file or files you want to process\n1. Then, configure the endpoint with its various options the route supports\n1. Finally, run the route and receive your resulting file\n\n- Files will be PDF or ZIP, depending on what endpoint and its configuration. Endpoints which handle\n  multiple files, but don't merge them, return a ZIP archive of the resulting PDFs\n\n### Examples\n\nConverting a single HTML file into a PDF:\n\n```python\nfrom gotenberg_client import GotenbergClient\n\nwith GotenbergClient(\"http://localhost:3000\") as client:\n    with client.chromium.html_to_pdf() as route:\n      response = route.index(\"my-index.html\").run()\n      Path(\"my-index.pdf\").write_bytes(response.content)\n```\n\nConverting an HTML file with additional resources into a PDF:\n\n```python\nfrom gotenberg_client import GotenbergClient\n\nwith GotenbergClient(\"http://localhost:3000\") as client:\n    with client.chromium.html_to_pdf() as route:\n      response = route.index(\"my-index.html\").resource(\"image.png\").resource(\"style.css\").run()\n      Path(\"my-index.pdf\").write_bytes(response.content)\n```\n\nConverting an HTML file with additional resources into a PDF/A1a format:\n\n```python\nfrom gotenberg_client import GotenbergClient\nfrom gotenberg_client.options import PdfAFormat\n\nwith GotenbergClient(\"http://localhost:3000\") as client:\n    with client.chromium.html_to_pdf() as route:\n      response = route.index(\"my-index.html\").resources([\"image.png\", \"style.css\"]).pdf_format(PdfAFormat.A1a).run()\n      Path(\"my-index.pdf\").write_bytes(response.content)\n```\n\nConverting a URL into PDF, in landscape format\n\n```python\nfrom gotenberg_client import GotenbergClient\nfrom gotenberg_client.options import PageOrientation\n\nwith GotenbergClient(\"http://localhost:3000\") as client:\n    with client.chromium.html_to_pdf() as route:\n      response = route.url(\"https://hello.world\").orient(PageOrientation.Landscape).run()\n      Path(\"my-world.pdf\").write_bytes(response.content)\n```\n\nTo ensure the proper clean up of all used resources, both the client and the route(s) should be\nused as context manager. If for some reason you cannot, you should `.close` the client and any\nroutes:\n\n```python\nfrom gotenberg_client import GotenbergClient\n\ntry:\n  client = GotenbergClient(\"http://localhost:3000\")\n  try:\n    route = client.merge([\"myfile.pdf\", \"otherfile.pdf\"]).run()\n  finally:\n    route.close()\nfinally:\n  client.close()\n```\n\n## License\n\n`gotenberg-client` is distributed under the terms of the [MPL 2.0](https://spdx.org/licenses/MPL-2.0.html) license.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python client for interfacing with the Gotenberg API",
    "version": "0.4.1",
    "project_urls": {
        "Changelog": "https://github.com/stumpylog/gotenberg-client/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/stumpylog/gotenberg-client/#readme",
        "Issues": "https://github.com/stumpylog/gotenberg-client/issues",
        "Source": "https://github.com/stumpylog/gotenberg-client/"
    },
    "split_keywords": [
        "api",
        "client",
        "html",
        "pdf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "acc0c02ea4843efd4e98e8ec240a60d478006bb04a59ec52dfa00ae08430a896",
                "md5": "57000d08add36aa5041dcf81cc4eb741",
                "sha256": "69e9dd5264b75ed0ba1f9eebebdc750b13d190710fd82ca0670d161c249155c9"
            },
            "downloads": -1,
            "filename": "gotenberg_client-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "57000d08add36aa5041dcf81cc4eb741",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20602,
            "upload_time": "2023-12-11T23:12:49",
            "upload_time_iso_8601": "2023-12-11T23:12:49.599717Z",
            "url": "https://files.pythonhosted.org/packages/ac/c0/c02ea4843efd4e98e8ec240a60d478006bb04a59ec52dfa00ae08430a896/gotenberg_client-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2273067785b2f0e92a2b9aa60c080e3d7a64ef2d554dc066e7cc654f880611d",
                "md5": "769315d99ad3b853a0e0d61bdae61807",
                "sha256": "dd0f49d3d4e01399949f39ac5024a5512566c8ded6ee457a336a5f77ce4c1a25"
            },
            "downloads": -1,
            "filename": "gotenberg_client-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "769315d99ad3b853a0e0d61bdae61807",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 306958,
            "upload_time": "2023-12-11T23:12:51",
            "upload_time_iso_8601": "2023-12-11T23:12:51.312469Z",
            "url": "https://files.pythonhosted.org/packages/f2/27/3067785b2f0e92a2b9aa60c080e3d7a64ef2d554dc066e7cc654f880611d/gotenberg_client-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-11 23:12:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stumpylog",
    "github_project": "gotenberg-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gotenberg-client"
}
        
Elapsed time: 0.15510s