Skip to content

launch

Main entry point for starting Drafter servers.

Provides the start_server() function which routes to either in-browser ClientServer or local development AppServer based on execution context.

CODE_AFTER_START_ERROR_ID = 'config.code_after_start_server' module-attribute

Stable id of the warning for statements written after start_server(...).

LEGACY_START_SERVER_OPTIONS = frozenset({'backend', 'cdn_drafter_setup', 'debug', 'save_uploaded_files', 'skulpt', 'src_image_folder', 'style', 'title'}) module-attribute

Options that start_server took in Drafter 1 and no longer uses.

They are ignored without a warning, so a program written for Drafter 1 still starts quietly.

MaybeBoolStr = bool | str | None module-attribute

Type alias for parameters that accept a bool, a string, or None.

START_SERVER_ONLY_OPTIONS = frozenset({'initial_state', 'server', 'reloader', 'argv'}) module-attribute

Parameters of start_server that are not settings of their own, offered alongside the settings when suggesting a correction for a misspelled option.

UNKNOWN_OPTION_ERROR_ID = 'config.unknown_start_server_option' module-attribute

Stable id of the warning for a start_server option Drafter does not have.

describe_unknown_option(name, setting_names)

Write the warning for one unknown start_server option.

Parameters:

Name Type Description Default
name str

The option as it was written.

required
setting_names frozenset[str]

Every setting name Drafter does have.

required

Returns:

Type Description
str

The warning, with a "Did you mean" suggestion when a real option has a similar name.

find_code_after_call(source, call_line)

Find the first statement written after a call at the top of a file.

Parameters:

Name Type Description Default
source str

The text of a Python file.

required
call_line int

The line of a call in that file (start_server(...)).

required

Returns:

Type Description
int | None

The line of the first top-level statement after the one holding the call, or None when the call is the last thing in the file. Also None when the call is not at the top level of the file (it is inside a function, say), since what runs after it then depends on who called that function.

find_unknown_options(options, setting_names)

Pick out the start_server options that Drafter does not have.

Parameters:

Name Type Description Default
options dict[str, Any]

The extra keyword arguments given to start_server.

required
setting_names frozenset[str]

Every setting name Drafter does have.

required

Returns:

Type Description
list[str]

The unknown names, in the order they were written. Options from Drafter 1 (LEGACY_START_SERVER_OPTIONS) are left out.

report_code_after_start(server, filename, call_line)

Warn when a program has statements after its start_server(...) call.

That code does run, but not when a reader of the file would expect: on the computer start_server does not return until the server stops, while in the browser it returns as soon as the first page is shown. A file that cannot be read or parsed (code typed at a prompt) is skipped.

Parameters:

Name Type Description Default
server ClientServer

The server being started, whose debug panel gets the warning in the browser.

required
filename str

The file that called start_server.

required
call_line int

The line of that call.

required

report_unknown_options(unknown, setting_names, server)

Warn about start_server options that were ignored.

On the computer the warning is printed in the terminal. In the browser it goes to the debug panel. Either way the site still starts.

Parameters:

Name Type Description Default
unknown list[str]

The unknown option names.

required
setting_names frozenset[str]

Every setting name Drafter does have.

required
server ClientServer

The server being started, whose debug panel gets the warning in the browser.

required

start_server(initial_state=None, server=None, server_name=None, in_debug_mode=None, framed=None, theme=None, site_title=None, favicon=None, information=None, verbose=None, asset_directory=None, show_filename_as=None, engine=None, port=None, host=None, prerender_initial_page=None, open_browser=None, browser=None, inline_py=None, use_reloader=None, pyodide_url=None, pyodide_version=None, pyodide_branch=None, reloader=None, cdn_skulpt=None, cdn_skulpt_std=None, cdn_skulpt_drafter=None, skip=None, argv=None, **extra_configuration)

Start the Drafter server (web or local development mode).

