Skip to content

feat: add Format constants for convert media types, including JXL - #28

Open
Sreini wants to merge 1 commit into
masterfrom
feat/jxl-format
Open

feat: add Format constants for convert media types, including JXL#28
Sreini wants to merge 1 commit into
masterfrom
feat/jxl-format

Conversation

@Sreini

@Sreini Sreini commented Sep 3, 2026

Copy link
Copy Markdown

Adds a Format namespace of media-type constants so the types accepted by
convert are discoverable via autocomplete — including JPEG XL
(image/jxl), which the API already accepts but no client surfaced.

image/jxl is already in the API allowlist (apps/api/src/schemas/optimizations.ts
and apps/opt-api/src/constants/content-types.ts), so this is a client-side
discoverability change only. There is no API-side work outstanding.

Members

WEBP, PNG, JPEG, JPG, AVIF, JXL, ANY (*/*) — mirroring the
API allowlist exactly.

Why string constants and not an enum

The JSON body has to carry the media type verbatim. A language-level enum
serializes as its name or ordinal, not image/jxl. String constants also keep
this fully backward compatible: callers passing raw strings are unaffected.

Also fixed here

ConvertTypes was missing image/jpg, which the API does accept — passing it
failed type checking. Added.

Verification

Full suite green locally: pytest test/unit → 90 passed, 1 pre-existing skip, including 4 new tinify_format_test.py cases.

Part of a coordinated change across all six Tinify client libraries, so the
same Format API is available in each.

Adds a Format namespace of media-type string constants so the types
accepted by convert() are discoverable via autocomplete, matching the
other Tinify client libraries.

Also adds the missing image/jpg to ConvertTypes. The API accepts it,
but the type hints did not, so passing it failed type checking.
Comment thread tinify/_typed.py
height: Optional[int]

ConvertTypes = Literal['image/webp', 'image/jpeg', 'image/png', "image/avif", "image/jxl", "*/*"]
ConvertTypes = Literal['image/webp', 'image/jpeg', 'image/jpg', 'image/png', "image/avif", "image/jxl", "*/*"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We also need a type hint in the API to inform the user that they may use the enum from _format.py

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