sextile.cli

The pieces both command lines are built from.

Sextile has a command of its own, which can serve or draw any application, and an application generally needs one too – if only to say where its data lives. Neither should have to reimplement the other, so what they share is here.

The command line is Click. A service builds its own click.Group and adds the render and serve commands standard_commands returns; the framework’s own command line is that same pair over a module:name.

sextile.cli.CONTEXT_SETTINGS: Final = {'help_option_names': ['-h', '--help']}

-h as well as –help, the way argparse offered both, on every command.

exception sextile.cli.ApplicationSpecError[source]

Bases: ValueError

A module:name that does not name an application.

sextile.cli.form_options(command)[source]

Add –frame, –form and –no-colour to a Click command.

Parameters:

command (Any) – The command to add them to.

Return type:

Any

Returns:

The command, so it composes as a decorator.

sextile.cli.listening_options(command)[source]

Add –host, –port, –idle-timeout, –warn-after and –max-connections.

Parameters:

command (Any) – The command to add them to.

Return type:

Any

Returns:

The command, so it composes as a decorator.

sextile.cli.load_application(spec)[source]

Load the application a module:name specification names.

Parameters:

spec (str) – A module:name, the same shape a WSGI or ASGI server takes: what is served is chosen when the server starts, not when it is written.

Return type:

Sextile

Returns:

The application. A callable is called, so a factory works as well as an instance.

Raises:

ApplicationSpecError – If the spec is malformed, the module will not import, the name is absent, or the value is not a Sextile.

async sextile.cli.render_page(application, *, page, frame=0, form='ansi', colour=True)[source]

Render one frame of one page to standard output, its keys to standard error.

Parameters:
  • application (Sextile) – The service to fetch the page from.

  • page (str) – The page number to draw.

  • frame (int) – Which frame of a page that runs to several, the first by default.

  • form (str) – One of FORMS.

  • colour (bool) – Whether the ansi form carries colour.

Returns:

0 drawn, 2 where the page, frame or number is not there.

Return type:

int

async sextile.cli.run_service(application, *, host='127.0.0.1', port=16650, idle_timeout=900.0, warn_after=None, max_connections=64)[source]

Serve the application until interrupted.

Parameters:
  • application (Sextile) – The service to serve.

  • host (str) – The address to listen on.

  • port (int) – The port to listen on.

  • idle_timeout (float) – Seconds a caller may be silent before the line is released; 0 holds it indefinitely.

  • warn_after (float | None) – Seconds before the draining warning appears, or None for half the idle timeout.

  • max_connections (int) – How many callers may be on the line at once; 0 for no ceiling.

Return type:

int

Returns:

A process exit code, 0 once interrupted.

sextile.cli.standard_commands(load, *, options=(), page_example='1')[source]

The render and serve commands every service’s command line shares.

A service adds these to its own click.Group, and its own commands beside them – Stardot its ingest, the weather its import-places. Click routes to each, so there is nothing to dispatch by hand.

Parameters:
  • load (Callable[[Context], Sextile]) – Builds the application from a command’s click.Context, whose params hold the values the options collected. Called only for a command that needs it, and for render only once –page is present, so an unfindable data path fails no earlier than the command reading it.

  • options (Sequence[Callable[[Any], Any]]) – Click option decorators added to both commands, for the arguments a service needs to find its data, such as a database path. The same decorators run against both, so render and serve agree about where the data lives without the service saying it twice.

  • page_example (str) – A page number to show in render –page’s help, such as “1 or 82489493”.

Return type:

tuple[Command, Command]

Returns:

The render and serve commands, for group.add_command.

Example

>>> import click
>>> @click.group()
... def app() -> None: ...
>>> for command in standard_commands(lambda context: ...):
...     app.add_command(command)