How to programmatically generate download link?

In a notebook, I want to programmatically generate a download link and pass that URL to a Javascript-based visualization tool for display.

In classic Notebook I was able to do this simply by prepending files/ to the relative URL. For example: files/data/file_to_display.bam. I could then pass that relative URL to the visualization and it would work. In JupyterLab, however, it doesn’t work.

So is there a way to reliably generate a download link to a local file? (from the kernel)

P.S. I noticed that IPython.display.FileLink generates an HTML tag that works when displayed, but I haven’t been able to figure out a way programmatically get the URL in the kernel.