classPlatform#
- class Platform( )#
A catalogue of projects. Subclass it to support another platform.
Use it as a context manager, or call
closewhen you are done.- Parameters:
session (Session | None) – The session to use. If omitted, the platform creates its own and closes it in
close.
- session#
The session in use.
- abstractmethod search(
- query: str,
- *,
- project_type: Literal['mod', 'modpack', 'resourcepack', 'shader'] = 'modpack',
- game_version: str | None = None,
- loader: str | None = None,
- offset: int = 0,
- limit: int = 20,
Search the platform’s catalogue.
- Parameters:
query (str) – The search text.
project_type (Literal['mod', 'modpack', 'resourcepack', 'shader']) – The kind of project to find.
game_version (str | None) – Only match this Minecraft version.
loader (str | None) – Only match this mod loader.
offset (int) – How many results to skip.
limit (int) – The maximum number of results to return.
- Returns:
One page of results.
- Raises:
NetworkError – The platform could not be reached.
- Return type:
- abstractmethod get_project( ) Project#
Look up a project by id, slug or URL.
- Parameters:
- Returns:
The project.
- Raises:
NetworkError – The platform failed or does not know the project.
- Return type:
- abstractmethod iter_releases(
- project: Project,
- *,
- game_version: str | None = None,
- loader: str | None = None,
- release_only: bool = False,
Yield a project’s releases, newest first, reading pages as needed.
Stopping early saves requests, so
next()finds the latest release with a single request. Use it while the platform is still open.- Parameters:
- Yields:
Each release, once.
- Raises:
NetworkError – The platform could not be reached.
- list_releases(
- project: Project,
- *,
- game_version: str | None = None,
- loader: str | None = None,
- release_only: bool = False,
List all of a project’s releases, newest first.
This reads every page. Use
iter_releasesif you need only some.- Parameters:
- Returns:
The releases.
- Raises:
NetworkError – The platform could not be reached.
- Return type:
- fetch(
- release: Release,
- into: Path,
- *,
- progress: Callable[[Progress], None] | None = None,
- cancel: CancelToken | None = None,
Download a release’s primary file into a directory.
- Parameters:
release (Release) – The release.
into (Path) – The directory. It is created if needed.
progress (Callable[[Progress], None] | None) – Receives download updates.
cancel (CancelToken | None) – Stops the download.
- Returns:
The downloaded file.
- Raises:
PlatformError – The file has no download link.
DownloadError – The download failed.
Cancelled –
cancelwas triggered.
- Return type: