How to access query_params when running Panel using FastAPI?

Hi All!

I’m trying to embed Panel application in FastAPI using instructions from https://panel.holoviz.org/how_to/integrations/FastAPI.html and I need to provide query params to initialize Panel app state, unfortunately pn.state.location.query_params is always empty, is there a different way to get query params inside of Panel app running in FastAPI?

1 Like

I can confirm that pn.state.location.query_params is empty via

import panel as pn
from fastapi import FastAPI
from panel.io.fastapi import add_application

app = FastAPI()


@app.get("/")
async def read_root():
    return {"Hello": "World"}


@add_application("/panel", app=app, title="My Panel App")
def create_panel_app():
    slider = pn.widgets.IntSlider(name="Slider", start=0, end=10, value=3)
    return pn.Column(
        pn.state.location.query_params,
        slider.rx() * "⭐",
    )

If you open http://127.0.0.1:8000/panel?hello=world you see

image

I’ve reported it as a bug here No query_params, session_args or FastAPI Query Params · Issue #7338

1 Like

Thanks a lot @Marc!

1 Like