builder

class typy.builder.DocumentBuilder(verbose=False)[source]

Bases: object

Parameters:

verbose (bool)

add_template(template)[source]
Parameters:

template (Template)

get_template_data_model()[source]
Return type:

Type[Template]

add_data(data)[source]
Parameters:

data (dict | Template)

add_typ_template(typ_path, data=None)[source]

Add a raw Typst .typ template file with optional JSON-serialisable data dict.

Parameters:
  • typ_path (Path) – Path to the .typ Typst template file to render.

  • data (dict | None) – Optional dictionary of template variables. When provided, the data is encoded and written to typy_data.typ in the build directory so the template can import it.

Returns:

self – enables method chaining.

copy_assets_from(source_dir)[source]

Copy files from source_dir into the build temp dir.

This makes relative paths (e.g. assets/image.png) in the document resolvable during Typst compilation, which otherwise runs in an isolated temporary directory.

Files named main.typ, typy_data.typ, and typy.typ are intentionally excluded so the generated build files are not overwritten.

Parameters:

source_dir (Path) – Directory whose contents are copied to the build dir.

Returns:

self – enables method chaining.

Return type:

DocumentBuilder

add_file(filepath)[source]
Parameters:

filepath (Path)

Return type:

Path

compile(typ_file, output)[source]
Parameters:
  • typ_file (Path)

  • output (Path)

save_pdf(filepath)[source]
Parameters:

filepath (Path)

to_buffer()[source]
Return type:

BytesIO

save_source(dirpath)[source]
Parameters:

dirpath (Path)