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:
- Raises:
pydantic_core.ValidationError – If the server specification is invalid
- 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
SSH Key management
- class hostedpi.models.sshkeys.SSHKeySources[source]
Sources for SSH keys to be added to Pi servers
- Parameters:
- Raises:
pydantic_core.ValidationError – If the SSH key sources are invalid
- field ssh_key_path: Annotated[Path, PathType(path_type=file)] | None = None
Path to an SSH key file
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 ssh_port: int [Required]
The SSH port that can be used to connect to the server using the IPv4 proxy
- 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
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 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