mesop Basics

Development Environment Installation

  1. Download and install python 3.1x
  2. Install VSCode
  3. Install vscode Extensions
    Python : Microsoft

Create Virtual Dev Environment

  1. install virtualenv
    windows: pip install virtualenv
    osx: pip3 install virtualenv
  2. Create the virtual enviroment
    virtualenv env (env is the virtural enviroment name)
  3. Activate the virtural enviroment
    windows: env\scripts\activate
    osx: source env/bin/activate
    your prompt should now look like
    (env) PS path…. windows: env\scripts\deactivate
    osx: source env/bin/deactivate

Install App Development Requirements

osx: pip3 install mesop

windows:    pip install mesop

Create a Basic Web App

create a file web1.py

add the folllowing

import mesop as me

@me.page(path=”/”)
def foo():
me.text(“This ia a basic page”)

Running The web app
Run the following in the terminal

mesop web1.py

Create a Multipage Web App with state

create a file web2.py

add the folllowing

import mesop as me

def on_click(e: me.ClickEvent):
state = me.state(State)
state.count += 1
me.navigate(“/multi_page_nav/page_2”)

@me.page(path=”/multi_page_nav”)
def main_page():
me.button(“Navigate to Page 2”, on_click=on_click)

@me.page(path=”/multi_page_nav/page_2″)
def page_2():
state = me.state(State)
me.text(f”Page 2 – count: {state.count}”)

@me.stateclass
class State:
count: int

Running The web app
Run the following in the terminal

mesop web2.py