How to generate pdf with typst syntax using python?

You can pass all files as a JSON-object, for example. If you have have a folder csvs/, you can load all of them in python as a json string:

import subprocess
import glob
import os
import json

folder_path = "csvs"

files = glob.glob(
    os.path.join(folder_path, "*.csv")
)

json_files = json.dumps(files)

subprocess.run([
    "typst",
    "c",
    "main.typ",
    "--input",
    f"files={json_files}"
], capture_output=True, text=True)

and then read it in typst:

#let files = json.decode(sys.inputs.files)

#files


#for f in files {
  let data = csv(f)
  // do what you want with the files
}
2 Likes