Skip to content

Options and resources

These types group rendering, animation, HTML parsing, font, and image inputs.

Common validation contracts:

  • RenderOptions.lang, when set, must be a valid BCP-47 language tag.
  • FontResource.weight, when set, must be finite and within 1 through 1000.
  • Each FontResource.unicode_range entry is an inclusive (start, end) pair with 0 <= start <= end <= 0x10FFFF.
  • AnimationEncodeOptions.quality accepts 0 through 100, and webp_speed accepts 0 through 6.

Violations of these numeric or language-tag contracts raise ValueError.

takumi_py.options.RenderOptions dataclass

Reusable render settings shared by raster, SVG, and measurement APIs.

Explicit keyword arguments on a render method override matching fields.

Attributes:

Name Type Description
width int | None

Viewport width in CSS pixels, or None to infer it from layout. The default is 1200.

height int | None

Viewport height in CSS pixels, or None to infer it from layout. The default is 630.

format ImageOutputFormat

Static output format. "raw" returns row-major RGBA bytes.

quality int | None

Lossy encoder quality from 0 through 100 where supported.

lossless bool | None

Whether to use lossless WebP encoding.

font_size float

Root font size in CSS pixels.

device_pixel_ratio float

Scale factor for raster output and layout.

draw_debug_border bool

Draw Takumi's layout debug borders.

time_ms int

Animation sampling time in milliseconds.

dithering DitheringAlgorithm

Color-dithering algorithm for supported formats.

images Sequence[ImageResourceInput] | None

Per-render image resources addressable by their src values.

keyframes KeyframesInput | None

Structured animation rules appended to the stylesheets.

font_families Sequence[str] | None

Preferred fallback font-family order.

lang str | None

BCP-47 language tag used for text shaping and font selection.

width class-attribute instance-attribute

width: int | None = 1200

height class-attribute instance-attribute

height: int | None = 630

format class-attribute instance-attribute

format: ImageOutputFormat = 'png'

quality class-attribute instance-attribute

quality: int | None = None

lossless class-attribute instance-attribute

lossless: bool | None = None

font_size class-attribute instance-attribute

font_size: float = 16.0

device_pixel_ratio class-attribute instance-attribute

device_pixel_ratio: float = 1.0

draw_debug_border class-attribute instance-attribute

draw_debug_border: bool = False

time_ms class-attribute instance-attribute

time_ms: int = 0

dithering class-attribute instance-attribute

dithering: DitheringAlgorithm = 'none'

images class-attribute instance-attribute

images: Sequence[ImageResourceInput] | None = None

keyframes class-attribute instance-attribute

keyframes: KeyframesInput | None = None

font_families class-attribute instance-attribute

font_families: Sequence[str] | None = None

lang class-attribute instance-attribute

lang: str | None = None

__init__

__init__(
    width: int | None = 1200,
    height: int | None = 630,
    format: ImageOutputFormat = "png",
    quality: int | None = None,
    lossless: bool | None = None,
    font_size: float = 16.0,
    device_pixel_ratio: float = 1.0,
    draw_debug_border: bool = False,
    time_ms: int = 0,
    dithering: DitheringAlgorithm = "none",
    images: Sequence[ImageResourceInput] | None = None,
    keyframes: KeyframesInput | None = None,
    font_families: Sequence[str] | None = None,
    lang: str | None = None,
) -> None

takumi_py.options.AnimationEncodeOptions dataclass

Reusable encoder settings for animated output.

Explicit keyword arguments on render_animation or encode_frames override matching fields.

Attributes:

Name Type Description
format AnimationOutputFormat

Animation container format.

quality int | None

Lossy encoder quality from 0 through 100 where supported.

lossless bool | None

Whether to use lossless WebP encoding.

loop_count int | None

Number of animation repetitions, or None for the format-specific default.

webp_blend bool

Blend each WebP frame with the previous canvas.

webp_dispose bool

Dispose each WebP frame before drawing the next one.

webp_speed int | None

WebP encoder speed/effort setting from 0 through 6.

format class-attribute instance-attribute

format: AnimationOutputFormat = 'webp'

quality class-attribute instance-attribute

quality: int | None = None

lossless class-attribute instance-attribute

lossless: bool | None = None

loop_count class-attribute instance-attribute

loop_count: int | None = None

webp_blend class-attribute instance-attribute

webp_blend: bool = True

