Skip to main content

No project description provided

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 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")

# Also for svg
svg_bytes = typst.compile("hello.typ", format="svg")

# 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))

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.

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.14.8.tar.gz (62.4 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.14.8-cp314-cp314t-win_amd64.whl (21.5 MB view details)

Uploaded CPython 3.14tWindows x86-64

typst-0.14.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.0 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

typst-0.14.8-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl (27.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ s390x

typst-0.14.8-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (28.0 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ppc64le

typst-0.14.8-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (26.5 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARMv7l

typst-0.14.8-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.9 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

typst-0.14.8-cp314-cp314t-macosx_11_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

typst-0.14.8-cp314-cp314t-macosx_10_12_x86_64.whl (22.9 MB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

typst-0.14.8-cp38-abi3-win_amd64.whl (21.5 MB view details)

Uploaded CPython 3.8+Windows x86-64

typst-0.14.8-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.0 MB view details)

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

typst-0.14.8-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (27.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

typst-0.14.8-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (28.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

typst-0.14.8-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (26.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

typst-0.14.8-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

typst-0.14.8-cp38-abi3-macosx_11_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

typst-0.14.8-cp38-abi3-macosx_10_12_x86_64.whl (22.9 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for typst-0.14.8.tar.gz
Algorithm Hash digest
SHA256 8ffb8d5896aa6a20a7b88ae3fa1dfcf062fdd09b5b6a0a164f92f78ad1a2d8cd
MD5 940cb1924d39ef84c265354cd38c9ad1
BLAKE2b-256 0e17011059074fe6c51ed775991d5066c73443f17d49b3d4ab9c1a969dcdb5cb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for typst-0.14.8-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 10710c58dbc8820a954970ba5d0af5611c7c57f8ddacfebb1a85ddb6449f01eb
MD5 79f9add9ef1e6f37c55af31436900b71
BLAKE2b-256 5bca44732fc1e486be822ba65ee9a02f0bc5f28d1cb08284c9dd1286d975f9ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b509e7a599dd07e36e18495f0258511de527f5e0dc145622025d204c84db5246
MD5 ecc1e122b5503f30343afc90903ec620
BLAKE2b-256 5197b1f43e29051401289b6ef37398eb83d78584f52e0b213f8675b9b10b0c0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 e1cfbc313ba3b883da8c45233506766a503da307057a5d8d39e360023733c463
MD5 5c76c37e6b0137f5c026793568d649fc
BLAKE2b-256 611b8769c89998299525e4b04fddce1b15977d18051695c65760203b55f7ed47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 37da60ec4afcd82b55664612aab10cac11a8ebc075686057705261de9e901523
MD5 e6c0febf2fc25e90a8cc367f05f65c3b
BLAKE2b-256 272b3b1256033c7b971d0c79af41fadff552c1df7a9f9774a540f1a2ede97937

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d8c4ac751c3480b0fcfc7fce273025bb7392654db5a3aa65904f8678192c54f8
MD5 10041817efa5e229484dcf7c2d2e748f
BLAKE2b-256 ee328754413c4cdf631c51e16690775dcfd28e783c1ccc0efc71d92ef73e0db3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f9db137ca037bd12c0ebbbbfa1190fffaa75a2043d04adacb273cc98f0265a32
MD5 1725049f3cbf578d5ca8ee93f77dd165
BLAKE2b-256 7738070c068442a8be93125366b27e5cf1a6b1dd62c85dab62bd6d4355643d29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e2ecb523ff7e3eb68667ad693ff4c460ac58aedfbeb6514054efce2718e7563f
MD5 dca906ae122eff9cb5cc90f458d2adbf
BLAKE2b-256 6f93cbb32c7e830a806105ee0f6d9b6c780f2736a9c75d8121602e7842a316d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4697b9de12d7b1bc85209960e1ef7e2c4947cffd7d6ef68201aea03597cf38bd
MD5 2bf91ead666577a8df1a5c37de09b291
BLAKE2b-256 d267af5551e95261fc425f6dbf241ec08bf1172fd10ef239787ff6e009bb2f08

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for typst-0.14.8-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 66eb2ebfe13275cf2a63ed7ff261eb5af3da5293077a5d6ca16e27a96d0d2f5e
MD5 b4b2fefe4a2bbb66be91185d0f3f0f87
BLAKE2b-256 a942db15d775c09f0da92191ea1b50cee056e46b599bb5524e2d8ff51f973765

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a12766a83e390377008722a8c80afdd9195a297261fd3c9d1f3720f9aecd2b19
MD5 919e6161f1f60f456c3a6aa11216d704
BLAKE2b-256 4c6fff1c58dac9245d4c355bfced006090b14a2f17497e9cf79a84d9d720663a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 7a19cf938607c73fd8c5245a7cb32c94af413080a3d747fcf7e16df88713c686
MD5 af8176a9bdedf3de5a549e8e768e9655
BLAKE2b-256 11a115cd399dfc5ce0ea9e05d5bbc274c95f8ecababc04b4210bae8d583fe454

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 6e3891a2e5551017c9030dd6de31587a29b97c18464df6bcff05f30f7cdab677
MD5 864d131f15f8bf4358cd955fb283b8b8
BLAKE2b-256 7e28094d4b9f0ff4ee81f88eee2df00dbcfbd961070df981973bc385a1544ff8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a296f85bf0d27043b031d1d2d74a34802e4876a8936f70784fbe99021b0dad4d
MD5 3e351e60ba6d5ea0325add72b3c20c3d
BLAKE2b-256 bce83efdebcf37639daa4799e7a4c833a280f14685f7e6058fed576c6fb2e722

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 544fcd9ce55b140115d7442b3661c45897778650c307e2eb0749efed29bbfcea
MD5 387ded0119cf4f21fce48ae2253c85f8
BLAKE2b-256 6fb487d2d24078b94645ba8788c8b4a5bbab6a3c779370141c31a02e2003ee0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aba11243463f6994ca1140b8515e70be1a98fd3025ae3211b84103499b0c5a5a
MD5 e4a31862151efa33e5292f91e9806d73
BLAKE2b-256 f86bd36f312c32b70303abd88d0abe6ffb50f8f7fcc0b457c914c78d791ed934

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for typst-0.14.8-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f47fe029f6ebe907f981ce0cb5208eab27eaf7342e319e6c798ac1dbae976f58
MD5 f421213da3734670cf40aafe3d1d3aa8
BLAKE2b-256 5bcbe49219a75d39ce866ae5d64e0a1d8d712b394ed3a1e7de3a8f4a35cde78e

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