Routes to either ClientServer (web mode) or AppServer (local dev mode) based on execution context. In web mode, initializes browser-side bridge; in local mode, starts Starlette dev server with file watching.

This function is the primary entry point for users and accepts parameters for both ClientServer and AppServer modes (the appropriate ones are used depending on context).

Parameters:

Name Type Description Default
initial_state

Optional initial application state.

None
server

Optional pre-created server instance (defaults to main server).

None
server_name str | None

Server identifier name.

None
in_debug_mode bool | None

Enable debug panel and logging.

None
framed bool | None

Whether to frame the content.

None
theme str | None

Theme name (e.g., "default").

None
site_title str | None

Title displayed in UI.

None
favicon str | None

Browser tab icon: a URL or the path to an adjacent image file (svg, png, ico, ...).

None
information dict | None

Dict of site information (author, description, etc.).

None
verbose bool | None

Enable verbose logging.

None
asset_directory MaybeBoolStr

Assets directory (uses Drafter defaults if False).

None
show_filename_as MaybeBoolStr

Display filename in UI (if different from actual).

None
engine EngineType | None

Python engine ("skulpt" or "pyodide").

None
port int | None

Server port for dev mode.

None
host str | None

Server host for dev mode.

None
prerender_initial_page bool | None

Prerender initial page on startup.

None
open_browser bool | None

Auto-open browser in dev mode.

None
browser str | None

Which browser to open in dev mode: "chrome", "firefox", "safari", "edge", or "default" for the system default. When not given, Chrome is used if installed, then Firefox, then the system default.

None
inline_py bool | None

Inline code in HTML vs. load via HTTP.

None
use_reloader bool | None

Enable file watcher and auto-reload.

None
pyodide_url str | None

Base URL to load Pyodide from (default: jsDelivr CDN).

None
pyodide_version str | None

Pyodide version segment, e.g. "v314.0.5" or "dev".

None
pyodide_branch str | None

Pyodide distribution branch, "full" or "debug".

None
reloader bool | None

Deprecated alias for use_reloader, kept for compatibility with older versions; used only when use_reloader is not given.

None
cdn_skulpt str | None

Deprecated and ignored; passing a value prints a warning.

None
cdn_skulpt_std str | None

Deprecated and ignored; passing a value prints a warning.

None
cdn_skulpt_drafter str | None

Deprecated and ignored; passing a value prints a warning.

None
skip bool | None

If True, do nothing at all — do not start the server or compile anything. Useful for running unit tests against a site file. Also settable via the DRAFTER_SKIP environment variable, the --skip flag, or a config file.

None
argv list[str] | None

Command-line argument override passed into the system configuration.

None
**extra_configuration

Additional configuration parameters.

{}

Raises:

Type Description
SystemExit

In local development mode, when the server cannot start for a reason that has a student-facing explanation (the main file is missing, the port is in use). The explanation is printed instead of a traceback; with the verbose setting on, the original StudentFacingError propagates instead.

suggest_option(name, setting_names)

Find the real start_server option closest to a misspelled one.

Parameters:

Name Type Description Default
name str

The option as it was written.

required
setting_names frozenset[str]

Every setting name Drafter does have.

required

Returns:

Type Description
str | None

The most similar real option, or None when nothing is close.

warn_at_startup(server, error_id, message, *, title, friendly, steps, terminal_note='')

Report a problem with how a program starts its site, without stopping it.

On the computer the warning is printed in the terminal. In the browser it goes to the debug panel, where it stays listed from page to page.

Parameters:

Name Type Description Default
server ClientServer

The server being started, whose debug panel gets the warning in the browser.

required
error_id str

Stable, code-like id of the warning.

required
message str

The warning itself, in one or two sentences.

required
title str

Short title for the debug panel.

required
friendly str

Plain-language explanation for the debug panel.

required
steps tuple[str, ...]

What to try, for the debug panel.

required
terminal_note str

Extra sentence printed after the message in the terminal, where there is no room for the explanation.

''