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

Add docs for mounting Mesop app #892

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/guides/server-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Server integration

Mesop allows you to integrate Mesop with other Python web servers like FastAPI or Flask by mounting the Mesop app which is a [WSGI](https://wsgi.readthedocs.io/en/latest/what.html) app.

This enables you to do things like:

- Serve local files (e.g. images)
- Provide API endpoints (which can be called by the web component, etc.)

## API

The main API for doing this integration is the `create_wsgi_app` function.

::: mesop.server.wsgi_app.create_wsgi_app

## FastAPI example

For a working example of using Mesop with FastAPI, please take a look at this repo:
[https://github.com/wwwillchen/mesop-fastapi](https://github.com/wwwillchen/mesop-fastapi)

> Note: you can apply similar steps to use any other web framework that allows you to mount a WSGI app.
5 changes: 4 additions & 1 deletion mesop/server/wsgi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def create_app(

def create_wsgi_app(*, debug_mode: bool = False):
"""
Creates a WSGI app that can be used to run Mesop in a WSGI server.
Creates a WSGI app that can be used to run Mesop in a WSGI server like gunicorn.

Args:
debug_mode: If True, enables debug mode for the Mesop app.
"""
_app = None

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nav:
- Multi-Pages: guides/multi-pages.md
- Auth: guides/auth.md
- Theming: guides/theming.md
- Server integration: guides/server-integration.md
- Development:
- Debugging: guides/debugging.md
- Testing: guides/testing.md
Expand Down
Loading