diff --git a/docs/guides/server-integration.md b/docs/guides/server-integration.md new file mode 100644 index 000000000..3355fdd52 --- /dev/null +++ b/docs/guides/server-integration.md @@ -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. diff --git a/mesop/server/wsgi_app.py b/mesop/server/wsgi_app.py index 074433eb4..b8407e398 100644 --- a/mesop/server/wsgi_app.py +++ b/mesop/server/wsgi_app.py @@ -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 diff --git a/mkdocs.yml b/mkdocs.yml index b821c215e..42ee08b06 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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