### Installing py4web with Virtual Environment on Linux/MacOS Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst These commands guide users through creating and activating a Python virtual environment, installing py4web and its dependencies within it, and then performing initial setup tasks like creating an 'apps' folder and setting an admin password, finally starting the py4web server. ```Shell python3 -m venv venv . venv/bin/activate python -m pip install --upgrade py4web --no-cache-dir python py4web setup apps python py4web set_password python py4web run apps ``` -------------------------------- ### Installing Py4web Globally from Source (Linux/MacOS) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet details the process of cloning the py4web repository, building assets, running tests, installing it globally using pip from the local source, and then performing initial setup and starting the application. This method is typically for Linux and macOS. ```Shell git clone https://github.com/web2py/py4web.git cd py4web make assets make test python -m pip install . py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Displaying py4web Setup Command Help Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command displays the help message for the `py4web setup` utility, detailing its usage and options like `--yes`. It explains how to create or reinstall an applications folder, providing guidance for initial setup or re-initialization. ```Shell py4web setup -h ``` -------------------------------- ### Installing py4web with Virtual Environment on Windows Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This set of commands provides instructions for Windows users to set up py4web within a virtual environment. It covers creating the environment, activating it using the batch script, installing py4web via pip, and then running py4web-specific setup commands to initialize apps, set a password, and start the server. ```Batch run cmd.exe In e.g. folder c:\py4web python3 -m venv venv "C:\py4web\venv\Scripts\activate.bat" python -m pip install --upgrade py4web --no-cache-dir cd venv\scripts py4web.exe setup apps py4web.exe set_password py4web.exe run apps ``` -------------------------------- ### Starting Py4web (Virtual Environment) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command is used to start the py4web application after it has been installed and configured within a virtual environment. It initiates the server and makes the applications accessible. ```Shell python py4web run apps ``` -------------------------------- ### Starting py4web Server Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command is used to start the py4web server, which will serve applications located in the 'apps' folder. It is a universal command that works whether py4web is installed in a virtual environment or globally. ```Shell python py4web run apps ``` -------------------------------- ### Displaying Py4web Setup Help (Shell) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This snippet displays the help output for the `py4web setup` command, outlining its usage and options. It explains how to create or reinstall an applications folder, with an option (`-Y` or `--yes`) to bypass confirmation prompts. ```Shell # py4web setup -h Usage: py4web.py setup [OPTIONS] APPS_FOLDER Setup new apps folder or reinstall it Options: -Y, --yes No prompt, assume yes to questions [default: False] -help, -h, --help Show this message and exit. ``` -------------------------------- ### Getting Help for py4web call Command Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command provides detailed help and usage information for the `py4web call` subcommand. It lists available options, arguments, and examples specific to calling functions within py4web applications from the command line. ```Shell # py4web call -h ``` -------------------------------- ### Installing py4web from Source (Global) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This sequence of commands details how to install py4web directly from its source code repository. It involves cloning the Git repository, building necessary assets, running tests, installing the package locally, and then performing the standard setup and server launch procedures. This method is typically used on Linux and MacOS. ```Shell git clone https://github.com/web2py/py4web.git cd py4web make assets make test python -m pip install . py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Setting up and Running py4web after Global pip Install Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst After a global pip installation, these commands are used to perform the initial setup of py4web, including creating the default 'apps' folder, setting an administrative password, and finally launching the py4web server to host applications. ```Shell py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Installing py4web from Source using Git and Pip Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This sequence of commands clones the py4web repository from GitHub, navigates into the newly created directory, and then installs py4web in editable mode using pip. This method ensures you get the latest changes directly from the master branch, suitable for development or testing new features. ```Bash git clone https://github.com/web2py/py4web.git cd py4web python3 -m pip install --upgrade -e . ``` -------------------------------- ### Running py4web from Binaries Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst After downloading and unzipping the py4web binaries, these commands are used to set the administrative password and start the py4web server. The './' prefix should be omitted if you are running these commands on Windows. This method is ideal for beginners as it doesn't require Python pre-installation. ```Bash ./py4web set_password ./py4web run apps ``` -------------------------------- ### Configuring Google Cloud SDK for py4web Deployment Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst These commands automate the setup process for Google Cloud deployment. They install the GCloud SDK, perform initial py4web setup, and configure the `gcloud` CLI with the user's Google email and project ID for authentication and target project selection. ```Shell make install-gcloud-linux make setup gcloud config set {your email} gcloud config set {project id} ``` -------------------------------- ### Running py4web from Binaries Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html These commands are used to initialize and run py4web when installed from pre-compiled binaries. `set_password` configures the administrative password, and `run apps` starts the server, serving applications from the 'apps' folder. Omit './' on Windows. ```Shell ./py4web set_password ./py4web run apps ``` -------------------------------- ### Installing Py4web with Pip in a Virtual Environment (Windows) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet provides instructions for Windows users to set up a virtual environment, activate it, and install py4web via pip. It also includes commands for initial setup, password configuration, and running the py4web application. ```Shell run cmd.exe In e.g. folder c:\py4web python3 -m venv venv "C:\py4web\venv\Scripts\activate.bat" python -m pip install --upgrade py4web --no-cache-dir cd venv\scripts py4web.exe setup apps py4web.exe set_password py4web.exe run apps ``` -------------------------------- ### Running py4web Locally on Linux and MacOS Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst These commands initialize the 'apps' folder, set the administrative password for the py4web dashboard, and then start the py4web server. The './' prefix explicitly forces the execution of the local py4web installation, which is important if a global installation also exists. ```Bash ./py4web.py setup apps ./py4web.py set_password ./py4web.py run apps ``` -------------------------------- ### Installing and Setting Up py4web Source: https://github.com/web2py/py4web/blob/master/apps/_default/static/index.html This snippet provides the command-line steps to install py4web using pip, set up a new application, configure the admin password, and start the py4web server. It emphasizes the use of a virtual environment for installation. ```Shell $ pip install py4web # install it (but use a venv or Nix) $ py4web setup apps # answer yes to all questions $ py4web set_password # pick a password for the admin $ cp -r apps/_scaffold apps/myapp # make a new app $ py4web run apps # start py4web ``` -------------------------------- ### Setting Up py4web for Google Cloud App Engine Deployment (Bash) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html These commands outline the initial setup steps for deploying a py4web application to Google App Engine. It includes creating a working directory, copying necessary deployment files, installing the Google SDK, and configuring `gcloud` with user credentials and project ID. ```Bash mkdir gae cd gae ``` ```Bash cp /path/to/py4web/development_tools/gcloud/* ./ ``` ```Bash make install-gcloud-linux make setup gcloud config set {your email} gcloud config set {project id} ``` -------------------------------- ### Calling a Function with py4web call Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This example demonstrates how to use the `py4web call` command to execute `myfunction` located in `apps/examples/test.py`, passing a dictionary of arguments. Note the required single and double quotes for the parameters to work correctly. ```Bash # py4web call apps examples.test.myfunction --args '{"x": 100}' ``` -------------------------------- ### Displaying Help for py4web run Command Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command shows the extensive options available for `py4web run`, which starts the py4web server and runs applications within a specified folder. It includes options for host, port, server type, logging, and automatic app reloading. ```Bash # py4web run -h Usage: py4web.py run [OPTIONS] APPS_FOLDER Run the applications on apps_folder Options: -Y, --yes No prompt, assume yes to questions -H, --host TEXT Host listening IP [default: 127.0.0.1] -P, --port INTEGER Port number [default: 8000] -A, --app_names TEXT List of apps to run, comma separated (all if omitted or empty) -p, --password_file TEXT File for the encrypted password [default: password.txt] -Q, --quiet Suppress server output -R, --routes Write apps routes to file -s, --server [default|wsgiref|tornado|wsgiref+threaded|rocket|waitress|gunicorn|gevent|gunicorn+gevent|gevent+websockets] Web server to use (unavailable: waitress, gunicorn, gevent, gunicorn+gevent, gevent+websockets) -w, --number_workers INTEGER Number of workers [default: 0] -d, --dashboard_mode TEXT Dashboard mode: demo, readonly, full, none [default: full] --watch [off|sync|lazy] Watch python changes and reload apps automatically, modes: off, sync, lazy [default: lazy] --ssl_cert PATH SSL certificate file for HTTPS --ssl_key PATH SSL key file for HTTPS --errorlog TEXT Where to send error logs (:stdout|:stderr|tickets_only|{filename}) [default: :stderr] -L, --logging_level INTEGER The log level (0 - 50) [default: 30 (=WARNING)] -D, --debug Debug switch -U, --url_prefix TEXT Prefix to add to all URLs in and out -m, --mode TEXT default or development [default: default] -help, -h, --help Show this message and exit. ``` -------------------------------- ### Setting Up and Running PY4WEB after pip Installation Source: https://github.com/web2py/py4web/blob/master/README.rst These commands are executed after a pip installation to set up and run PY4WEB. `py4web setup apps` prepares the application environment, `py4web set_password` configures the dashboard password, and `py4web run apps` starts the server, serving applications from the specified 'apps' folder. ```bash py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Running py4web with uv Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command executes py4web using `uv`, a modern Python package manager. It starts the py4web server and manages its dependencies, offering an alternative and potentially faster way to run Python applications. ```Bash uv run py4web.py run apps ``` -------------------------------- ### Running py4web with uv Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command executes py4web using the `uv` package manager. It assumes `uv` is already installed and configured. The command starts the py4web server, serving applications from the 'apps' folder, leveraging `uv` for dependency management and execution. ```Shell uv run py4web.py run apps ``` -------------------------------- ### Installing Py4web with Pip in a Virtual Environment (Linux/MacOS) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet outlines the steps to create and activate a Python virtual environment, then install py4web using pip within that environment on Linux or macOS. It also includes commands to set up applications, set an admin password, and start the py4web server. ```Shell python3 -m venv venv . venv/bin/activate python -m pip install --upgrade py4web --no-cache-dir python py4web setup apps python py4web set_password python py4web run apps ``` -------------------------------- ### Running py4web Locally on Windows Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst These commands perform the same setup, password configuration, and server startup as on Linux/macOS, but explicitly use `python3` to execute the scripts. On Windows, local programs are prioritized, so the `./` prefix is not needed, and direct execution of `.py` files requires the `python3` command. ```Python python3 py4web.py setup apps python3 py4web.py set_password python3 py4web.py run apps ``` -------------------------------- ### Installing py4web via pip (User Scope) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command installs py4web and its dependencies for the current user only, without requiring administrative privileges or modifying the system-wide Python environment. It's a quick way to get the latest stable release. ```Shell python3 -m pip install --upgrade py4web --no-cache-dir --user ``` -------------------------------- ### Running Py4web After Global Pip Installation Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html These commands are executed after a global pip installation of py4web to set up default applications, configure the admin password, and start the py4web server. They assume py4web is in the system's PATH. ```Shell py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Copying py4web GCloud Example Files (CLI) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This command-line snippet copies example deployment files for Google Cloud from the py4web development tools directory to the current working directory. These files include `Makefile`, `app.yaml`, and `main.py`, which are essential for GAE deployment. ```Shell cp /path/to/py4web/development_tools/gcloud/* ./ ``` -------------------------------- ### Running PY4WEB after Binary Installation (Linux/MacOS) Source: https://github.com/web2py/py4web/blob/master/README.rst These commands are used to initialize and run PY4WEB after a binary installation on Linux or MacOS. The first command sets the dashboard password, and the second starts the PY4WEB server, serving applications from the 'apps' folder. For Windows, omit the './' prefix. ```bash ./py4web set_password ./py4web run apps ``` -------------------------------- ### Running py4web Commands on Windows (Explicit Path) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst For Windows users, if the 'py4web' command is not directly accessible in the system's PATH (e.g., after a '--user' pip install), these commands explicitly call the 'py4web.py' script using the Python interpreter to perform setup, password configuration, and server startup. ```Batch python3 py4web.py setup apps python3 py4web.py set_password python3 py4web.py run apps ``` -------------------------------- ### Listing py4web Command Line Options Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command displays all available command-line options for py4web. It's the default behavior when py4web is executed without any arguments. ```Bash # py4web ``` -------------------------------- ### Hello World Example - web2py Python Source: https://github.com/web2py/py4web/blob/master/docs/chapter-15.rst Demonstrates a basic 'Hello World' response in web2py by defining an 'index' function within 'controllers/default.py' that simply returns a string. ```Python # in controllers/default.py def index(): return "hello world" ``` -------------------------------- ### Installing Py4web Globally with Pip Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command installs py4web and its dependencies globally on the system using pip, without creating a virtual environment. The --user flag installs it to the user's site-packages directory. ```Shell python3 -m pip install --upgrade py4web --no-cache-dir --user ``` -------------------------------- ### Deploying py4web to Google App Engine Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This simple `make` command initiates the deployment of the py4web application to Google App Engine. It leverages the `Makefile` in the GAE deployment folder to package and upload the application. ```Shell make deploy ``` -------------------------------- ### Displaying Help for py4web call Command Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command shows the usage and available options for the `py4web call` command, which is used to execute a specific function within an application folder. ```Bash # py4web call -h Usage: py4web.py call [OPTIONS] APPS_FOLDER FUNC Call a function inside apps_folder Options: -Y, --yes No prompt, assume yes to questions [default: False] --args TEXT Arguments passed to the program/function [default: {}] -help, -h, --help Show this message and exit. ``` -------------------------------- ### Deploying py4web as a WSGI Application with Gunicorn (Python) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet demonstrates how to configure and run py4web as a standard WSGI application using Gunicorn. It involves creating a Python file to initialize the WSGI application and then using the `gunicorn` command-line interface to start it, specifying the number of worker processes. ```Python # py4web_wsgi.py from py4web.core import wsgi application = wsgi(apps_folder="apps") ``` ```Bash gunicorn -w 4 py4web_wsgi:application ``` -------------------------------- ### Preparing Py4web for Local Source Execution Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet describes how to clone the py4web repository and install it in "editable" mode using pip. This allows running py4web directly from the source directory, which is useful for development or testing different versions without a full global installation. ```Shell git clone https://github.com/web2py/py4web.git cd py4web python3 -m pip install --upgrade -e . ``` -------------------------------- ### Running py4web on a Specific Host Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command demonstrates how to configure py4web to listen on all available network interfaces (`0.0.0.0`) instead of just localhost, making it accessible from other machines on the network. ```Bash py4web run --host 0.0.0.0 apps ``` -------------------------------- ### Running py4web After Global Pip Installation Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html After a global pip installation, these commands are used to set up applications, configure the administrator password, and start the py4web server. These commands assume py4web is in the system's PATH. ```Shell py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Initializing GCloud Deployment Directory Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst These shell commands create a new directory named `gae` and then navigate into it. This prepares a dedicated working folder for deploying py4web applications to Google App Engine. ```Shell mkdir gae cd gae ``` -------------------------------- ### Displaying Py4web Version Help (Shell) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This snippet displays the help output for the `py4web version` command, detailing its usage and options. It explains how to show the py4web framework version, with an additional option (`-a` or `--all`) to list versions of all available Python modules. ```Shell # py4web version -h Usage: py4web.py version [OPTIONS] Show versions and exit Options: -a, --all List version of all modules -h, -help, --help Show this message and exit. ``` -------------------------------- ### Listing py4web Command Line Options Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html Running `py4web` without any arguments displays a list of available command-line options and their basic usage. This is useful for discovering the various functionalities and subcommands provided by the py4web CLI. ```Shell # py4web ``` -------------------------------- ### Running Py4web Locally from Source (Linux/MacOS) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html These commands are used to run py4web directly from its source directory on Linux or macOS after it has been installed in editable mode. The ./ prefix ensures the local py4web.py script is executed instead of a globally installed version. ```Shell ./py4web.py setup apps ./py4web.py set_password ./py4web.py run apps ``` -------------------------------- ### VSCode Debug Configuration for py4web (Source Install) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-02.html This JSON snippet shows the `launch.json` configuration for debugging py4web when it has been installed from source. It specifies the program path and arguments to run the 'apps' folder. Users must replace 'your_full_path_to_py4web.py' with their actual path, using forward slashes on Windows. ```JSON "args": ["run", "apps"], "program": "your_full_path_to_py4web.py", ``` -------------------------------- ### Starting py4web with PostgreSQL via Makefile Source: https://github.com/web2py/py4web/blob/master/deployment_tools/docker/README.md This command utilizes the 'make' utility to bring up the py4web and PostgreSQL containers as defined in the Makefile, providing an automated setup for multi-service environments on Linux/Mac. ```Shell $ make up ``` -------------------------------- ### Installing Google SDK and Configuring py4web for GAE (Makefile/CLI) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This sequence of commands installs the Google SDK, sets up the py4web working folder using a Makefile, and configures the `gcloud` CLI with the user's email and project ID. These steps are crucial prerequisites for deploying applications to Google App Engine. ```Shell make install-gcloud-linux make setup gcloud config set {your email} gcloud config set {project id} ``` -------------------------------- ### Displaying Help for py4web new_app Command Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command provides usage details and options for `py4web new_app`, which is used to create a new application by copying a scaffolding template. It includes options for suppressing prompts and specifying a custom scaffold zip file. ```Bash # py4web new_app -h Usage: py4web.py new_app [OPTIONS] APPS_FOLDER APP_NAME Create a new app copying the scaffolding one Options: -Y, --yes No prompt, assume yes to questions [default: False] -s, --scaffold_zip TEXT Path to the zip with the scaffolding app -help, -h, --help Show this message and exit. ``` -------------------------------- ### Installing py4web with Virtual Environment on Windows Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This snippet outlines the steps for Windows users to set up a virtual environment, activate it, install py4web via pip, and then configure and run py4web applications. It includes specific paths for Windows batch activation and py4web.exe commands. ```Shell run cmd.exe In e.g. folder c:\\py4web python3 -m venv venv "C:\\py4web\\venv\\Scripts\\activate.bat" python -m pip install --upgrade py4web --no-cache-dir cd venv\\scripts py4web.exe setup apps py4web.exe set_password py4web.exe run apps ``` -------------------------------- ### Running py4web with Custom Password File Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command starts the py4web application, instructing it to use the specified `my_password_file.txt` for dashboard authentication. This ensures that the py4web instance uses a pre-configured password file instead of prompting for a password or using the default. ```Shell py4web run -p my_password_file.txt apps ``` -------------------------------- ### Installing py4web Globally via Pip Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This command installs py4web and its dependencies directly into the system's Python environment using pip. It's a quick way to get the latest stable release, but it modifies the global Python installation. The --user option can be used to install into the user's home directory. ```Shell python3 -m pip install --upgrade py4web --no-cache-dir --user ``` -------------------------------- ### Setting URL Prefix and Port for py4web (Shell) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This example illustrates how to use the `url_prefix` and `port` options to run py4web applications with a specific URL prefix and on a designated port. This is useful for routing multiple py4web instances or integrating with reverse proxies. ```Shell py4web run --url_prefix=/abracadabra --port 8000 apps ``` -------------------------------- ### VS Code Debug Configuration for py4web Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This JSON snippet configures VS Code's `launch.json` for debugging a py4web application using `debugpy`. It specifies the module to run (`py4web`) and includes command-line arguments for running apps, enabling SSL with specified certificate and key paths, and selecting the `rocketServer`. ```JSON { "name": "py4web", "type": "debugpy", "request": "launch", "module": "py4web", "args": [ "run", "apps", "--ssl_cert", "/path_to/localhost.crt", "--ssl_key", "/path_to/localhost.key", "--server", "rocketServer" ] } ``` -------------------------------- ### Configuring py4web as a WSGI Application (Python) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This snippet demonstrates how to configure py4web as a standard WSGI application using a Python file. It initializes the py4web WSGI application by specifying the 'apps' folder. This setup is useful when a full program installation is not feasible, allowing py4web to run as a standalone WSGI app. ```Python # py4web_wsgi.py from py4web.core import wsgi application = wsgi(apps_folder="apps") ``` -------------------------------- ### VSCode Py4web Launch Configuration (JSON) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This JSON snippet shows the beginning of a VSCode `launch.json` configuration for py4web. It indicates where to define specific launch configurations for debugging or running py4web applications within the VSCode environment, particularly relevant for setting up HTTPS. ```JSON "configurations": [ ``` -------------------------------- ### Upgrading py4web using Pip Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command upgrades an existing pip installation of py4web to its latest version. It's important to note that this command does not automatically upgrade standard applications like Dashboard and Default, which require manual reinstallation after removal. ```Bash python3 -m pip install --upgrade py4web ``` -------------------------------- ### Running Py4web via Python Script (Windows Global Install) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet provides an alternative way to run py4web commands on Windows if the py4web executable is not directly in the system's PATH, typically when the --user option was used during installation. It explicitly calls the py4web.py script with python3. ```Shell python3 py4web.py setup apps python3 py4web.py set_password python3 py4web.py run apps ``` -------------------------------- ### Displaying py4web Version Command Help Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command displays the help message for the `py4web version` utility, detailing its usage and the `--all` option. It shows how to check the version of py4web and optionally all available Python modules, useful for debugging and environment verification. ```Shell py4web version -h ``` -------------------------------- ### Deploying py4web to Google Cloud App Engine (Bash) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command initiates the deployment of the py4web application to Google App Engine. It assumes that the `Makefile` and `app.yaml` are correctly configured in the working directory, allowing for a simplified deployment process. ```Bash make deploy ``` -------------------------------- ### Routing by HTTP Method Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-15.html This example shows how to handle different HTTP methods (GET, POST) for the same URL. py4web simplifies this by allowing method specification directly in the action decorator, eliminating explicit `if request.method` checks. ```Python def index(): if request.method == "GET": return "GET" if request.method == "POST": return "POST" raise HTTP(400) ``` ```Python @action("index", method="GET") def index(): return "GET" @action("index", method="POST") def index(): return "POST" ``` -------------------------------- ### Creating a py4web WSGI Application File Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This Python code defines a standard WSGI application for py4web. It imports the `wsgi` function from `py4web.core` and initializes the `application` object, pointing it to the `apps` folder where py4web applications reside. ```Python # py4web_wsgi.py from py4web.core import wsgi application = wsgi(apps_folder="apps") ``` -------------------------------- ### Hello World Example - py4web Python Source: https://github.com/web2py/py4web/blob/master/docs/chapter-15.rst Shows the 'Hello World' implementation in py4web, utilizing the '@action('index')' decorator to route the 'index' function, which returns a string. This code is typically imported by '__init__.py'. ```Python # file imported by __init__.py @action('index') def index(): return "hello world" ``` -------------------------------- ### Installing py4web from Source Globally (Linux/MacOS) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This snippet details the process of cloning the py4web repository, building assets, running tests, and installing py4web globally from source. This method is typically used on Linux and MacOS and installs all requirements and links to the system's path. ```Shell git clone https://github.com/web2py/py4web.git cd py4web make assets make test python -m pip install . py4web setup apps py4web set_password py4web run apps ``` -------------------------------- ### Displaying Py4web Shell Help (Shell) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This snippet shows the help output for the `py4web shell` command, detailing its usage and options. It describes how to open a Python shell with the application's parent directory added to the Python path, facilitating direct interaction with py4web modules. ```Shell # py4web shell -h Usage: py4web.py shell [OPTIONS] APPS_FOLDER Open a python shell with apps_folder's parent added to the path Options: -Y, --yes No prompt, assume yes to questions [default: False] -h, -help, --help Show this message and exit. ``` -------------------------------- ### VSCode Debug Configuration for py4web (Pip Install) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-02.html This `launch.json` configuration is used for debugging py4web when it has been installed via pip. It sets up the debugger to run py4web as a module, passing arguments like 'run', 'apps', '-D', and '--watch lazy' for development and auto-reloading. The 'args' array should be adjusted to match the specific apps folder. ```JSON { "name": "py4web apps", "type": "debugpy", "request": "launch", "module": "py4web", "args": ["run", "apps", "-D", "--watch", "lazy"] } ``` -------------------------------- ### Setting Up py4web from Source Without Global Install Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This command sequence clones the py4web repository and installs its dependencies in editable mode, allowing py4web to be run directly from the source directory without a global installation. This is useful for development or testing specific branches. ```Shell git clone https://github.com/web2py/py4web.git cd py4web python3 -m pip install --upgrade -e . ``` -------------------------------- ### Running py4web Applications (run) - Shell Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet displays the help output for the `py4web run` command, which is used to start py4web applications within a specified `APPS_FOLDER`. It details numerous options for configuring the server, including host, port, specific app selection (`--app_names`), password file, quiet mode, route writing, web server choice (`--server`), number of workers, dashboard mode, automatic reloading (`--watch`), SSL settings, error logging, logging level, debug mode, URL prefix, and application mode. It highlights important security defaults like listening only on `127.0.0.1` and the `--watch` directive's behavior. ```Shell py4web run -h Usage: py4web.py run [OPTIONS] APPS_FOLDER Run the applications on apps_folder Options: -Y, --yes No prompt, assume yes to questions -H, --host TEXT Host listening IP [default: 127.0.0.1] -P, --port INTEGER Port number [default: 8000] -A, --app_names TEXT List of apps to run, comma separated (all if omitted or empty) -p, --password_file TEXT File for the encrypted password [default: password.txt] -Q, --quiet Suppress server output -R, --routes Write apps routes to file -s, --server [default|wsgiref|tornado|wsgiref+threaded|rocket|waitress|gunicorn|gevent|gunicorn+gevent|gevent+websockets] Web server to use (unavailable: waitress, gunicorn, gevent, gunicorn+gevent, gevent+websockets) -w, --number_workers INTEGER Number of workers [default: 0] -d, --dashboard_mode TEXT Dashboard mode: demo, readonly, full, none [default: full] --watch [off|sync|lazy] Watch python changes and reload apps automatically, modes: off, sync, lazy [default: lazy] --ssl_cert PATH SSL certificate file for HTTPS --ssl_key PATH SSL key file for HTTPS --errorlog TEXT Where to send error logs (:stdout|:stderr|tickets_only|{filename}) [default: :stderr] -L, --logging_level INTEGER The log level (0 - 50) [default: 30 (=WARNING)] -D, --debug Debug switch -U, --url_prefix TEXT Prefix to add to all URLs in and out -m, --mode TEXT default or development [default: default] -help, -h, --help Show this message and exit. ``` -------------------------------- ### Running py4web with Synchronous File Watching Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command configures py4web to immediately reload applications upon detecting changes in Python files, providing synchronous updates during development. This is achieved by setting the `--watch` option to `sync`. ```Bash py4web run --watch sync ``` -------------------------------- ### Running py4web WSGI with Gunicorn Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This shell command demonstrates how to launch the py4web WSGI application using `gunicorn`. It configures 4 worker processes (`-w 4`) and specifies the `py4web_wsgi` module and its `application` object as the entry point. ```Shell gunicorn -w 4 py4web_wsgi:application ``` -------------------------------- ### Copying py4web GCloud Deployment Tools Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command copies all files from the py4web source's `development_tools/gcloud` directory into the current working folder. These files are essential templates and scripts for setting up py4web deployment on Google App Engine. ```Shell cp /path/to/py4web/development_tools/gcloud/* ./ ``` -------------------------------- ### Running py4web with URL Prefix and Custom Port Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This command illustrates how to run py4web with a custom URL prefix (`/abracadabra`) and a specific port (`8000`), useful for routing multiple py4web instances or integrating with reverse proxies. ```Bash py4web run --url_prefix=/abracadabra --port 8000 apps ``` -------------------------------- ### VSCode Debugging Configuration for py4web (Source Install) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-02.html This JSON configuration fragment is added to the VSCode `launch.json` file to enable debugging for py4web when installed from source. It specifies the arguments to run the 'apps' folder and the full path to the `py4web.py` script. For Windows paths, forward slashes must be used. If gevent errors occur, add `"gevent": true` to the configuration. ```JSON "args": ["run", "apps"], "program": "your_full_path_to_py4web.py", ``` -------------------------------- ### Calling a Function with py4web call Command (Shell) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This example demonstrates how to use the `py4web call` command to execute a specific function, `myfunction`, located within `apps/examples/test.py`. It illustrates passing arguments to the function using the `--args` option, requiring specific single and double quote usage for JSON parameters. This is useful for testing or running specific application logic from the command line. ```Shell # py4web call apps examples.test.myfunction --args '{"x": 100}' ``` -------------------------------- ### VSCode Debugging Configuration for py4web (Pip Install) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-02.html This `launch.json` configuration sets up VSCode debugging for py4web when installed via pip. It runs py4web as a module with arguments to execute the 'apps' folder, enable debug mode (`-D`), and lazy watching. The `args` array should be adjusted to match the actual apps folder location. If gevent errors occur, add `"gevent": true` to the configuration. ```JSON { "name": "py4web apps", "type": "debugpy", "request": "launch", "module": "py4web", "args": ["run", "apps", "-D", "--watch", "lazy"] } ``` -------------------------------- ### Reinstalling Standard py4web Applications Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst After upgrading py4web via pip, this command is used to re-install the standard applications (such as Dashboard and Default) into the specified apps folder. This step is a safety precaution, allowing users to preserve any changes made to these default applications. ```Bash py4web setup ``` -------------------------------- ### Displaying py4web Shell Command Help Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command displays the help message for the `py4web shell` utility, outlining its usage and options. It explains how to open a Python shell with the applications folder's parent added to the path, facilitating interactive development and debugging. ```Shell py4web shell -h ``` -------------------------------- ### Basic Authentication Setup and Usage in py4web Source: https://github.com/web2py/py4web/blob/master/docs/chapter-15.rst This py4web snippet initializes `Auth` (without immediate table definition), defines tables, and enables authentication with a route. The `index` action, protected by `auth.user`, demonstrates accessing `user_id` and fetching user details via `auth.get_user()`, accessible via `/auth/login`. ```python auth = Auth(define_table=False) auth.define_tables() auth.enable(route='auth') @action("index") @action.uses(auth.user) def index(): user_id = auth.user_id user_email = auth.get_user().get('email') return locals() ``` -------------------------------- ### Installing py4web with Virtual Environment on Linux/MacOS Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This snippet provides commands to create and activate a Python virtual environment, install py4web using pip, and then set up and run py4web applications on Linux and MacOS systems. It ensures a clean installation isolated from the system's Python environment. ```Shell python3 -m venv venv . venv/bin/activate python -m pip install --upgrade py4web --no-cache-dir python py4web setup apps python py4web set_password python py4web run apps ``` -------------------------------- ### Running py4web from Local Source on Linux/MacOS Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html After setting up py4web from source without a global install, these commands are used to configure and run the local instance on Linux and MacOS. The ./ prefix ensures the local py4web.py script is executed instead of any globally installed version. ```Shell ./py4web.py setup apps ./py4web.py set_password ./py4web.py run apps ``` -------------------------------- ### Creating New py4web Applications (new_app) - Shell Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet shows the help output for the `py4web new_app` command, which is used to create a new py4web application from a scaffolding template. It outlines the command's usage, required arguments like `APPS_FOLDER` and `APP_NAME`, and available options such as `--yes` for no prompts and `--scaffold_zip` for specifying a custom scaffolding archive. This command currently has known issues with binary and local source installations due to missing asset zip files. ```Shell py4web new_app -h Usage: py4web.py new_app [OPTIONS] APPS_FOLDER APP_NAME Create a new app copying the scaffolding one Options: -Y, --yes No prompt, assume yes to questions [default: False] -s, --scaffold_zip TEXT Path to the zip with the scaffolding app -help, -h, --help Show this message and exit. ``` -------------------------------- ### Running Py4web Locally from Source (Windows) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This snippet provides commands for running py4web directly from its source directory on Windows. It explicitly uses python3 to execute the py4web.py script, which is common practice on Windows for local script execution. ```Shell python3 py4web.py setup apps python3 py4web.py set_password python3 py4web.py run apps ``` -------------------------------- ### Installing PY4WEB via pip Source: https://github.com/web2py/py4web/blob/master/README.rst This command installs or upgrades PY4WEB and its dependencies using pip. It's the standard installation method for all operating systems, requiring Python 3.7+. The `--user` option should be omitted when using virtual environments or standard Windows installations. ```bash python3 -m pip install --upgrade py4web --no-cache-dir --user ``` -------------------------------- ### Example PY4WEB Run Command with Specific Options Source: https://github.com/web2py/py4web/blob/master/README.rst This example demonstrates how to run PY4WEB with specific command-line arguments. It configures the server to listen on `127.0.0.1` at port `8000` and sets the dashboard to `demo` mode, serving applications from the 'apps' folder. ```bash py4web run -H 127.0.0.1 -P 8000 -d demo apps ``` -------------------------------- ### Configuring py4web Host for External Access - Shell Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command demonstrates how to configure the `py4web run` command to listen on all available network interfaces (`0.0.0.0`) instead of the default `127.0.0.1` (localhost). This is necessary to make the py4web application accessible from other machines on the network. The `apps` argument specifies the folder containing the applications to run. ```Shell py4web run --host 0.0.0.0 apps ``` -------------------------------- ### Displaying Py4web Set Password Help (Shell) Source: https://github.com/web2py/py4web/blob/master/docs/chapter-03.rst This snippet shows the help output for the `py4web set_password` command, detailing its usage and available options. It explains how to set the administrator's dashboard password, either directly via `--password` or by specifying a password file with `-p` or `--password_file`. ```Shell # py4web set_password -h Usage: py4web.py set_password [OPTIONS] Set administrator's password for the Dashboard Options: --password TEXT Password value (asked if missing) -p, --password_file TEXT File for the encrypted password [default: password.txt] -h, -help, --help Show this message and exit. ``` -------------------------------- ### Configuring VSCode Debugger for py4web HTTPS Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This JSON configuration snippet for VSCode's `launch.json` sets up a debug profile for py4web to run with HTTPS. It specifies the `debugpy` type, launches `py4web` as a module, and passes arguments to enable SSL with provided certificate and key paths, using the `rocketServer`. ```JSON "configurations": [ { "name": "py4web", "type": "debugpy", "request": "launch", "module": "py4web", // or "program": "${workspaceFolder}/py4web.py", if you didn't install py4web as a package "args": [ "run", "apps", "--ssl_cert", "/path_to/localhost.crt", "--ssl_key", "/path_to/localhost.key", "--server", "rocketServer" ] } ] ``` -------------------------------- ### Running py4web WSGI Application with Gunicorn (CLI) Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/pt/chapter-03.html This command-line snippet shows how to start the py4web WSGI application using `gunicorn-cli`. It specifies 4 worker processes (`-w 4`) and points to the `application` object within the `py4web_wsgi.py` file. This is the command used to launch the WSGI application configured in the previous Python snippet. ```Shell gunicorn -w 4 py4web_wsgi:application ``` -------------------------------- ### Displaying py4web set_password Command Help Source: https://github.com/web2py/py4web/blob/master/apps/_documentation/static/en/chapter-03.html This command displays the help message for the `py4web set_password` utility, outlining its usage, available options like `--password` and `--password_file`, and their default values. It helps users understand how to manage the dashboard administrator password. ```Shell py4web set_password -h ```