classPlatform#

class Platform(
session: Session | None = None,
)#

A catalogue of projects. Subclass it to support another platform.

Use it as a context manager, or call close when you are done.

Parameters:

session (Session | None) – The session to use. If omitted, the platform creates its own and closes it in close.

name#

The platform’s name.

Type:

ClassVar[str]

session#

The session in use.

close() → None#

Close the session, if the platform created it.

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,
) → SearchResults#

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:

SearchResults

abstractmethod get_project(
ref: str | int,
*,
project_type: Literal['mod', 'modpack', 'resourcepack', 'shader'] = 'modpack',
) → Project#

Look up a project by id, slug or URL.

Parameters:
  • ref (str | int) – The project’s id, slug or web address.

  • project_type (Literal['mod', 'modpack', 'resourcepack', 'shader']) – The kind of project.

Returns:

The project.

Raises:

NetworkError – The platform failed or does not know the project.

Return type:

Project

abstractmethod iter_releases(
project: Project,
*,
game_version: str | None = None,
loader: str | None = None,
release_only: bool = False,
) → Iterator[Release]#

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:
  • project (Project) – The project.

  • game_version (str | None) – Only list this Minecraft version.

  • loader (str | None) – Only list this mod loader.

  • release_only (bool) – Leave out alpha and beta releases.

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[Release]#

List all of a project’s releases, newest first.

This reads every page. Use iter_releases if you need only some.

Parameters:
  • project (Project) – The project.

  • game_version (str | None) – Only list this Minecraft version.

  • loader (str | None) – Only list this mod loader.

  • release_only (bool) – Leave out alpha and beta releases.

Returns:

The releases.

Raises:

NetworkError – The platform could not be reached.

Return type:

list[Release]

resolve(
pack: Modpack,
) → Modpack#

Fill in downloads for entries this platform can identify.

Parameters:

pack (Modpack) – The modpack.

Returns:

The modpack with resolved entries. By default, it is returned unchanged.

Return type:

Modpack

fetch(
release: Release,
into: Path,
*,
progress: Callable[[Progress], None] | None = None,
cancel: CancelToken | None = None,
) → Path#

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:
Return type:

Path