Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serving REST APIs as part of panel serve #1164

Merged
merged 10 commits into from
Jul 29, 2020
Merged

Allow serving REST APIs as part of panel serve #1164

merged 10 commits into from
Jul 29, 2020

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 19, 2020

Allows serving using panel serve some_script.py some_notebook.ipynb --tranquilize to serve REST APIs alongside the panel apps. Automatically discovers any tranquilized functions.

import panel as pn

from tranquilizer import tranquilize

@tranquilize()
def order(cheese):
    '''I'd like to buy some cheese!'''
    return {'response':"I'm afraid we're fresh out of {}, Sir.".format(cheese)}

pn.panel("# A panel app").servable()

e.g. this will serve the Panel app on http://localhost:5006/ and the REST API on http://localhost:5006/rest/order.

@codecov
Copy link

codecov bot commented Mar 19, 2020

Codecov Report

Merging #1164 into master will decrease coverage by 0.57%.
The diff coverage is 26.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1164      +/-   ##
==========================================
- Coverage   86.27%   85.70%   -0.58%     
==========================================
  Files         143      144       +1     
  Lines       15786    15932     +146     
==========================================
+ Hits        13620    13654      +34     
- Misses       2166     2278     +112     
Impacted Files Coverage Δ
panel/io/state.py 44.58% <20.37%> (-12.68%) ⬇️
panel/io/rest.py 26.96% <26.96%> (ø)
panel/command/serve.py 19.10% <28.57%> (+1.76%) ⬆️
panel/util.py 82.08% <100.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 844c883...5dd78de. Read the comment docs.

@jlstevens
Copy link
Contributor

This is great, thanks! I'll now check out this branch and test it...

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Mar 21, 2020

As far as I can see this supports

  • parameters: like ?cheese=goatcheese ?
  • get, post, put, delete requests?
  • open api documentation?

If possible it would be so great if this supported

  • serving csv and xlsx files as well.

and the documentation hinted at how to use this in practice using serializers etc.

I know I'm hoping for a lot. :-)

I've added a feature request to tranquilizer for serving csv, xlsx and parquet files ContinuumIO/tranquilizer#20.

@philippjfr
Copy link
Member Author

I think for file serving we can easily add a simple static file request handler rather than building that on Tranquilizer or some other REST API.

@mattpap
Copy link
Collaborator

mattpap commented Mar 21, 2020

tranquilized functions

Is this a well defined term? Seeing just the title of this PR I didn't have any idea what to expect from its contents. I would use well known and defined terms like REST API across the board, and leave the name of the library as an implementation detail. So on the command like I would just use something along --allow-rest-apis or --serve-rest.

@philippjfr
Copy link
Member Author

Yeah, I hear you, we're still iterating on what we actually want to support and this PR was mostly a prototype for a client.

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Mar 21, 2020

@philippjfr . I would like to serve some static files like sphinx documentation, some Angular .js files or similar. But the most important is actually to serve dynamic data in csv, xlsx and parquet format.

My primary use case is creating a dashboard and when the user gets to a dead end in the dashboard/ wants more she can get a link to the exact data in the plot, table or similar depending on the state of the app/ the value of sliders, dropdowns etc. She can use the link to download the data here and now. But also store or share the link. Or use PowerQuery in excel to setup a permanent link. Build her own small Panel app using Pandas and use the link to get the data etc.

Dynamic, shareable links are powerfull.

@philippjfr
Copy link
Member Author

I understand that's a very different thing from a REST API though and is already covered by this issue of yours: #1118

@philippjfr philippjfr changed the title Allow serving tranquilized functions as part of panel serve Allow serving REST APIs as part of panel serve Mar 30, 2020
@philippjfr philippjfr force-pushed the tranquilize branch 2 times, most recently from 90c26e0 to e9ff759 Compare April 2, 2020 18:32
Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@philippjfr philippjfr merged commit 4be32f4 into master Jul 29, 2020
@philippjfr philippjfr deleted the tranquilize branch July 29, 2020 11:00
@JuliaS92
Copy link

JuliaS92 commented Jan 20, 2021

Hi @philippjfr, as far as I understand this was part of the 0.10.0 release. Could you please provide an updated minimal example of how to use this? I tried the code snippet from the top of this thread and neither panel version 0.10.0, nor 0.10.3 accepted the --tranquilize option and it seems there are several --rest.. options added instead.

UPDATE: I just found the example in the version blog, so just for reference if anybody else looks for this here:
http://blog.holoviz.org/panel_0.10.0.html#Tranquilizer-REST-Provider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants