Models

The hostedpi module uses Pydantic models to validate and serialize data structures. The models provided give a simple way to specify the requirements for a Raspberry Pi server, including the specifications of the Raspberry Pi, and sources the SSH keys to be added to the server.

Models are provided at the root of the module and can be imported as follows:

from hostedpi import Pi3ServerSpec, Pi4ServerSpec, SSHKeySources, PiInfo, PiInfoBasic, Settings

They can be constructed using keyword arguments:

pi4_spec = Pi4ServerSpec(
    memory_gb=8,
    cpu_speed=2000,
    disk=30,
    os_image="rpi-bookworm-arm64",
)

Alternatively, they can be constructed from a dictionary using model_validate (or similar):

mypi = {
    "memory_gb": 8,
    "cpu_speed": 2000,
    "disk": 30,
    "os_image": "rpi-bookworm-arm64",
}

pi4_spec = Pi4ServerSpec.model_validate(mypi)

Default values are provided for most fields, so these can be omitted.

When using the models, you can access the attributes directly using dot notation:

print(pi.info.boot_progress)

Raspberry Pi specifications

class hostedpi.models.specs.Pi3ServerSpec[source]

Specification model for the Raspberry Pi 3

Parameters:
  • disk (int) – Disk size in GB. Must be a multiple of 10, defaults to 10.

  • os_image (str | None) – Operating system image to use. Defaults to None, which uses Mythic’s default image.

Raises:

pydantic_core.ValidationError – If the server specification is invalid

field memory_gb: Literal[3] = 1

Memory in GB. Pi 3 only supports 1GB.

field cpu_speed: Literal[1200] = 1200

CPU speed in MHz. Pi 3 only supports 1200MHz.

field disk: int = 10

Disk size in GB

field os_image: str | None = None

Operating system image

class hostedpi.models.specs.Pi4ServerSpec[source]

Specification model for the Raspberry Pi 4

Parameters:
  • disk (int) – Disk size in GB. Must be a multiple of 10, defaults to 10.

  • memory_gb (int) – Memory in GB. Can be 4 or 8, defaults to 4.

  • cpu_speed (int) – CPU speed in MHz. Can be 1500 or 2000, defaults to 1500.

  • os_image (str | None) – Operating system image to use. Defaults to None, which uses Mythic’s default image.

Raises:

pydantic_core.ValidationError – If the server specification is invalid

field memory_gb: Literal[4, 8] = 4

Memory in GB. Pi 4 supports 4GB or 8GB

field cpu_speed: Literal[1500, 2000] = 1500

CPU speed in MHz. Pi 4 supports 1500MHz or 2000MHz.

field disk: int = 10

Disk size in GB

field os_image: str | None = None

Operating system image

SSH Key management

class hostedpi.models.sshkeys.SSHKeySources[source]

Sources for SSH keys to be added to Pi servers

Parameters:
  • ssh_keys (set[str] | None) – Set of SSH key strings

  • ssh_key_path (Path | None) – Path to an SSH key file

  • github_usernames (set[str] | None) – Set of GitHub usernames to collect SSH keys for

  • launchpad_usernames (set[str] | None) – Set of Launchpad usernames to collect SSH keys for

Raises:

pydantic_core.ValidationError – If the SSH key sources are invalid

field ssh_keys: set[str] | None = None

Set of SSH key strings

field ssh_key_path: Annotated[Path, PathType(path_type=file)] | None = None

Path to an SSH key file

field github_usernames: set[str] | None = None

Set of GitHub usernames to collect SSH keys for

field launchpad_usernames: set[str] | None = None

Set of Launchpad usernames to collect SSH keys for

collect() set[str] | None[source]

Collect SSH keys from various sources, and return them as a set of strings which can be added to a Pi by setting ssh_keys.

Pi info

class hostedpi.models.mythic.responses.PiInfo[source]

Detailed information about a Raspberry Pi server, which comes back when retrieving details for a specific server

field model_full: str | None = None

The full model name of the server, e.g. 3B, 3B+ or 4B rather than just the model number

field is_booting: bool [Required]

Whether the server is currently booting

field boot_progress: str | None = None

The server’s current boot progress

field power: bool [Required]

The server’s power state, True if powered on, False if powered off

field ssh_port: int [Required]

The SSH port that can be used to connect to the server using the IPv4 proxy

field disk_size: int | None = None

The disk size in GB

field nic_speed: int [Required]

The network interface speed of the server in Mbps

field ipv6_address: IPv6Address [Required] (alias 'ip')

The IPv6 address of the server

field ipv6_network: IPv6Network [Required] (alias 'ip_routed')

The IPv6 network the server is on

field initialised_keys: bool [Required]

Whether the server has initialised SSH keys

field location: str [Required]

The location of the data centre the server is in

field model: int [Required]

The model number of the Raspberry Pi server

field memory: int [Required]

The Pi’s RAM size in MB

field cpu_speed: int [Required]

The Pi’s CPU speed in MHz

field provision_status: str [Required] (alias 'status')

The provisioning status of the server

class hostedpi.models.mythic.responses.PiInfoBasic[source]

Basic information about a Raspberry Pi server, which comes back when listing servers

field model: int [Required]

The model number of the Raspberry Pi server

field memory: int [Required]

The Pi’s RAM size in MB

field cpu_speed: int [Required]

The Pi’s CPU speed in MHz

class hostedpi.models.mythic.responses.ProvisioningServer[source]

Response from the Mythic Beasts API when a Raspberry Pi server is still provisioning

field provision_status: str [Required] (alias 'status')

The provisioning status of the server

Settings

Warning

This is for advanced use only. Most users should not need to interact with the settings directly, as they are automatically loaded from Environment variables.

class hostedpi.settings.Settings[source]

This model handles the configuration settings for the Mythic Beasts Hosted Pi API.

Parameters:
  • id (str) – Your API ID. Required to authenticate with the API.

  • secret (str) – Your API secret key. Required to authenticate with the API.

  • auth_url (str) – The authentication URL for the API. This is used to log in and obtain an access token. Defaults to “https://auth.mythic-beasts.com/login”.

  • api_url (str) – The base URL for the API. This is used to make requests to the API endpoints. Defaults to “https://api.mythic-beasts.com/beta/pi/”.

Raises:

pydantic_core.ValidationError – If the provided settings are invalid or missing required fields.

field id: str [Required]

Your API ID

field secret: SecretStr [Required]

Your API secret key

field auth_url: AnyHttpUrl = 'https://auth.mythic-beasts.com/login'

The authentication URL

field api_url: AnyHttpUrl = 'https://api.mythic-beasts.com/beta/pi/'

The API URL