Typst is really good for this. The syntax takes a little bit of getting used to but on the whole I’ve had a lot of success producing contracts and other legal documents with it. I tend to assemble the input files using a templating engine and then use the compiler in a subprocess. The compiler is very fast and the development is pretty active. The output is much easier to manage than with packages like reportlab.