Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/messense/typst-py
Python binding to typst
https://github.com/messense/typst-py
typst
Last synced: 10 days ago
JSON representation
Python binding to typst
- Host: GitHub
- URL: https://github.com/messense/typst-py
- Owner: messense
- License: apache-2.0
- Created: 2023-04-02T15:20:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-01T11:55:14.000Z (about 1 month ago)
- Last Synced: 2024-10-16T00:41:27.718Z (24 days ago)
- Topics: typst
- Language: Rust
- Homepage:
- Size: 6.36 MB
- Stars: 105
- Watchers: 3
- Forks: 11
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-typst - typst-py - Python binding to typst (Integrations & Tools / Programming)
- awesome-typst-cn - typst-py - based typesetting system that is powerful and easy to learn. (编程 / 杂项)
README
# typst-py
![CI](https://github.com/messense/typst-py/workflows/CI/badge.svg)
[![PyPI](https://img.shields.io/pypi/v/typst.svg)](https://pypi.org/project/typst)Python binding to [typst](https://github.com/typst/typst),
a new markup-based typesetting system that is powerful and easy to learn.## Installation
```bash
pip install typst
```## Usage
```python
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 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("hello.typ")
compiler.compile(format="png", ppi=144.0)# Query something
import jsonvalues = json.loads(typst.query("hello.typ", "", field="value", one=True))
```## License
This work is released under the Apache-2.0 license. A copy of the license is provided in the [LICENSE](./LICENSE) file.