utils
utils contains a few functions for helping you that doesn’t fit in any other category
- get_minecraft_directory() str[source]
Returns the default path to the .minecraft directory
Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() print(f"The default minecraft directory is {minecraft_directory}")
- Return type:
str
- get_latest_version() LatestMinecraftVersions[source]
Returns the latest version of Minecraft
Example:
latest_version = minecraft_launcher_lib.utils.get_latest_version() print("Latest Release " + latest_version["release"]) print("Latest Snapshot " + latest_version["snapshot"])
- Return type:
- get_version_list() list[MinecraftVersionInfo][source]
Returns all versions that Mojang offers to download
Example:
for version in minecraft_launcher_lib.utils.get_version_list(): print(version["id"])
- Return type:
list[MinecraftVersionInfo]
- get_installed_versions(minecraft_directory: str | PathLike) list[MinecraftVersionInfo][source]
Returns all installed versions
Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() for version in minecraft_launcher_lib.utils.get_installed_versions(minecraft_directory): print(version["id"])
- Parameters:
minecraft_directory (str | PathLike) – The path to your Minecraft directory
- Return type:
list[MinecraftVersionInfo]
- get_available_versions(minecraft_directory: str | PathLike) list[MinecraftVersionInfo][source]
Returns all installed versions and all versions that Mojang offers to download
Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() for version in minecraft_launcher_lib.utils.get_available_versions(minecraft_directory): print(version["id"])
- Parameters:
minecraft_directory (str | PathLike) – The path to your Minecraft directory
- Return type:
list[MinecraftVersionInfo]
- get_java_executable() str[source]
Tries the find out the path to the default java executable. Returns
java, if no path was found.Example:
print("The path to Java is " + minecraft_launcher_lib.utils.get_java_executable())
- Return type:
str
- get_library_version() str[source]
Returns the version of minecraft-launcher-lib
Example:
print(f"You are using version {minecraft_launcher_lib.utils.get_library_version()} of minecraft-launcher-lib")
- Return type:
str
- generate_test_options() MinecraftOptions[source]
Generates test options to launch minecraft. This includes a random name and a random uuid.
Note
This function is just for debugging and testing, if Minecraft works. The behavior of this function may change in the future. Do not use it in production.
Example:
version = "1.0" options = minecraft_launcher_lib.utils.generate_test_options() minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() command = minecraft_launcher_lib.command.get_minecraft_command(version, minecraft_directory, options) subprocess.run(command)
- Return type:
- is_version_valid(version: str, minecraft_directory: str | PathLike) bool[source]
Checks if the given version exists. This checks if the given version is installed or offered to download by Mojang. Basically you can use this tho check, if the given version can be used with
install_minecraft_version().Example:
version = "1.0" minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() if minecraft_launcher_lib.utils.is_version_valid(version, minecraft_directory): print(f"{version} is a valid version") else: print(f"{version} is not a valid version")
- Parameters:
version (str) – A Minecraft version
minecraft_directory (str | PathLike) – The path to your Minecraft directory
- Return type:
bool
- is_vanilla_version(version: str) bool[source]
Checks if the given version is a vanilla version
Example:
version = "1.0" if minecraft_launcher_lib.utils.is_vanilla_version(version): print(f"{version} is a vanilla version") else: print(f"{version} is not a vanilla version")
- Parameters:
version (str) – A Minecraft version
- Return type:
bool
- is_platform_supported() bool[source]
Checks if the current platform is supported
Example:
if not minecraft_launcher_lib.utils.is_platform_supported(): print("Your platform is not supported", file=sys.stderr) sys.exit(1)
- Return type:
bool
- is_minecraft_installed(minecraft_directory: str | PathLike) bool[source]
Checks, if there is already a existing Minecraft Installation in the given Directory
Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() if minecraft_launcher_lib.utils.is_minecraft_installed(minecraft_directory): print("Minecraft is installed") else: print("Minecraft is not installed")
- Parameters:
minecraft_directory (str | PathLike) – The path to your Minecraft directory
- Returns:
Is a Installation is found
- Return type:
bool