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_rangeentry is an inclusive(start, end)pair with0 <= start <= end <= 0x10FFFF. AnimationEncodeOptions.qualityaccepts 0 through 100, andwebp_speedaccepts 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 |
height |
int | None
|
Viewport height in CSS pixels, or |
format |
ImageOutputFormat
|
Static output format. |
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 |
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. |
__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 |
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. |
__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. |
tailwind_property |
str | None
|
HTML attribute that contains Tailwind classes.
|
max_depth |
int | None
|
Maximum element nesting depth, or |
__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 |
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. |
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 |
subset_of |
str | None
|
Deprecated. Takumi now treats it as the family name and it
takes precedence over |
generic_family |
GenericFontFamily | None
|
CSS generic family keyword this font resolves. |
unicode_range |
Sequence[UnicodeRange] | None
|
Inclusive |
unicode_range
class-attribute
instance-attribute
¶
__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
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. |