typst-py icon indicating copy to clipboard operation
typst-py copied to clipboard

Passing json data as argument parameter

Open rousbound opened this issue 2 years ago • 5 comments
trafficstars

I think it would be desirable to pass json data directly to typst. Without needing typst to read the json file from disk.

rousbound avatar May 09 '23 04:05 rousbound

What json data? Can you elaborate?

messense avatar May 09 '23 09:05 messense

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.

rousbound avatar May 09 '23 18:05 rousbound

We found a plausible path to solve this feature in: https://github.com/typst/typst/issues/1158#issuecomment-1541199060

rousbound avatar May 10 '23 03:05 rousbound

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 avatar Mar 17 '25 19:03 barredterra

@barredterra See API in https://github.com/messense/typst-py/blob/main/python/typst/init.pyi

messense avatar Mar 18 '25 04:03 messense