typst-py
typst-py copied to clipboard
Passing json data as argument parameter
I think it would be desirable to pass json data directly to typst. Without needing typst to read the json file from disk.
What json data? Can you elaborate?
I'm sorry for my unclear explanation.
I meant that it would be desirable for generating dynamic documents, to have an API such as the following:
import typst
compiler = typst.Compiler(".")
json_file = get_json_file()
pdf_bytes = typst.compile("hello.typ", json_file=json_file)
So in the document I could retrieve the json file in a way like:
#let data = json(json_file)
Or something else in a similar way.
The advantage is to load json in memory, instead of writing the json in a directory and making typst reading it.
I don't know if that is possible without deeper modifications to typst though.
We found a plausible path to solve this feature in: https://github.com/typst/typst/issues/1158#issuecomment-1541199060
It would be awesome if you could add some documentation on how to access data files (JSON, CSV, etc.) or images when using this library. I. e. what is the default working directory and (how) can it be changed?
@barredterra See API in https://github.com/messense/typst-py/blob/main/python/typst/init.pyi