run()

The recommended entry point for Nib applications. Creates an App instance, passes it to your main function for configuration, then starts the application event loop.

Signature

nib.run(
    main: Callable[[App], None],
    assets_dir: str | Path | None = None,
    identifier: str | None = None,
) -> None

Parameters

Parameter Type Default Description
main Callable[[App], None] none A function that receives an App instance and configures it by setting properties and calling app.build()
assets_dir str | Path | None None Path to the assets directory. When None, Nib auto-detects an assets/ folder relative to the script. Relative paths resolve from the main script directory
identifier str | None None Bundle identifier and UserDefaults domain. By default the one nib run and nib build give the script, else com.nib.<slug of the title>. The runtime takes it at launch, so it cannot be set inside main

Behavior

  1. If assets_dir is provided, calls App.set_assets_dir(assets_dir).
  2. Creates App(identifier=identifier) and connects it to the runtime, so services work inside main.
  3. Calls main(app) so you can configure the app.
  4. Calls app.run() to render and enter the event loop.
  5. Cleans up when the app exits.

Examples

Basic usage

import nib

def main(app: nib.App):
    app.title = "Hello"
    app.icon = nib.SFSymbol("hand.wave")
    app.width = 300
    app.height = 200

    app.build(
        nib.Text("Hello, World!", font=nib.Font.TITLE, padding=20)
    )

nib.run(main)

With custom assets directory

import nib

def main(app: nib.App):
    app.title = "Gallery"
    app.icon = nib.SFSymbol("photo")
    app.width = 400
    app.height = 300

    # "logo.png" resolves to "my_assets/logo.png"
    app.build(
        nib.Image(src="logo.png", width=200, height=200)
    )

nib.run(main, assets_dir="my_assets")