Skip to main content

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

Project description

typst-py

CI PyPI Documentation Status

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typst-0.15.0.tar.gz (66.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

typst-0.15.0-cp314-cp314t-win_amd64.whl (29.4 MB view details)

Uploaded CPython 3.14tWindows x86-64

typst-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

typst-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl (35.2 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ s390x

typst-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (36.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ppc64le

typst-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (34.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARMv7l

typst-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (34.9 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

typst-0.15.0-cp314-cp314t-macosx_11_0_arm64.whl (30.5 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

typst-0.15.0-cp314-cp314t-macosx_10_12_x86_64.whl (30.9 MB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

typst-0.15.0-cp38-abi3-win_amd64.whl (29.4 MB view details)

Uploaded CPython 3.8+Windows x86-64

typst-0.15.0-cp38-abi3-pyemscripten_2026_0_wasm32.whl (25.7 MB view details)

Uploaded CPython 3.8+PyEmscripten 2026.0 wasm32

typst-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

typst-0.15.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (35.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

typst-0.15.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (36.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

typst-0.15.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (34.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

typst-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (34.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

typst-0.15.0-cp38-abi3-macosx_11_0_arm64.whl (30.5 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

typst-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl (30.9 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file typst-0.15.0.tar.gz.

File metadata

  • Download URL: typst-0.15.0.tar.gz
  • Upload date:
  • Size: 66.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for typst-0.15.0.tar.gz
Algorithm Hash digest
SHA256 a60231b55f0a793c2401b26577522dbf7528207407b383de3a7f0cf7fd3ce28a
MD5 f536ec0a21967a183980d0dd4583b624
BLAKE2b-256 95695d6700379124632f243c7eb2b41b3244ef991fe8ff29b27333e0bb655918

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-win_amd64.whl.

File metadata

  • Download URL: typst-0.15.0-cp314-cp314t-win_amd64.whl
  • Upload date:
  • Size: 29.4 MB
  • Tags: CPython 3.14t, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for typst-0.15.0-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 5a942eb7a86885f30cd34c0f42c24bf14bd270fb20fe37e268b2061d7d783daa
MD5 596f559628fd3d49c01d6e6552fc7eb9
BLAKE2b-256 4b6b9715202f2179a00a8be7fee6e9c890d10dc41ac145c03e09ec336906e93f

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7007ccb3cd3cd3a5fe23876b413eca927b4d210ddbebc087b9394fe0cea8e91a
MD5 91024d6a05017fc20081db1cf51cfb85
BLAKE2b-256 2858a78f0620dceabbd4f2e5ee7dc377cfeb331ebaacd8c541de07c6a9892c47

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 0e2f5cd0cffc7a0d388ad6c38d7c1d7bc1cf630abfe1bc682e09614e8d203a48
MD5 6bb3ab3185471c6c1401bf9afd90f7d8
BLAKE2b-256 7f5bff49f4f2ed7591f76566e1f14fc46f4cfd638bf6be36ca6e0d3c9b54ee7d

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 07351f26991ed61e732fe3f1035076ee6b4a241dcdef789e78cbcf3fcdb267d7
MD5 ac37a1411a1526398b7716199b8bdcf4
BLAKE2b-256 0faeda45903d5b939a07979e4ba9a360f55cf76f2be1025a2ed3c631f07bbcdd

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 686fdf83684e4ada66a841442c6fcf8dc934e14ba5458fceb5cf50fb2a0c80d6
MD5 4d480b116e6c48f0c686ea6514c05105
BLAKE2b-256 44e1499c395e83ab44da091d51f99ece04dd7edcbb1b6cd5b2ec8ce5906202c6

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7152f62e1737d82d55650162f03534be4639ae800921a1a84848387c0f3b0ba4
MD5 861fe1f4bb20e80257d269f096822f06
BLAKE2b-256 ca8332c54f97c2638076a4b5301b0c7d7b282f232c85bcab539ccb80284983dd

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89aafbd9f3d788b72486a90106d927f17dba1fe30c55c3522f77a201397bc107
MD5 bfdc201135516618232b20d29be86f1a
BLAKE2b-256 215efb330894aa9a80e39a5e9d0a3f6f3ea4fcb44ba883965635a281323a027d

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp314-cp314t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 880da56762b240649492186a24cc53427e8a41108b2e73fa337ac4cb314eb3b0
MD5 b3605cfec184820c0261f53fc9b35c5a
BLAKE2b-256 928c53e4acb6095fc20d2ec981155a1b9a1364b34aa86a884a75f9be1addb88d

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: typst-0.15.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 29.4 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for typst-0.15.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7c12706685dbaf5bb7e43f0fa32e57f2a42549b9ec3de539ad0d32bd8d1ca92e
MD5 65afc42d3de9b9c163e77dc0df13ab78
BLAKE2b-256 f25f7f19bc9f7a2917a52aa39981aff19f86972f4055b432f77f31642ab57625

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-pyemscripten_2026_0_wasm32.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 019b4282daa892e0a540687efdd2909808a07453700332c7f61a2c1455950ec9
MD5 e962be92291cb9427e34c85b421130fb
BLAKE2b-256 073f6d526ddd93e6a7dd26c2b180245df8d1957d2723860030a10bcc0f93650c

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f33d98451bab132a612b98ffc8d1830c97a076ea3f3fde11f6ff7ab9bcae89c
MD5 91a566f1f174fdb125b4c35752ceb918
BLAKE2b-256 2b57e2bb9b7823c049361c9e7d2d971996430b71260bfc3a7ed289ca4b37c1b0

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 bb95304a78d4a068d7d19f036a9ab60872aca4e514a4abf214ff65e657ab9bc0
MD5 bcac95a546ce6bfff6e1a6cf48b76bbb
BLAKE2b-256 d6673c78adb30f715cbcd0612039b621033a8a57c1d6053a7618837ddf6c19c4

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 3eadd17f2170e48c73c386b7ccbab2fc1cc4a190969fce8bbad3b3cdc5bc58cf
MD5 58cc73fefa8ac19175f09dd3290fb958
BLAKE2b-256 a5ddca5c10380b63d3f4914be09b694f34c7c7ba24640f2f0713076c77e6b8bb

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a400a27115b85acc020cc514c76ea1d56e607ac40e99e0d3e7413e105ff3485d
MD5 23072bfa33d0339f5a5661bf3eb4a86e
BLAKE2b-256 5c1c6134b210a08c929663f7e3913713758fb475ce76696eea92aeba68f62d7f

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 97350fcf5eebe5b6c75415e005ac42136744aa9950f4c0e4c484dc015e38d9de
MD5 fe7e5ce570ae7bbe832bafd419566834
BLAKE2b-256 83b529e6218486259056c2649fb245c5066c3a821cb8b56d6710c3007062136a

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98afafa47e372728bce7fe1153b8d3ace4619d6c3a549908989d65f9aec96247
MD5 c7619ff0f34dacff8cdcb6d90d577a56
BLAKE2b-256 2ca98cb66f027d644572836423382a8e063c388c9d87fed474e0f499c4cb17e1

See more details on using hashes here.

File details

Details for the file typst-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for typst-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a9c02ca7503d1916fb3eaa22aef413bd23b6d54abef5c6c5ecac8d1b804deb8d
MD5 2ba896cb2bdbfca3d6ed917998aaa408
BLAKE2b-256 0d30cce48475a335eced15769252bc5b2631b02196f07c001ab34ccd79664afb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page