Skip to content

Nitro CLI

The best way to get better at programming is to clone other apps and tinker with them. Read the source, Luke!

The nitro CLI (command line interface) makes it really easy to play with any Nitro app published anywhere on the world wide web.

Tip

You don't need the nitro CLI to develop or deploy Nitro apps. It's simply a tool to easily clone, set up and run examples and apps shared on the internet.

Caution

Using nitro run to execute code is no different than using python to execute code. Do not use nitro run to execute someone else's code without reading it first! Make sure you trust the authors.

Install

  1. Go to https://github.com/h2oai/nitro/releases.
  2. Download the appropriate archive for your platform.
  3. Extract the archive and move nitro or nitro.exe to a location that's in your PATH. Learn how.

Test your installation

To verify if nitro is accessible, open a new terminal window and run nitro version.

Run an app

# Create and switch to a new directory
mkdir my_app
cd my_app

# Run the "Hello World" app
nitro run https://raw.githubusercontent.com/h2oai/nitro/main/py/demo/hello.py
:: Create and switch to a new directory
mkdir my_app
cd my_app

:: Run the "Hello World" app
nitro run https://raw.githubusercontent.com/h2oai/nitro/main/py/demo/hello.py

The nitro run command does several things for you:

  • Creates a new virtual environment.
  • Ensures that a current version of pip is available.
  • Installs all the libraries that hello.py needs.
  • Launches the app.
Downloading https://raw.githubusercontent.com/h2oai/nitro/main/py/demo/hello.py
Downloaded hello.py: 1.5 kB
Creating virtual environment using "/usr/bin/python3" ...
Running /usr/bin/python3 [-m venv venv] ...
Found "venv/bin/python" in virtual environment.
Bootstrapping pip ...
Running venv/bin/python [-m ensurepip --upgrade] ...
Running venv/bin/python [-m pip install -r requirements.txt] ...
Starting venv/bin/python [-m flask run] ...
 * Serving Flask app 'hello.py' (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 140-120-041

Play with the app

Go to http://localhost:5000/.

Edit the app

To see what nitro run just did, let's inspect the directory's contents. You should see:

Open the directory in a Python editor, like PyCharm or Visual Studio Code. Then, make some change to hello.py and save. You should see your browser reload and display your changes automatically!

Tip

nitro run can run any Nitro app hosted anywhere on the world wide web, including gists and snippets, which makes sharing your apps just as easy as running them.

It's just Python!

If you inspect hello.py, you'll see that it's a plain Python file containing a simple Flask app and a Nitrogen header:

# Flask imports go here.

from h2o_nitro import View, box, web_directory


def main(view: View):
    name = view(box('What is your name?', value='Boaty McBoatface'))
    feel = view(box(f'How do you feel today, {name}?', value='intrigued'))
    view(f'What a coincidence, {name}, I feel {feel}, too!')


nitro = View(main, title='Hello Nitro!', caption='v1.0')

# Flask initialization goes here.

You can run hello.py using nitro run like this:

nitro -source . run hello.py

Or, if you prefer to use Python directly:

source venv/bin/activate
python hello.py
.\env\Scripts\activate
python hello.py

There's no magic here. Nitro apps are just plain Python programs.

How does it work?

The nitro run command looks for and executes Nitrogen instructions in the source file's comments.

Nitrogen is a mini-language that describes libraries to install, files to fetch, and commands to run in order to set up and launch the app.

Read the Nitrogen specifications to learn more.

Upgrading

Upgrades are easy: simply download a new release and replace your old copy of nitro.