You can learn more about weasyprint on their website (https://weasyprint.org/ ). It's an open source Python package that can be launched using cli or from Python code.
It uses pypdf, which is "pydyf is a low-level PDF generator written in Python and based on PDF specification 1.7" (from their README at https://github.com/CourtBouillon/pydyf ).
Compile a minimal python interpreter with tinycc &| cproc &| scc, run this pydyf and you should be good to go :)
Hopefully, its API a C API bridge for interop.
But pydyf pretends to go up to PDF 1.7: this is kind of arrogant due to the file format complexity.
That's why such tools are not enough: what's important is to evaluate and to assess a subset of the PDF format, that to reduce significantly the technical cost of ownership and exit cost, and maybe use such tools to write also validation tools in order to enforce the usage of that subset of PDF.
Very often, complex file formats (open or not) end up being generated and consumed by one program.
A warning: big tech and its minions will fight super hard everything that is simple, stable in table and does a good enough job (like noscript/basic (x)html for nearly all online services as they were working a few years back).