betty.serve module

Provide the Serve API to serve resources within the application.

final class betty.serve.BuiltinProjectServer[source]

Bases: ProjectServer

A built-in server for a Betty project.

__init__(localizer: Localizer, project: Project) None[source]
property public_url: str

The server’s public URL.

async start() None[source]

Start the server.

async stop() None[source]

Stop the server.

final class betty.serve.BuiltinServer[source]

Bases: Server

A built-in server for a WWW directory.

__init__(www_directory_path: Path, *, root_path: str | None = None, localizer: Localizer) None[source]
property public_url: str

The server’s public URL.

async start() None[source]

Start the server.

async stop() None[source]

Stop the server.

exception betty.serve.NoPublicUrlBecauseServerNotStartedError[source]

Bases: ServerNotStartedError

A public URL is not yet available because the server has not (fully) started yet.

__init__()[source]
exception betty.serve.OsError[source]

Bases: UserFacingError, OSError

Raised for I/O errors.

class betty.serve.ProjectServer[source]

Bases: ProjectDependentFactory, Server

A web server for a Betty project.

__init__(localizer: Localizer, project: Project) None[source]
async classmethod new_for_project(project: Project) Self[source]

Create a new instance using the given project.

class betty.serve.Server[source]

Bases: ABC

Provide a (development) web server.

__init__(localizer: Localizer)[source]
async assert_available() None[source]

Assert that this server is available.

abstract property public_url: str

The server’s public URL.

async show() None[source]

Show the served site to the user.

abstractmethod async start() None[source]

Start the server.

abstractmethod async stop() None[source]

Stop the server.

exception betty.serve.ServerNotStartedError[source]

Bases: RuntimeError

Raised when a web server has not (fully) started yet.