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

Python: support fastapi APIs in Viewer Pane #3024

Closed
isabelizimm opened this issue May 6, 2024 · 1 comment
Closed

Python: support fastapi APIs in Viewer Pane #3024

isabelizimm opened this issue May 6, 2024 · 1 comment
Assignees
Labels
area: viewer Issues related to Viewer category. enhancement New feature or request lang: python theme: app builder

Comments

@isabelizimm
Copy link
Contributor

To fully support fastapi, we would want to be able to:

  • recognize fastapi Python files and have a gesture to click "Play" and run in terminal
  • automatically open running APIs in Viewer pane

Notes:

We might want to have Play options for fastapi dev app.py as well as fastapi run app.py; running fastapi in dev mode will auto-reload the API endpoint and is convenient for iterating on a file. FastAPI uses a lot of starlette under the hood, so we might be able to get starlette support for free when implementing fastapi.

@isabelizimm isabelizimm added the enhancement New feature or request label May 6, 2024
@juliasilge juliasilge added area: viewer Issues related to Viewer category. lang: python labels May 6, 2024
@juliasilge juliasilge added this to the Release Candidate milestone May 6, 2024
seeM added a commit that referenced this issue Sep 23, 2024
This PR adds support for local Python application development for the
following frameworks:

* Streamlit
* Dash
* Gradio
* FastAPI
* Flask

This is facilitated by a new extension: `positron-run-app`.

Addresses #4557,
#4555, #3023, #3027, #3024.

https://github.com/user-attachments/assets/d72e5028-a8c9-4aab-b927-4413c4e74b24

### QA notes

1. Open an application developed using one of the supported frameworks.
2. Run the relevant "Python: Run X App in Terminal" command. It should
also be the default action if you click the run button in the editor
menu.
3. It should create a terminal named after the framework, and
automatically show the app in the Viewer pane once its ready.

Here are example apps for all of the supported frameworks:

#### Streamlit

```python
import streamlit as st
x = st.slider('x')
st.write(x, 'squared is', x * x)
```

#### Dash

```python
from dash import Dash, html
app = Dash()
app.layout = [html.Div(children='Hello World')]
if __name__ == '__main__':
    app.run(debug=True)
```

#### Gradio

```python
import gradio as gr
def image_classifier(inp):
    return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
demo.launch()
```

#### FastAPI

```python
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
    return {"message": "Hello World"}
```

#### Flask

```python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"
```

### Next steps: Workbench integration

To support Workbench, we'll need to update `runApplication` to detect if
we're in Workbench, and if so, find a free port and corresponding
proxied URL (possibly related to
#4274) and pass them both to
`getTerminalOptions`.
@testlabauto
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.09.0-95
OS Version          : OSX

Test scenario(s)

Added fastapi example to qa-example-content and ran with customized menu

Link(s) to TestRail test cases run or created:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: viewer Issues related to Viewer category. enhancement New feature or request lang: python theme: app builder
Projects
None yet
Development

No branches or pull requests

4 participants