Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

typst-py

> 编程语言
Open source

Python binding to typst

341 stars0 likes2 views
WebsiteGitHub

About

Python binding to typst

typst-py

Python binding to typst, a new markup-based typesetting system that is powerful and easy to learn.

Installation

bash
pip install typst

Usage

…

Multi-file projects

You can compile multi-file Typst projects by passing a dictionary mapping filenames to their content as bytes. The entry point must be keyed as "main" or "main.typ" (if there is only one file, any key works):

python
import typst

files = {
    "main.typ": b'#import "lib.typ": greet\n= Hello\n#greet("World")',
    "lib.typ": b'#let greet(name) = [Hello, #name!]',
}

pdf = typst.compile(files, format="pdf")

This is useful when Typst sources are bundled as Python package resources:

python
import typst
import importlib.resources

files = {}
for filename in ["main.typ", "lib.typ", "utils.typ"]:
    files[filename] = importlib.resources.read_binary("mypackage.typst_files", filename)

pdf = typst.compile(files, format="pdf")

Dictionary values can also be file paths (as strings or Path objects), which will be read from disk.

Packages

Use package_path to point Typst at a local package directory and package_cache_path to control where downloaded @preview packages are cached:

python
import typst

pdf = typst.compile(
    "main.typ",
    package_path="vendor",
    package_cache_path="vendor",
)

Passing values

You can pass values to the compiled Typst file with the sys_inputs argument. For example:

python
import json
import typst

persons = [{"name": "John", "age": 35}, {"name": "Xoliswa", "age": 45}]
sys_inputs = {"persons": json.dumps(persons)}

typst.compile(input="main.typ", output="ages.pdf", sys_inputs=sys_inputs)

The following example shows how the passed data can be used in a Typst file.

bash
#let persons = json(bytes(sys.inputs.persons))

#for person in persons [
  #person.name is #person.age years old. \
]

License

This work is released under the Apache-2.0 license. A copy of the license is provided in the LICENSE file.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rusttypst

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言