☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Recommended pattern for adding custom session state that should stay on the server?

Community Supportserver
hrbigelow
hrbigelow

Hi,

I have a bokeh server app and a bokeh.application.handlers.Handler derived class in which I would like to add custom session state that should not go in the Document (or at least, I don’t intend for it to be sent to the client). The other option seems to be to augment the SessionContext in the on_session_created method. Is there another way?

I did also override process_request and do use a few extra pieces of information there. But, the content returned by process_request must be json-serializable and is sent to the client.

⌁   Link to post
Bryan
Bryan

This is a reasonable approach and what I would suggest at the present time. If you have any concrete suggestions for new APIs to help make this simpler or easier, please feel free to submit an issue or PR. There’s been a few casual discussions about this in the past but they were never focused enough on tangible use-cases to move forward.

⌁   Link to post
hrbigelow
hrbigelow

Great, thanks Bryan. For the moment I’m using this technique and it seems to work great. I’ll see how it goes and maybe submit a PR if I have more insights.

At the moment the only suggestion I would have would be to add some (initially empty) reserved property on SessionState (not sure what to call it though) documented to be used for this purpose.
Perhaps also to document ctx.token_payload a bit clearer to mention that it is state that should be serializable and will be propagated between client and server.

I have definitely implemented a tangible use-case for it shown here:

This mainly runs a “refresh data” coroutine which pushes data and holds logic for updating server-side ColumnDataSources. I did try lots of other approaches before this and for various reasons they didn’t work, but I could have missed something of course.

⌁   Link to post

End of archived discussion · Replies are disabled