Skip to content

Examples: use the converters the API spec documents - #62

Merged
tomasr78 merged 1 commit into
mainfrom
examples-documented-converters
Nov 9, 2026
Merged

tomasr78 merged 1 commit into
mainfrom
examples-documented-converters

Conversation

@tomasr78

@tomasr78 tomasr78 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Two examples call converters that the production API spec (https://v2.convertapi.com/info/openapi, 332 paths on 2026-11-09) does not list. Both still convert today, but developers copy these examples and the how-to guides on convertapi.com reuse them, so they should call documented converters. This is the Python part of what ConvertAPI/convertapi-library-dotnet#86 does for .NET.

Example Before After
convert_url_to_pdf.py web -> pdf, comment links /web-to-pdf html -> pdf (parameters), same Url and FileName; comment links https://www.convertapi.com/html-to-pdf
conversions_chaining.py any -> zip: with no source format the library sends every zip conversion to any file -> zip (parameters): from_format = 'file', same Files

https://www.convertapi.com/web-to-pdf is not in the site's sitemap; https://www.convertapi.com/html-to-pdf is. The other examples already call documented converters; the pdf -> extract step of create_pdf_thumbnail.py goes away with #61.

Verified against production (2026-11-09)

Python 3.15.2 in a venv with this branch installed (pip install ., requests 2.34.2). Each example ran with python <name>.py from examples/, once on main (58b93a2) and once on this branch, with the token in API_TOKEN. A wrapper logged each request's path; <tmp> is tempfile.gettempdir().

conversions_chaining.py, same output before and after:

Converting PDF to JPG and compressing result files with ZIP
Conversions done. Cost: 1. Total files created: 6
Conversions done. Cost: 1. Total files created: 1
File saved to ['<tmp>/test.zip']

Requests on main: POST /upload, POST /convert/pdf/to/jpg, POST /convert/any/to/zip. On this branch: POST /upload, POST /convert/pdf/to/jpg, POST /convert/file/to/zip. All answered HTTP 200. Both runs saved a 775,249-byte test.zip with test.jpg to test-6.jpg; the JPGs are byte-identical before and after.

convert_url_to_pdf.py, same output before and after:

The web page PDF saved to ['<tmp>/web-example.pdf']

Request on main: POST /convert/web/to/pdf; on this branch: POST /convert/html/to/pdf; both HTTP 200. The PDF text: on this branch the PDF is the article (3 pages, 1,925 words, title "Data conversion"). On main, Wikimedia answered ConvertAPI's renderer with its "Too many requests" page (1 page, 62 words); that rate limiting comes and goes for both converters and is being looked at separately.

Seen, not changed: the library itself still picks undocumented converters when no source format is given: any for every zip target and web when the parameters have a Url (convertapi/task.py, __detect_format). The examples now pass the source format, so they do not depend on it.

Same change in the other SDKs

🤖 Generated with Claude Code

The production API spec (https://v2.convertapi.com/info/openapi) has no
web -> pdf and no any -> zip converter. convert_url_to_pdf.py now converts
the URL with html -> pdf (same Url and FileName parameters) and links the
html-to-pdf page. conversions_chaining.py passes from_format = 'file' to
the ZIP step: without a source format the library sends every zip
conversion to any -> zip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the example updates to explicit HTML-to-PDF and file-to-ZIP converters.

No open issues 🎉

What changed in this PR

Updates two Python examples to use documented ConvertAPI converters without changing the library’s automatic format detection.

Changes:

  • Uses explicit html → pdf conversion for web page URLs and updates the documentation-link comment.
  • Uses explicit file → zip conversion when archiving chained conversion results.
File Description
examples/​convert_url_to_pdf.py Sets from_format = 'html' and links to the HTML-to-PDF documentation.
examples/​conversions_chaining.py Sets from_format = 'file' for ZIP creation instead of relying on automatic detection.

Review effort: Balanced

@tomasr78
tomasr78 merged commit 20918c5 into main Nov 9, 2026
7 checks passed
@tomasr78
tomasr78 deleted the examples-documented-converters branch November 9, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants