百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

typst-py

> 编程语言
开源

Python 绑定到 typst

341 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Python 绑定到 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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rusttypst

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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