messense / typst-py

Python binding to typst
Apache License 2.0
103 stars 11 forks source link

Passing json data as argument parameter #5

Open rousbound opened 1 year ago

rousbound commented 1 year ago

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

messense commented 1 year ago

What json data? Can you elaborate?

rousbound commented 1 year ago

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 commented 1 year ago

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