webp_dispose class-attribute instance-attribute

webp_dispose: bool = False

webp_speed class-attribute instance-attribute

webp_speed: int | None = None

__init__

__init__(
    format: AnimationOutputFormat = "webp",
    quality: int | None = None,
    lossless: bool | None = None,
    loop_count: int | None = None,
    webp_blend: bool = True,
    webp_dispose: bool = False,
    webp_speed: int | None = None,
) -> None

takumi_py.options.HtmlOptions dataclass

Inputs that control how the Rust HTML parser builds a node tree.

Attributes:

Name Type Description
presets HtmlStylePresets

Default element styles to apply. "chromium" matches browser defaults; "none" applies no preset.

tailwind_property str | None

HTML attribute that contains Tailwind classes. None reads the tw attribute.

max_depth int | None

Maximum element nesting depth, or None for Takumi's default limit.

presets class-attribute instance-attribute

presets: HtmlStylePresets = 'chromium'

tailwind_property class-attribute instance-attribute

tailwind_property: str | None = None

max_depth class-attribute instance-attribute

max_depth: int | None = None

__init__

__init__(
    presets: HtmlStylePresets = "chromium",
    tailwind_property: str | None = None,
    max_depth: int | None = None,
) -> None

takumi_py.options.ImageResource dataclass

Image bytes addressable by an image node's src.

Attributes:

Name Type Description
src str

Identifier matched against the image node's src.

data bytes

Encoded image bytes, such as PNG, JPEG, WebP, or SVG data.

cache ImageCacheMode

Whether the renderer may retain the decoded image in its renderer-local resource cache.

src instance-attribute

src: str

data instance-attribute

data: bytes

cache class-attribute instance-attribute

cache: ImageCacheMode = 'auto'

__init__

__init__(
    src: str, data: bytes, cache: ImageCacheMode = "auto"
) -> None

takumi_py.options.FontResource dataclass

Font bytes plus the @font-face descriptors used to register them.

Register each subset of a family under the same name with the unicode_range its @font-face declares; a subset only serves the codepoints in its ranges.

Attributes:

Name Type Description
data bytes

TrueType, OpenType, WOFF, or WOFF2 font bytes.

name str | None

Family name to register the font under. Defaults to the name stored in the font file.

weight float | None

Weight override from 1 through 1000.

style str | None

CSS font-style override such as "italic".

subset_of str | None

Deprecated. Takumi now treats it as the family name and it takes precedence over name; use name with unicode_range instead.

generic_family GenericFontFamily | None

CSS generic family keyword this font resolves.

unicode_range Sequence[UnicodeRange] | None

Inclusive (start, end) codepoint ranges the font serves, as in @font-face unicode-range. None serves every codepoint the font covers.

data instance-attribute

data: bytes

name class-attribute instance-attribute

name: str | None = None

weight class-attribute instance-attribute

weight: float | None = None

style class-attribute instance-attribute

style: str | None = None

subset_of class-attribute instance-attribute

subset_of: str | None = None

generic_family class-attribute instance-attribute

generic_family: GenericFontFamily | None = None

unicode_range class-attribute instance-attribute

unicode_range: Sequence[UnicodeRange] | None = None

__init__

__init__(
    data: bytes,
    name: str | None = None,
    weight: float | None = None,
    style: str | None = None,
    subset_of: str | None = None,
    generic_family: GenericFontFamily | None = None,
    unicode_range: Sequence[UnicodeRange] | None = None,
) -> None

__post_init__

__post_init__() -> None

Structured keyframes

Structured keyframes can be passed to render methods or stored in RenderOptions.keyframes. The mapping form uses animation names as keys.

takumi_py.options.Keyframe

Bases: TypedDict

One structured keyframe and the declarations it applies.

Attributes:

Name Type Description
offsets Sequence[float]

Normalized timeline positions from 0 through 1.

declarations StyleInput

CSS declarations applied at those positions.

offsets instance-attribute

offsets: Sequence[float]

declarations instance-attribute

declarations: StyleInput

takumi_py.options.KeyframesRule

Bases: TypedDict

A structured keyframe rule with a CSS animation name.

Attributes:

Name Type Description
name str

Animation name referenced by the CSS animation property.

keyframes Sequence[Keyframe]

Ordered keyframes that make up the rule.

name instance-attribute

name: str

keyframes instance-attribute

keyframes: Sequence[Keyframe]