typst-py
Python binding to typst, a new markup-based typesetting system that is powerful and easy to learn.
Installation
pip install typst
Usage
import datetime
import typst
# Compile `hello.typ` to PDF and save as `hello.pdf`
typst.compile("hello.typ", output="hello.pdf")
# Compile `hello.typ` to PNG and save as `hello.png`
typst.compile("hello.typ", output="hello.png", format="png", ppi=144.0)
# Or pass `hello.typ` content as bytes
with open("hello.typ", "rb") as f:
typst.compile(f.read(), output="hello.pdf")
# Or return PDF content as bytes
pdf_bytes = typst.compile("hello.typ")
# Use a fixed creation timestamp for reproducible PDFs
timestamp = datetime.datetime.fromtimestamp(0, datetime.timezone.utc)
pdf_bytes = typst.compile("hello.typ", timestamp=timestamp)
# Also for svg
svg_bytes = typst.compile("hello.typ", format="svg")
# Typst 0.15 minifies PDF, SVG, and HTML by default; pass pretty=True for
# human-readable export output.
svg_bytes = typst.compile("hello.typ", format="svg", pretty=True)
# Multiple compatible PDF standards can be requested at once.
pdf_bytes = typst.compile("hello.typ", pdf_standards=["a-2a", "ua-1"])
# For multi-page export (the template is the same as the typst cli)
images = typst.compile("hello.typ", output="hello{n}.png", format="png")
# Or use Compiler class to avoid reinitialization
compiler = typst.Compiler()
compiler.compile(input="hello.typ", format="png", ppi=144.0)
# Query something
import json
values = json.loads(typst.query("hello.typ", "<note>", field="value", one=True))
# Or use Typst's newer eval-style query expression
values = json.loads(typst.eval("hello.typ", "query(<note>).first().value"))
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):
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:
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:
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:
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.
#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.
Metadata
Release files for typst 0.15.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typst-0.15.0.tar.gz | 66.9 kB | Details |
Built distributions (wheels)
Total release size: 557.5 MB
Release files / typst-0.15.0.tar.gz
| Download URL | typst-0.15.0.tar.gz |
|---|---|
| Size | 66.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a60231b55f0a793c2401b26577522dbf7528207407b383de3a7f0cf7fd3ce28a
|
|
BLAKE2b-256 checksum How to use checksums |
95695d6700379124632f243c7eb2b41b3244ef991fe8ff29b27333e0bb655918
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-win_amd64.whl
| Download URL | typst-0.15.0-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 29.4 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5a942eb7a86885f30cd34c0f42c24bf14bd270fb20fe37e268b2061d7d783daa
|
|
BLAKE2b-256 checksum How to use checksums |
4b6b9715202f2179a00a8be7fee6e9c890d10dc41ac145c03e09ec336906e93f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | typst-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 34.1 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7007ccb3cd3cd3a5fe23876b413eca927b4d210ddbebc087b9394fe0cea8e91a
|
|
BLAKE2b-256 checksum How to use checksums |
2858a78f0620dceabbd4f2e5ee7dc377cfeb331ebaacd8c541de07c6a9892c47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | typst-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 35.2 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ IBM System/390x |
|
SHA-256 checksum How to use checksums |
0e2f5cd0cffc7a0d388ad6c38d7c1d7bc1cf630abfe1bc682e09614e8d203a48
|
|
BLAKE2b-256 checksum How to use checksums |
7f5bff49f4f2ed7591f76566e1f14fc46f4cfd638bf6be36ca6e0d3c9b54ee7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | typst-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 36.4 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ PowerPC 64-le |
|
SHA-256 checksum How to use checksums |
07351f26991ed61e732fe3f1035076ee6b4a241dcdef789e78cbcf3fcdb267d7
|
|
BLAKE2b-256 checksum How to use checksums |
0faeda45903d5b939a07979e4ba9a360f55cf76f2be1025a2ed3c631f07bbcdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | typst-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 34.4 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARMv7l |
|
SHA-256 checksum How to use checksums |
686fdf83684e4ada66a841442c6fcf8dc934e14ba5458fceb5cf50fb2a0c80d6
|
|
BLAKE2b-256 checksum How to use checksums |
44e1499c395e83ab44da091d51f99ece04dd7edcbb1b6cd5b2ec8ce5906202c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | typst-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 34.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
7152f62e1737d82d55650162f03534be4639ae800921a1a84848387c0f3b0ba4
|
|
BLAKE2b-256 checksum How to use checksums |
ca8332c54f97c2638076a4b5301b0c7d7b282f232c85bcab539ccb80284983dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | typst-0.15.0-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 30.5 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
89aafbd9f3d788b72486a90106d927f17dba1fe30c55c3522f77a201397bc107
|
|
BLAKE2b-256 checksum How to use checksums |
215efb330894aa9a80e39a5e9d0a3f6f3ea4fcb44ba883965635a281323a027d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | typst-0.15.0-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 30.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
880da56762b240649492186a24cc53427e8a41108b2e73fa337ac4cb314eb3b0
|
|
BLAKE2b-256 checksum How to use checksums |
928c53e4acb6095fc20d2ec981155a1b9a1364b34aa86a884a75f9be1addb88d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-win_amd64.whl
| Download URL | typst-0.15.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 29.4 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7c12706685dbaf5bb7e43f0fa32e57f2a42549b9ec3de539ad0d32bd8d1ca92e
|
|
BLAKE2b-256 checksum How to use checksums |
f25f7f19bc9f7a2917a52aa39981aff19f86972f4055b432f77f31642ab57625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-pyemscripten_2026_0_wasm32.whl
| Download URL | typst-0.15.0-cp38-abi3-pyemscripten_2026_0_wasm32.whl |
|---|---|
| Size | 25.7 MB |
| Tags | CPython 3.8 PyEmscripten 2026.0+ WebAssembly abi3 |
|
SHA-256 checksum How to use checksums |
019b4282daa892e0a540687efdd2909808a07453700332c7f61a2c1455950ec9
|
|
BLAKE2b-256 checksum How to use checksums |
073f6d526ddd93e6a7dd26c2b180245df8d1957d2723860030a10bcc0f93650c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | typst-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 34.2 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8f33d98451bab132a612b98ffc8d1830c97a076ea3f3fde11f6ff7ab9bcae89c
|
|
BLAKE2b-256 checksum How to use checksums |
2b57e2bb9b7823c049361c9e7d2d971996430b71260bfc3a7ed289ca4b37c1b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | typst-0.15.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 35.2 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
bb95304a78d4a068d7d19f036a9ab60872aca4e514a4abf214ff65e657ab9bc0
|
|
BLAKE2b-256 checksum How to use checksums |
d6673c78adb30f715cbcd0612039b621033a8a57c1d6053a7618837ddf6c19c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | typst-0.15.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 36.5 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
3eadd17f2170e48c73c386b7ccbab2fc1cc4a190969fce8bbad3b3cdc5bc58cf
|
|
BLAKE2b-256 checksum How to use checksums |
a5ddca5c10380b63d3f4914be09b694f34c7c7ba24640f2f0713076c77e6b8bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | typst-0.15.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 34.4 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
a400a27115b85acc020cc514c76ea1d56e607ac40e99e0d3e7413e105ff3485d
|
|
BLAKE2b-256 checksum How to use checksums |
5c1c6134b210a08c929663f7e3913713758fb475ce76696eea92aeba68f62d7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | typst-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 34.9 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
97350fcf5eebe5b6c75415e005ac42136744aa9950f4c0e4c484dc015e38d9de
|
|
BLAKE2b-256 checksum How to use checksums |
83b529e6218486259056c2649fb245c5066c3a821cb8b56d6710c3007062136a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | typst-0.15.0-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 30.5 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
98afafa47e372728bce7fe1153b8d3ace4619d6c3a549908989d65f9aec96247
|
|
BLAKE2b-256 checksum How to use checksums |
2ca98cb66f027d644572836423382a8e063c388c9d87fed474e0f499c4cb17e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|
Release files / typst-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | typst-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 30.9 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
a9c02ca7503d1916fb3eaa22aef413bd23b6d54abef5c6c5ecac8d1b804deb8d
|
|
BLAKE2b-256 checksum How to use checksums |
0d30cce48475a335eced15769252bc5b2631b02196f07c001ab34ccd79664afb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.14.0
|