holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.63k stars 504 forks source link

Allow to easily register custom request handlers #6009

Open maximlt opened 9 months ago

maximlt commented 9 months ago

My use case is that I was trying to see how I'd allow users to download very large non-static files (e.g. streamed from elsewhere) to users of my app. I thought that maybe I could just build links that'd expose these files to download, these links pointing to another endpoint of my app that when hit would start the download. Something along those lines.

Panel allows to set up one of two REST provides: param and tranquilizer (with e.g. --rest-provider param). Users can register other REST providers via the panel.io.rest entry point (I've actually not tried that). However, and if I understand correctly, this means that you need to build a package.

I'm wondering whether it wouldn't be easier to allow users to register custom request handlers in their setup script (--setup mysetup.py). Maybe exposing a global CUSTOM_PATTERNS list that users could import and extend as they like.

philippjfr commented 9 months ago

Should be trivial to implement, we already support this via the extra_patterns argument in pn.serve and the same could be achieved by extracting some fixed variable from the --setup script.

maximlt commented 9 months ago

Ah indeed I missed extra_patterns in get_server, might be worth documenting that better.

the same could be achieved by extracting some fixed variable from the --setup script.

You mean that users would have to define some specific variable like extra_patterns = [...] and we'd look for them after executing the module? Not sure I like that so much, linters won't for sure :D What's against extending a global list?

MarcSkovMadsen commented 1 month ago

I would like to add a custom tornado handler too. I would be running panel serve pages/*.py .... How would I add a custom tornado handler using this setup?