Using the nbconvert Python library to write to disk

I am trying to turn the following CLI command into Python code using nbconvert:

jupyter nbconvert --to markdown \
  --template /path/to/my/template.tpl \
  --NbConvertApp.output_files_dir=/output/dir/for/images \
  --FilesWriter.build_directory=/output/dir/for/markdown_files \
  /path/to/my/notebook

I’m having a hard time figuring this out from the nbconvert library docs as it seems like there is a fair bit of extra steps that are taken when people use the CLI vs. the Python library.

I’ve figured out that I need to use the MarkdownExporter as well as the FilesWriter. And I think I am mostly there, but I have one main question:

How can I make the notebook outputs (e.g. images) go to a different location than the written markdown files?

Is there any extra documentation I’m missing on how to use the Python library? Or information specifically about this question?

If this is still relevant, here’s my solution (tl;dr, you have to provide path for storing the outputs via metadata). AFAIR I had to code dive for that.