Como Crear Tu Launcher de Minecraft en Ingles
Como Crear Tu Launcher de Minecraft en Ingles
Como Crear Tu Launcher de Minecraft en Ingles
Release 6.4
JakobDev
1 Introduction 3
1.1 What’s this? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Installation 5
3 Tutorial 7
3.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Microsoft Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Get Installation Progress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4 More Launch Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.5 Install Forge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.6 Install Fabric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.7 Custom Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.8 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4 Modules 15
4.1 command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 natives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4 microsoft_account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.5 utils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.6 java_utils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.7 forge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.8 fabric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.9 quilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.10 runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.11 vanilla_launcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.12 mrpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.13 exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.14 types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.15 microsoft_types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5 FAQ 43
6 Examples 45
6.1 PyQtLauncherWithOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.2 TkinterLauncher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.3 ForgeInstall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.4 PyQtInstallation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
i
6.5 FabricInstall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
6.6 SimpleLaunch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
6.7 PyQtLoginWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.8 Mrpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
6.9 InstallationProgress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7 Troubleshooting 61
8 Contribute 63
9 Develop 65
9.1 Testing changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9.2 Codestyle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9.3 Automatic tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
9.4 Static typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
9.5 Build and edit documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
9.6 Making a Pull Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
10 Showcase 69
11 Changelog 71
11.1 6.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.2 6.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.3 6.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.4 6.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.5 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
11.6 5.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
11.7 5.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
11.8 5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
11.9 5.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
11.10 4.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.11 4.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.12 4.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.13 4.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.14 4.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.15 4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11.16 4.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.17 3.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.18 3.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.19 3.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.20 3.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
11.21 3.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11.22 3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11.23 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11.24 2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11.25 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11.26 1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11.27 1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.28 1.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.29 1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.30 1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.31 0.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.32 0.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.33 0.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
11.34 0.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
ii
11.35 0.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
12 History 79
Index 83
iii
iv
minecraft-launcher-lib, Release 6.4
minecraft-launcher-lib is a easy to use Python library for creating your own Minecraft Launcher.
CONTENTS 1
minecraft-launcher-lib, Release 6.4
2 CONTENTS
CHAPTER
ONE
INTRODUCTION
minecraft-launcher-lib is (as the Name might suggest) a Python library for creating a custom Minecraft launcher. It
allows you to easily install and launch Minecraft without needing to know technical details. It also included functions for
some optional things you may want to have e.g. Installing modloaders like Forge/Fabric/Quilt or installing Modpacks.
Many different things are included, so you can write a Launcher that fit’s exactly your needs.
• You want a simple script that just launches the latest Minecraft version? No problem!
• You want to play a Modpack with your friends, but they have problems installing it? Just create a custom launcher
using minecraft-launcher-lib that installs Minecraft together with the Modpack and automatically connects to
your server.
• You want to create a branded Launcher for your Modpack, to make sure it everyone can install it? With minecraft-
launcher-lib you can do this easily!
1.2 Goals
3
minecraft-launcher-lib, Release 6.4
This documentation contains a tutorial. You should start with the Getting Started tutorial. You can also take a look
at the Modules documentation which contains the full public API. There are also Examples which shows how to use
minecraft-launcher-lib in real code. If you want to see full programs which are using minecraft-launcher-lib, you can
visit the Showcase.
4 Chapter 1. Introduction
CHAPTER
TWO
INSTALLATION
• AUR
If you use Arch Linux or a Arch based Distro like Manjaro, you may want to install it from the Arch User
Repository.
• From Source
You can also install minecraft-launcher-lib directly from source. That will give you the latest changes that
are not in a release yet. Please do this only if you have a good reason.
5
minecraft-launcher-lib, Release 6.4
6 Chapter 2. Installation
CHAPTER
THREE
TUTORIAL
This first chapter of the documentation shows how to install and run Minecraft. The login with Microsoft is skipped
here.
To get started with minecraft-launcher-lib, you need a Minecraft Directory first. You can use a new directory or the
default Directory of Minecraft. You can get the default Directory with get_minecraft_directory().
Before you can launch launch Minecraft, you need to install it. This can be done by using install_minecraft_version.
Let’s say we want to install Version 1.17 in our Minecraft Directory.
minecraft_launcher_lib.install.install_minecraft_version("1.17", minecraft_directory)
To get the information how to install Minecraft, minecraft-launcher-lib looks first for a JSON file in your Minecraft Di-
rectory. In the case of 1.17 it’s minecraft_directory/versions/1.17/1.17.json. This allows installing moded
versions that are not official from Mojang. If the JSON file not does exists minecraft-launcher-lib tries to download it
from the Mojang Servers. install_minecraft_version ensures that the Minecraft installation is correct, so you need to
call it every time before you launch Minecraft, even if you had the version already installed.
7
minecraft-launcher-lib, Release 6.4
If you don’t want to start a single version like 1.17 every time you need a list of all Minecraft version. To get that list
use minecraft_launcher_lib.utils.get_available_versions(minecraft_directory). It returns this list:
[
{
"id": "some_id",
"type": "release"
},
{
"id": "some_other_id",
"type": "snapshot"
}
]
The id is the Minecraft version that can be used as argument for install_minecraft_version and other versions. The type
says what type the version is. Possible values are currently: release, snapshot, beta, alpha. Moded Versions can
also use a custom value, so don’t rely on this list.
To get the latest version, use get_latest_version().
latest_release = minecraft_launcher_lib.utils.get_latest_version()["release"]
latest_snapshot = minecraft_launcher_lib.utils.get_latest_version()["snapshot"]
Since you know how to install Minecraft, it’s now time to start it. First we need a dict with all options. The minimal
options dict is this:
{
"username": "The Username",
"uuid": "The UUID",
"token": "The acces token"
}
The Username and UUID belongs to a Account. Since Name and UUID are public, the Token is used to log in. The
token is generated every time when a User logs in with his Microsoft Account. Minecraft can be launched with a not
existing user and a wrong token. This can be used for test cases. minecraft-launcher-lib allows creating a dict with a
test user.
options = minecraft_launcher_lib.utils.generate_test_options()
We use the test options here to keep it simple. The login with Microsoft comes latter. Keep in mind that publish-
ing a Launcher which allows User who haven’t bought Minecraft to play is illegal, so use this only for test cases in
development. You can add more options to the dict like the resolution, but this is not needed to launch.
Now we have the options, we need to get the Minecraft command. In this case for Version 1.17.
minecraft_command = minecraft_launcher_lib.command.get_minecraft_command("1.17",␣
˓→minecraft_directory, options)
The command that your get is a list of strings that can be used to run Minecraft e.g. with the subprocess module.
8 Chapter 3. Tutorial
minecraft-launcher-lib, Release 6.4
Login with a Microsoft Account requires a Web browser and a Azure Application.
To login with Microsoft you need to create a Azure Application first. Follow this tutorial to create one. You need the
Clinet ID, the Secret and the redirect URL of your new Application.
As stated here, new created Azure Apps need to apply for Permission using this Form before they can use the Minecraft
API. Apps that have been created before this change keeps working without a chance. complete_login() will raise
a AzureAppNotPermitted Exception if your App don’t have the Permission to use the Minecraft API. If you get any
other Exception, that probably means something else with your Azure App is not right.
The login happens in a Web browser. This can be the normal Browser of the System or a Browser Widget embed in your
Program. To get the url that is used for the login use minecraft_launcher_lib.microsoft_account.get_login_url(client_id:
str, redirect_uri: str). Open the URL and test if you can login. After you’ve logged in you will be redi-
rected to https://<your redirect URL>?code=codegoeshere&state=<optional. codegoeshere is the code
that you need. You can use minecraft_launcher_lib.microsoft_account.get_auth_code_from_url(url:
str) to get the code from the url. You can also use minecraft_launcher_lib.microsoft_account.
url_contains_auth_code(url: str) to check if the given URL has a code.
{
"id" : "The uuid",
"name" : "The username",
"access_token": "The acces token",
"refresh_token": "The refresh token",
"skins" : [{
"id" : "6a6e65e5-76dd-4c3c-a625-162924514568",
(continues on next page)
"variant" : "CLASSIC",
"alias" : "STEVE"
} ],
"capes" : []
}
As you can see it contains everything you need for the options dict of get_minecraft_command().
3.2.6 Refresh
Installing a new Minecraft version can, depending on the internet connection, take some time. It would be nice to show
the user the progress e.g. in a Progressbar.
To tell your program the current progress, minecraft-launcher-lib uses callbacks. Callbacks are just normal functions
that you write and that are called by minecraft-launcher-lib. Here is a example:
import minecraft_launcher_lib
current_max = 0
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory()
callback = {
"setStatus": set_status,
"setProgress": set_progress,
(continues on next page)
10 Chapter 3. Tutorial
minecraft-launcher-lib, Release 6.4
minecraft_launcher_lib.install.install_minecraft_version("1.17", minecraft_directory,␣
˓→callback=callback)
As you can see callback is a dict with functions. The functions are defined by you. You can write in these functions
whatever you want. In the example above it prints the current status to the commandline.
minecraft-launcher-lib offers various options for launching Minecraft. This page shows the most important ones. For
a full list check out the documentation of the command module.
JVM Arguments are a list of strings. Each argument is a entry in the list. Here is a example:
# Right
options["jvmArguments"] = ["-Xmx2G", "-Xms2G"]
# Wrong
options["jvmArguments"] = ["-Xmx2G -Xms2G"]
# Wrong
options["jvmArguments"] = "-Xmx2G -Xms2G"
Make sure every argument starts with a -, otherwise Minecraft will not start with a Could not find or load main
class error.
The Java Executable is the path the Java which is used to run Minecraft. If the version.json contains a Java Runtime, it
minecraft-launcher-lib will download and use these version. Otherwise it will just use the java command. minecraft-
launcher-lib allows to overwrite this. This can be useful, if you want to start a older version which needs a older Java
and does not contain a runtime in the version.json.
There are 2 options to overwrite the Java Executable: executablePath and defaultExecutablePath. The dif-
ference is, that executablePath is always used. defaultExecutablePath is only used, when the version.json
has set no Java Runtime. If the version.json contains a Runtime, the Runtime will be prefered over the defaultExe-
cutablePath.
options["executablePath"] = "path/to/java"
options["defaultExecutablePath"] = "path/to/java"
minecraft-launcher-lib allows starting Minecraft with a custom resolution. The first thing you have to do is enable the
custom resolution. After that you can set it:
Make sure you use strings and not int for the resolution.
The Game Directory is the directory where Minecraft saves all his stuff like Worlds, Resourcepacks, Options etc. By
default your Minecraft Directory is used as Game Directory.
options["gameDirectory"] = "path/to/your/game/directory"
Minecraft has a build-in Demo mode, which is used, if somebody who does not bought Minecraft launches the Game
through the official launcher. minecraft-launcher-lib allows you to enable the Demo mode. You need at least Minecraft
version 1.3.1 to use the Demo mode.
options["demo"] = True
This tutorial shows how to install forge using minecraft-launcher-lib. Please note that the Forge Devs do not want
automatic installations unless you donated to them.
Before you install Forge, you need to know what Forge version you need. Use find_forge_version():
forge_version = minecraft_launcher_lib.forge.find_forge_version("1.17.1")
if forge_version is None:
print("This Minecraft Version is not supported by Forge")
return
12 Chapter 3. Tutorial
minecraft-launcher-lib, Release 6.4
Now we have the Forge version, so we can install it. Use install_forge_version().
minecraft_launcher_lib.forge.install_forge_version(forge_version, minecraft_
˓→directory)
Unfortunately, the version we got with find_forge_version() can’t be used for get_minecraft_command(), be-
cause forge installs it under a little different name. Use find_forge_version() to get the right version id for the
launch.
Installing Fabric is very easy. Let’s say you want to install Fabric for 1.17:
minecraft_launcher_lib.fabric.install_fabric("1.17", minecraft_directoy)
Use get_installed_versions() to get a list of all installed versions. Your new installed fabric version should be
in the list. You can launch it like any other Minecraft version.
You will see types like e.g MinecraftOptions or MinecraftVersionInfo. They are defined in types and microsoft_types.
They are all normal Dicts. Let’s take a look at MinecraftVersionInfo:
class MinecraftVersionInfo(TypedDict):
id: str
type: str
releaseTime: datetime.datetime
It means the following: This function returns a Dict with these keys:
• id: A string
• type: A string
• releaseTime: A datetime.datetime
This type definition is just there to help your IDE. The function itself returns just a normal Dict.
version_list = minecraft_launcher_lib.utils.get_version_list()
print(version_list[0]["id"])
print(type(version_list[0]))
# <class 'dict'>
As said above, it is there to help your IDE. When the function definition just say, that it returns a Dict, your IDE will
not know what the Dict contains. But when using a TypedDict, your IDE, will exactly know what the Dict contains and
can offer your better autocompletion and a better type checking.
You can even use it when you are calling a function:
import minecraft_launcher_lib
options: minecraft_launcher_lib.types.MinecraftOptions = {}
options["username"] = "Test123"
When using a IDE, you will see that it will start autocompleting the keys of the Dict while writing.
For more information about TypedDict see PEP 589.
14 Chapter 3. Tutorial
CHAPTER
FOUR
MODULES
4.1 command
options = {
# This is needed
"username": The Username,
"uuid": uuid of the user,
"token": the accessToken,
# This is optional
"executablePath": "java", # The path to the java executable
"defaultExecutablePath": "java", # The path to the java executable if the␣
˓→version.json has none
"port": "123", # The port of a server where Minecraft connect to after start
"nativesDirectory": "minecraft_directory/versions/version/natives", # The␣
(continues on next page)
15
minecraft-launcher-lib, Release 6.4
You can use the microsoft_account module to get the needed information. For more information about the options
take a look at the More Launch Options tutorial.
View the source code of this module
4.2 install
callback = {
"setStatus": some_function, # This function is called to set a text
"setProgress" some_function, # This function is called to set the progress.
"setMax": some_function, # This function is called to set to max progress.
}
16 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
4.3 natives
4.4 microsoft_account
microsoft_account contains functions for login with a Microsoft Account. Before using this module you need to create
a Azure application. Many thanks to wiki.vg for it’s documentation of the login process. You may want to read the
Microsoft Login tutorial before using this module. For a list of all types see microsoft_types.
get_login_url(client_id: str, redirect_uri: str) → str
Generate a login url.For a more secure alternative, use get_secure_login_data()
Parameters
• client_id (str) – The Client ID of your Azure App
• redirect_uri (str) – The Redirect URI of your Azure App
Returns
The url to the website on which the user logs in
Return type
str
generate_state() → str
Generates a random state
Return type
str
4.3. natives 17
minecraft-launcher-lib, Release 6.4
get_secure_login_data(client_id: str, redirect_uri: str, state: str | None = None) → Tuple[str, str, str]
Generates the login data for a secure login with pkce and state.Prevents Cross-Site Request Forgery attacks and
authorization code injection attacks.
Parameters
• client_id (str) – The Client ID of your Azure App
• redirect_uri (str) – The Redirect URI of your Azure App
• state (str | None) – You can use a existing state. If not set, a state will be generated
using generate_state().
Return type
Tuple[str, str, str]
url_contains_auth_code(url: str) → bool
Checks if the given url contains a authorization code
Parameters
url (str) – The URL to check
Return type
bool
get_auth_code_from_url(url: str) → str | None
Get the authorization code from the url.If you want to check the state, use parse_auth_code_url(), which
throws errors instead of returning an optional value.
Parameters
url (str) – The URL to parse
Returns
The auth code or None if the the code is nonexistent
Return type
str | None
parse_auth_code_url(url: str, state: str | None) → str
Parse the authorization code url and checks the state.
Parameters
• url (str) – The URL to parse
• state (str | None) – If set, the function raises a AssertionError, if the state do no match
the state in the URL
Returns
The auth code
Return type
str
get_authorization_token(client_id: str, client_secret: str | None, redirect_uri: str, auth_code: str,
code_verifier: str | None = None) → AuthorizationTokenResponse
Get the authorization token. This function is called during complete_login(), so you need to use this function
ony if complete_login() doesnt’t work for you.
Parameters
• client_id (str) – The Client ID of your Azure App
18 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
• client_secret (str | None) – The Client Secret of your Azure App. This is deprecated
and should not been used anymore.
• redirect_uri (str) – The Redirect URI of your Azure App
• auth_code (str) – The Code you get from parse_auth_code_url()
• code_verifier (str | None) – The 3rd entry in the Tuple you get from
get_secure_login_data()
Return type
AuthorizationTokenResponse
refresh_authorization_token(client_id: str, client_secret: str | None, redirect_uri: str | None, refresh_token:
str) → AuthorizationTokenResponse
Refresh the authorization token. This function is called during complete_refresh(), so you need to use this
function ony if complete_refresh() doesnt’t work for you.
Parameters
• client_id (str) – The Client ID of your Azure App
• client_secret (str | None) – The Client Secret of your Azure App. This is deprecated
and should not been used anymore.
• redirect_uri (str | None) – The Redirect URI of Azure App. This Parameter only
exists for backwards compatibility and is not used anymore.
• refresh_token (str) – Your refresh token
Return type
AuthorizationTokenResponse
authenticate_with_xbl(access_token: str) → XBLResponse
Authenticate with Xbox Live. This function is called during complete_login(), so you need to use this func-
tion ony if complete_login() doesnt’t work for you.
Parameters
access_token (str) – The Token you get from get_authorization_token()
Return type
XBLResponse
authenticate_with_xsts(xbl_token: str) → XSTSResponse
Authenticate with XSTS. This function is called during complete_login(), so you need to use this function
ony if complete_login() doesnt’t work for you.
Parameters
xbl_token (str) – The Token you get from authenticate_with_xbl()
Return type
XSTSResponse
authenticate_with_minecraft(userhash: str, xsts_token: str) → MinecraftAuthenticateResponse
Authenticate with Minecraft. This function is called during complete_login(), so you need to use this function
ony if complete_login() doesnt’t work for you.
Parameters
• userhash (str) – The Hash you get from authenticate_with_xbl()
• xsts_token (str) – The Token you get from authenticate_with_xsts()
4.4. microsoft_account 19
minecraft-launcher-lib, Release 6.4
Return type
MinecraftAuthenticateResponse
get_store_information(access_token: str) → MinecraftStoreResponse
Get the store information.
Parameters
access_token (str) – The Token you get from authenticate_with_minecraft()
Return type
MinecraftStoreResponse
get_profile(access_token: str) → MinecraftProfileResponse
Get the profile. This function is called during complete_login(), so you need to use this function ony if
complete_login() doesnt’t work for you.
Parameters
access_token (str) – The Token you get from authenticate_with_minecraft()
Return type
MinecraftProfileResponse
complete_login(client_id: str, client_secret: str | None, redirect_uri: str, auth_code: str, code_verifier: str | None
= None) → CompleteLoginResponse
Do the complete login process.
Parameters
• client_id (str) – The Client ID of your Azure App
• client_secret (str | None) – The Client Secret of your Azure App. This is deprecated
and should not been used anymore.
• redirect_uri (str) – The Redirect URI of your Azure App
• auth_code (str) – The Code you get from parse_auth_code_url()
• code_verifier (str | None) – The 3rd entry in the Tuple you get from
get_secure_login_data()
Raises
• AzureAppNotPermitted – Your Azure App don’t have the Permission to use the Minecraft
API
• AccountNotOwnMinecraft – The Account does not own Minecraft
Return type
CompleteLoginResponse
It returns the following:
{
"id" : "The uuid",
"name" : "The username",
"access_token": "The acces token",
"refresh_token": "The refresh token",
"skins" : [{
"id" : "6a6e65e5-76dd-4c3c-a625-162924514568",
"state" : "ACTIVE",
"url" : "http://textures.minecraft.net/texture/
˓→1a4af718455d4aab528e7a61f86fa25e6a369d1768dcb13f7df319a713eb810b",
20 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
complete_refresh(client_id: str, client_secret: str | None, redirect_uri: str | None, refresh_token: str) →
CompleteLoginResponse
Do the complete login process with a refresh token. It returns the same as complete_login().
Parameters
• client_id (str) – The Client ID of your Azure App
• client_secret (str | None) – The Client Secret of your Azure App. This is deprecated
and should not been used anymore.
• redirect_uri (str | None) – The Redirect URI of Azure App. This Parameter only
exists for backwards compatibility and is not used anymore.
• refresh_token (str) – Your refresh token
Raises
• InvalidRefreshToken – Your refresh token is not valid
• AccountNotOwnMinecraft – The Account does not own Minecraft
Return type
CompleteLoginResponse
View the source code of this module
4.5 utils
utils contains a few functions for helping you that doesn’t fit in any other category
get_minecraft_directory() → str
Returns the default path to the .minecraft directory
Return type
str
get_latest_version() → LatestMinecraftVersions
Returns the latest version of Minecraft
Return type
LatestMinecraftVersions
get_version_list() → List[MinecraftVersionInfo]
Returns all versions that Mojang offers to download
Return type
List[MinecraftVersionInfo]
get_installed_versions(minecraft_directory: str | PathLike) → List[MinecraftVersionInfo]
Returns all installed versions
4.5. utils 21
minecraft-launcher-lib, Release 6.4
Parameters
minecraft_directory (str | PathLike) – The path to your Minecraft directory
Return type
List[MinecraftVersionInfo]
get_available_versions(minecraft_directory: str | PathLike) → List[MinecraftVersionInfo]
Returns all installed versions and all versions that Mojang offers to download
Parameters
minecraft_directory (str | PathLike) – The path to your Minecraft directory
Return type
List[MinecraftVersionInfo]
get_java_executable() → str
Tries the find out the path to the default java executable
Return type
str
get_library_version() → str
Returns the version of minecraft-launcher-lib
Return type
str
generate_test_options() → MinecraftOptions
Generates options to launch minecraft. Useful for testing. Do not use in production.
Return type
MinecraftOptions
is_version_valid(version: str, minecraft_directory: str | PathLike) → bool
Checks if the given version exists
Parameters
• version (str) – A Minecraft version
• minecraft_directory (str | PathLike) – The path to your Minecraft directory
Return type
bool
get_minecraft_news(page_size: int = 20) → Articles
Get the news from minecraft.net
Parameters
page_size (int) – The Page Size (default 20)
Return type
Articles
is_vanilla_version(version: str) → bool
Checks if the given version is a vanilla version
Parameters
version (str) – A Minecraft version
Return type
bool
22 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
is_platform_supported() → bool
Checks if the current platform is supported
Return type
bool
is_minecraft_installed(minecraft_directory: str | PathLike) → bool
Checks, if there is already a existing Minecraft Installation in the given Directory
Parameters
minecraft_directory (str | PathLike) – The path to your Minecraft directory
Returns
Is a Installation is found
Return type
bool
View the source code of this module
4.6 java_utils
Note: This Function executes the Java executable to detemine details such as the version. This might be a
security risk.
4.6. java_utils 23
minecraft-launcher-lib, Release 6.4
Note: This Function executes the Java executable to detemine details such as the version. This might be a
security risk.
4.7 forge
Note: Before using this module, please read this comment from the forge developers:
It’s your choice, if you want to respect that and support forge.
24 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
4.7. forge 25
minecraft-launcher-lib, Release 6.4
4.8 fabric
26 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
4.9 quilt
4.9. quilt 27
minecraft-launcher-lib, Release 6.4
get_all_loader_versions() → List[QuiltLoader]
Returns all loader versions
Return type
List[QuiltLoader]
get_latest_loader_version() → str
Get the latest loader version
Return type
str
get_latest_installer_version() → str
Returns the latest installer version
Return type
str
install_quilt(minecraft_version: str, minecraft_directory: str | PathLike, loader_version: str | None = None,
callback: CallbackDict | None = None, java: str | PathLike | None = None) → None
Installs the Quilt modloader.
Parameters
• minecraft_version (str) – A vanilla version that is supported by Quilt
• minecraft_directory (str | PathLike) – The path to your Minecraft directory
• loader_version (str | None) – The Quilt loader version. If not given it will use the
latest
• callback (CallbackDict | None) – The same dict as for
install_minecraft_version()
• java (str | PathLike | None) – A Path to a custom Java executable
Raises
UnsupportedVersion – The given Minecraft version is not supported by Quilt
Return type
None
View the source code of this module
4.10 runtime
runtime allows to install the java runtime. This module is used by install_minecraft_version(), so you don’t
need to use it in your code most of the time.
get_jvm_runtimes() → List[str]
Returns a list of all jvm runtimes
Return type
List[str]
get_installed_jvm_runtimes(minecraft_directory: str | PathLike) → List[str]
Returns a list of all installed jvm runtimes
Parameters
minecraft_directory (str | PathLike) – The path to your Minecraft directory
28 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
Return type
List[str]
install_jvm_runtime(jvm_version: str, minecraft_directory: str | PathLike, callback: CallbackDict | None =
None) → None
Installs the given jvm runtime. callback is the same dict as in the install module.
Parameters
• jvm_version (str) – The Name of the JVM version
• minecraft_directory (str | PathLike) – The path to your Minecraft directory
• callback (CallbackDict | None) – the same dict as for
install_minecraft_version()
Raises
• VersionNotFound – The given JVM Version was not found
• FileOutsideMinecraftDirectory – A File should be placed outside the given Minecraft
directory
Return type
None
get_executable_path(jvm_version: str, minecraft_directory: str | PathLike) → str | None
Returns the path to the executable. Returns None if none is found.
Parameters
• jvm_version (str) – The Name of the JVM version
• minecraft_directory (str | PathLike) – The path to your Minecraft directory
Return type
str | None
get_jvm_runtime_information(jvm_version: str) → JvmRuntimeInformation
Returns some Information about a JVM Version
Parameters
jvm_version (str) – A JVM Version
Raises
• VersionNotFound – The given JVM Version was not found
• VersionNotFound – The given JVM Version is not available on this Platform
Returns
A Dict with Information
Return type
JvmRuntimeInformation
get_version_runtime_information(version: str, minecraft_directory: str | PathLike) →
VersionRuntimeInformation | None
Returns inforation about the runtime used by a version
Parameters
• jvm_version – The Minecraft version
• minecraft_directory (str | PathLike) – The path to your Minecraft directory
4.10. runtime 29
minecraft-launcher-lib, Release 6.4
• version (str) –
Raises
VersionNotFound – The Minecraft version was not found
Returns
A Dict with Information. None if the vserion has no runtime information.
Return type
VersionRuntimeInformation | None
View the source code of this module
4.11 vanilla_launcher
vanilla_launcher contains some functions for interacting with the Vanilla Minecraft Launcher
load_vanilla_launcher_profiles(minecraft_directory: str | PathLike) → List[VanillaLauncherProfile]
Loads the profiles of the Vanilla Launcher from the given Minecraft directory
Parameters
minecraft_directory (str | PathLike) – The Minecraft directory
Returns
A List with the Profiles
Return type
List[VanillaLauncherProfile]
vanilla_launcher_profile_to_minecraft_options(vanilla_profile: VanillaLauncherProfile) →
MinecraftOptions
Converts a VanillaLauncherProfile into a Options dict, that can be used by install_minecraft_version().
You still need to add the Login Data to the Options before you can use it.
Parameters
vanilla_profile (VanillaLauncherProfile) – The profile as returned by
load_vanilla_launcher_profiles()
Raises
InvalidVanillaLauncherProfile – The given Profile is invalid
Returns
The Options Dict
Return type
MinecraftOptions
get_vanilla_launcher_profile_version(vanilla_profile: VanillaLauncherProfile) → str
Returns the Minecraft version of the VanillaProfile. Handles latest-release and latest-snapshot.
Parameters
vanilla_profile (VanillaLauncherProfile) – The Profile
Raises
InvalidVanillaLauncherProfile – The given Profile is invalid
Returns
The Minecraft version
Return type
str
30 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
4.12 mrpack
4.12. mrpack 31
minecraft-launcher-lib, Release 6.4
mrpack_install_options = {
"optionalFiles": [], # List with all Optional files
"skipDependenciesInstall": False # If you want to skip the Dependencie install.␣
˓→Only used for testing purposes.
4.13 exceptions
32 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
4.13. exceptions 33
minecraft-launcher-lib, Release 6.4
34 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
expected_checksum: str
The expected Checksum
actual_checksum: str
The actual Checksum
exception AzureAppNotPermitted
Bases: Exception
Raised when you try to use a Azure App, that don’t have the Permission to use the Minecraft API. Take a look
at the For more information about the options take a look at the Microsoft Login tutorial to learn how to fix this.
Return type
None
exception PlatformNotSupported
Bases: Exception
Raised, when the current Platform is not supported by a feature
Return type
None
exception AccountNotOwnMinecraft
Bases: Exception
Raised by complete_login() and complete_login() when the Account does not own Minecraft
Return type
None
View the source code of this module
4.14 types
This module contains all Types for minecraft-launcher-lib. It may help your IDE. You don’t need to use this module
directly in your code. If you are not interested in static typing just ignore it. For more information about TypeDict see
PEP 589.
class MinecraftOptions
Bases: TypedDict
username: str
uuid: str
token: str
executablePath: str
defaultExecutablePath: str
jvmArguments: List[str]
launcherName: str
launcherVersion: str
gameDirectory: str
4.14. types 35
minecraft-launcher-lib, Release 6.4
demo: bool
customResolution: bool
resolutionWidth: str
resolutionHeight: str
server: str
port: str
nativesDirectory: str
enableLoggingConfig: bool
disableMultiplayer: bool
disableChat: bool
class CallbackDict
Bases: TypedDict
setStatus: Callable[[str], None]
class LatestMinecraftVersions
Bases: TypedDict
release: str
snapshot: str
class MinecraftVersionInfo
Bases: TypedDict
id: str
type: str
releaseTime: datetime
complianceLevel: int
class FabricMinecraftVersion
Bases: TypedDict
version: str
36 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
stable: bool
class FabricLoader
Bases: TypedDict
separator: str
build: int
maven: str
version: str
stable: bool
class QuiltMinecraftVersion
Bases: TypedDict
version: str
stable: bool
class QuiltLoader
Bases: TypedDict
separator: str
build: int
maven: str
version: str
class Image
Bases: dict
alt: str
videoURL: str
videoType: str
videoProvider: str
videoId: str
linkurl: str
imageURL: str
class Tile
Bases: TypedDict
sub_header: str
image: Image
4.14. types 37
minecraft-launcher-lib, Release 6.4
title: str
class Article
Bases: dict
preferred_tile: Tile
default_tile: Tile
articleLang: Literal['en-us']
primary_category: str
categories: List[str]
article_url: str
publish_date: str
tags: List[str]
class Articles
Bases: TypedDict
article_grid: List[Article]
article_count: int
class JavaInformation
Bases: TypedDict
path: str
name: str
version: str
java_path: str
is_64bit: bool
openjdk: bool
class VanillaLauncherProfileResolution
Bases: TypedDict
height: int
width: int
class VanillaLauncherProfile
Bases: TypedDict
name: str
38 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
class MrpackInformation
Bases: TypedDict
name: str
summary: str
versionId: str
formatVersion: int
minecraftVersion: str
optionalFiles: List[str]
class MrpackInstallOptions
Bases: TypedDict
optionalFiles: List[str]
skipDependenciesInstall: bool
class JvmRuntimeInformation
Bases: TypedDict
name: str
released: datetime
class VersionRuntimeInformation
Bases: TypedDict
name: str
javaMajorVersion: int
4.15 microsoft_types
This module contains all Types for the microsoft_account module. It has it’s own module because of the many types
needed that are not used somewhere else.
class AuthorizationTokenResponse
Bases: TypedDict
access_token: str
4.15. microsoft_types 39
minecraft-launcher-lib, Release 6.4
token_type: Literal['Bearer']
expires_in: int
scope: str
refresh_token: str
class XBLResponse
Bases: TypedDict
IssueInstant: str
NotAfter: str
Token: str
DisplayClaims: _DisplayClaims
class XSTSResponse
Bases: TypedDict
IssueInstant: str
NotAfter: str
Token: str
DisplayClaimns: _DisplayClaims
class MinecraftStoreResponse
Bases: TypedDict
signature: str
keyId: str
class MinecraftAuthenticateResponse
Bases: TypedDict
username: str
roles: List[Any]
access_token: str
token_type: str
expires_in: int
class MinecraftProfileResponse
Bases: TypedDict
id: str
name: str
skins: List[_MinecraftProfileSkin]
capes: List[_MinecraftProfileCape]
40 Chapter 4. Modules
minecraft-launcher-lib, Release 6.4
error: str
errorMessage: str
class CompleteLoginResponse
Bases: dict
access_token: str
refresh_token: str
id: str
name: str
skins: List[_MinecraftProfileSkin]
capes: List[_MinecraftProfileCape]
error: str
errorMessage: str
4.15. microsoft_types 41
minecraft-launcher-lib, Release 6.4
42 Chapter 4. Modules
CHAPTER
FIVE
FAQ
43
minecraft-launcher-lib, Release 6.4
44 Chapter 5. FAQ
CHAPTER
SIX
EXAMPLES
6.1 PyQtLauncherWithOutput
#!/usr/bin/env python3
# This example shows a simple launcher with PyQt that shows the output of Minecraft in a␣
˓→text filed
class GameOutputWidget(QPlainTextEdit):
def __init__(self, launch_button):
super().__init__()
self.setReadOnly(True)
self.launch_button = launch_button
# Disable line wrap
self.setLineWrapMode(QPlainTextEdit.LineWrapMode.NoWrap)
def display_output(self):
# This function displays the output of Minecraft in the text field
cursor = self.textCursor()
cursor.movePosition(cursor.MoveOperation.End)
cursor.insertText(bytes(self.process.readAll()).decode())
cursor.movePosition(cursor.MoveOperation.End)
self.ensureCursorVisible()
45
minecraft-launcher-lib, Release 6.4
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.username_edit = QLineEdit()
self.password_edit = QLineEdit()
self.version_select = QComboBox()
launch_button = QPushButton("Launch")
self.output_widget = GameOutputWidget(launch_button)
launch_button.clicked.connect(self.launch_minecraft)
main_layout = QVBoxLayout()
main_layout.addWidget(self.output_widget)
main_layout.addLayout(bottom_layout)
self.setLayout(main_layout)
self.setGeometry(0, 0, 800, 600)
self.setWindowTitle("PyQt Launcher with Output")
def launch_minecraft(self):
# Get the selected version
version = self.version_select.currentText()
46 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
# Login
login_data = minecraft_launcher_lib.account.login_user(self.username_edit.text(),
˓→ self.password_edit.text())
options = {
"username": login_data["selectedProfile"]["name"],
"uuid": login_data["selectedProfile"]["id"],
"token": login_data["accessToken"]
}
def main():
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()
6.1. PyQtLauncherWithOutput 47
minecraft-launcher-lib, Release 6.4
6.2 TkinterLauncher
#!/usr/bin/env python3
# This example shows how to write a basic launcher with Tkinter.
from tkinter import Tk, Label, Entry, Button, mainloop
from tkinter.ttk import Combobox
import minecraft_launcher_lib
import subprocess
import sys
def main():
def launch():
window.withdraw()
minecraft_launcher_lib.install.install_minecraft_version(version_select.get(),␣
˓→minecraft_directory)
login_data = minecraft_launcher_lib.account.login_user(username_input.get(),␣
˓→password_input.get())
options = {
"username": login_data["selectedProfile"]["name"],
"uuid": login_data["selectedProfile"]["id"],
"token": login_data["accessToken"]
}
minecraft_command = minecraft_launcher_lib.command.get_minecraft_command(version_
˓→select.get(), minecraft_directory, options)
subprocess.run(minecraft_command)
sys.exit(0)
window = Tk()
window.title("Minecraft Launcher")
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory()
versions = minecraft_launcher_lib.utils.get_available_versions(minecraft_directory)
version_list = []
for i in versions:
version_list.append(i["id"])
48 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
mainloop()
if __name__ == "__main__":
main()
6.3 ForgeInstall
#!/usr/bin/env python3
# This example shows how to install forge using minecraft-launcher-lib
import minecraft_launcher_lib
import sys
def main():
vanilla_version = input("Select the Minecraft version for which you want to install␣
˓→forge:")
6.3. ForgeInstall 49
minecraft-launcher-lib, Release 6.4
if __name__ == "__main__":
main()
6.4 PyQtInstallation
#!/usr/bin/env python3
# This example shows how to install Minecraft with a ProgressBar in PyQt
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QLineEdit,␣
˓→QPushButton, QProgressBar, QFileDialog, QFormLayout, QHBoxLayout, QVBoxLayout
class InstallThread(QThread):
progress_max = pyqtSignal("int")
progress = pyqtSignal("int")
text = pyqtSignal("QString")
class Window(QWidget):
def __init__(self) -> None:
super().__init__()
self._install_thread = InstallThread()
50 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
for i in minecraft_launcher_lib.utils.get_version_list():
self._version_combo_box.addItem(i["id"])
self._path_edit.setText(minecraft_launcher_lib.utils.get_minecraft_directory())
self._progress_bar.setTextVisible(True)
self._install_thread.finished.connect(self._install_thread_finished)
self._path_browse_button.clicked.connect(self._path_browse_button_clicked)
self._install_single_thread_button.clicked.connect(self._install_minecraft_
˓→single_thread)
self._install_multi_thread_button.clicked.connect(self._install_minecraft_multi_
˓→thread)
path_layout = QHBoxLayout()
path_layout.addWidget(self._path_edit)
path_layout.addWidget(self._path_browse_button)
form_layout = QFormLayout()
form_layout.addRow(QLabel("Version:"), self._version_combo_box)
form_layout.addRow(QLabel("Path:"), path_layout)
button_layout = QHBoxLayout()
button_layout.addWidget(self._install_single_thread_button)
button_layout.addWidget(self._install_multi_thread_button)
main_layout = QVBoxLayout()
main_layout.addLayout(form_layout)
main_layout.addWidget(self._progress_bar)
main_layout.addLayout(button_layout)
self.setLayout(main_layout)
self.setWindowTitle("PyQtInstallation")
6.4. PyQtInstallation 51
minecraft-launcher-lib, Release 6.4
callback = {
"setStatus": lambda text: self._progress_bar.setFormat(text),
"setProgress": lambda value: self._progress_bar.setValue(value),
"setMax": lambda maximum: self._progress_bar.setMaximum(maximum)
}
minecraft_launcher_lib.install.install_minecraft_version(self._version_combo_box.
˓→currentText(), self._path_edit.text(), callback=callback)
self._install_thread.set_data(self._version_combo_box.currentText(), self._path_
˓→edit.text())
self._install_thread.start()
def main():
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()
52 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
6.5 FabricInstall
#!/usr/bin/env python3
# This example shows how to install fabric using minecraft-launcher-lib
import minecraft_launcher_lib
import sys
def main():
vanilla_version = input("Select the Minecraft version for which you want to install␣
˓→fabric:")
if not minecraft_launcher_lib.fabric.is_minecraft_version_supported(vanilla_version):
print("This version is not supported by fabric")
sys.exit(0)
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory()
callback = {
"setStatus": lambda text: print(text)
}
minecraft_launcher_lib.fabric.install_fabric(vanilla_version, minecraft_directory,␣
˓→callback=callback)
if __name__ == "__main__":
main()
6.6 SimpleLaunch
#!/usr/bin/env python3
# This example shows how to simple install and launch the latest version of Minecraft.
import minecraft_launcher_lib
import subprocess
import sys
# Set the data for your Azure Application here. For more information look at the␣
˓→documentation.
# Login
(continues on next page)
6.5. FabricInstall 53
minecraft-launcher-lib, Release 6.4
print(f"Please open {login_url} in your browser and copy the url you are redirected into␣
˓→the prompt below.")
code_url = input()
except AssertionError:
print("States do not match!")
sys.exit(1)
except KeyError:
print("Url not valid")
sys.exit(1)
# Start Minecraft
subprocess.run(minecraft_command)
6.7 PyQtLoginWindow
#!/usr/bin/env python3
# This example shows how to use the PyQt WebEngine for the Login
# It needs the PyQt6 and PyQt6-WebEngine packages
from PyQt6.QtWidgets import QApplication, QMessageBox
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEngineProfile
from PyQt6.QtCore import QUrl, QLocale
import minecraft_launcher_lib
import json
import sys
import os
54 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
class LoginWindow(QWebEngineView):
def __init__(self):
super().__init__()
self.show_account_information(account_informaton)
# Show the window if the refresh token is invalid
except minecraft_launcher_lib.exceptions.InvalidRefreshToken:
pass
self.load(QUrl(login_url))
self.show()
# Do the login
account_information = minecraft_launcher_lib.microsoft_account.complete_
˓→login(CLIENT_ID, None, REDIRECT_URL, auth_code, self.code_verifier)
6.7. PyQtLoginWindow 55
minecraft-launcher-lib, Release 6.4
message_box = QMessageBox()
message_box.setWindowTitle("Account information")
message_box.setText(information_string)
message_box.setStandardButtons(QMessageBox.StandardButton.Ok)
message_box.exec()
if __name__ == "__main__":
app = QApplication(sys.argv)
# This line sets the language of the webpage to the system language
QWebEngineProfile.defaultProfile().setHttpAcceptLanguage(QLocale.system().name().
˓→split("_")[0])
w = LoginWindow()
sys.exit(app.exec())
6.8 Mrpack
#!/usr/bin/env python3
# This example shows how use the mrpack module
import minecraft_launcher_lib
import subprocess
import sys
import os
if answer == "Y":
return True
elif answer == "N":
return False
else:
print("Invalid answer. Use Y or N.")
56 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
if not os.path.isfile(mrpack_path):
print(f"{mrpack_path} was not found", file=sys.stderr)
sys.exit(1)
try:
mrpack_information = minecraft_launcher_lib.mrpack.get_mrpack_information(mrpack_
˓→path)
except Exception:
print(f"{mrpack_path} is not a valid .mrpack File")
sys.exit(1)
if minecraft_directory == "":
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory()
modpack_directory = input("Please enter the Path to the Directory you want to␣
˓→install the Modpack (leave empty for your Minecraft directory): ")
if modpack_directory == "":
modpack_directory = minecraft_directory
for i in mrpack_information["optionalFiles"]:
if ask_yes_no(f"The Pack includes the Optional File {i}. Do you want to install␣
˓→it?"):
mrpack_install_options["optionalFiles"].append(i)
# Install
print("Installing")
minecraft_launcher_lib.mrpack.install_mrpack(mrpack_path, minecraft_directory,␣
˓→modpack_directory=modpack_directory, mrpack_install_options=mrpack_install_options,␣
˓→callback={"setStatus": print})
print("Finished")
6.8. Mrpack 57
minecraft-launcher-lib, Release 6.4
subprocess.run(command)
if __name__ == "__main__":
main()
6.9 InstallationProgress
#!/usr/bin/env python3
# This example shows how to show the progress of installation to the user.
import minecraft_launcher_lib
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
length - Optional : character length of bar (Int)
fill - Optional : bar fill character (Str)
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
"""
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
filledLength = int(length * iteration // total)
bar = fill * filledLength + '-' * (length - filledLength)
print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end=printEnd)
# Print New Line on Complete
if iteration == total:
print()
58 Chapter 6. Examples
minecraft-launcher-lib, Release 6.4
callback = {
"setStatus": lambda text: print(text),
"setProgress": lambda value: printProgressBar(value, max_value[0]),
"setMax": lambda value: maximum(max_value, value)
}
version = minecraft_launcher_lib.utils.get_latest_version()["release"]
directory = minecraft_launcher_lib.utils.get_minecraft_directory()
minecraft_launcher_lib.install.install_minecraft_version(version, directory,␣
˓→callback=callback)
if __name__ == "__main__":
main()
6.9. InstallationProgress 59
minecraft-launcher-lib, Release 6.4
60 Chapter 6. Examples
CHAPTER
SEVEN
TROUBLESHOOTING
61
minecraft-launcher-lib, Release 6.4
62 Chapter 7. Troubleshooting
CHAPTER
EIGHT
CONTRIBUTE
Many thanks for contributing to minecraft-launcher-lib! You can do the following thinks:
• You can test minecraft-launcher-lib with all versions and write a Bug report if something did not work
• You can help developing minecraft-launcher-lib. Check out the Develop section of the documentation.
• You can can improve the documentation. See Build and edit documentation.
• You can also update the Examples and add new one.
63
minecraft-launcher-lib, Release 6.4
64 Chapter 8. Contribute
CHAPTER
NINE
DEVELOP
While there are automatic tests for the utils functions, the main part (installing launching and logging in into Microsoft)
must be tested by yourself.
Open a command line in the root directory of minecraft-launcher-lib and open the Python Interpreter. In the Interpreter
run:
It should print the path to your current directory. After you’ve confirmed, that you are using the version you are currently
working on, you can start testing.
Just run the functions you have changed and see, if everything worked correctly. Please test installation and launching
in a clean directory and not your normal .minecraft directory.
9.2 Codestyle
minecraft-launcher-lib uses PEP8 as it’s codestyle with the following additional rules:
• Lines longer than 80 chars are allowed. We are not in the 90s anymore. Any modern screen can display way
more than 80 chars per line without scrolling.
• All functions must have type annotations
• All functions must have docstrings
minecraft-launcher-lib uses flake8 along with the flake8-annotation, the flake8-docstring-checker plugin, and the flake8-
assert-finder plugin to do a automatic style check. To get started, install it:
To run it, open a command line in the root directory of minecraft-launcher-lib and run:
flake8
If it prints nothing, everything is OK. If it prints something, you should fix it.
65
minecraft-launcher-lib, Release 6.4
To run the tests, open a command line in the root directory of minecraft-launcher-lib and execute:
pytest
To see a detailed test coverage report (which lines are executed during the tests), open htmlcov/index.html with
your browser.
To get started, install mypy together with requests and the types for requests:
To run mypy open a command line in the root directory of minecraft-launcher-lib and execute:
mypy minecraft_launcher_lib
minecraft-launcher-lib uses Sphinx for it’s documentation. The documentation is hosted on Read the Docs. You can
find the soucre files for the documentation in doc folder.
66 Chapter 9. Develop
minecraft-launcher-lib, Release 6.4
9.5.1 Plugins
9.5.2 Building
First you need to install Sphinx and the Read the Docs theme:
You can also install the plugins, if you want to e.g. test the dark mode.
To build the documentation open a command line in the doc folder and run:
Now you can view the documentation by opening _build/html/index.html in your favourite browser.
9.5.3 Examples
The examples are stored in the examples folder. They are added to the documentation during build. Please do not edit
anything inside doc/examples. All files in this folder are overwritten during the build.
minecraft-launcher-lib uses Codeberg as development platform. If you want to contribute some changes, a need to
make a Pull Request (PR) against the Codeberg repo of minecraft-launcher-lib. A merge request is the same as a Pull
Request on GitHub, which I think you should familiar with. It’s works exactly the same way.
Before making a MR, you should follow this checklist:
• minecraft-launcher-lib currently targets version 3.8 of Python and the latest version of PyPy. Make sure, you
don’t use features that were added in a newer Python version.
• Your code should work on Linux, Mac and Windows
• Please make sure, you follow the Codestyle
• If possible, you should not break existing code that uses minecraft-launcher-lib
• If you can write a test, for your changes, you should do it
68 Chapter 9. Develop
CHAPTER
TEN
SHOWCASE
Here is a List of programs that uses minecraft-launcher-lib. If you want to add yours, feel free to make a PR on
Codeberg.
• jdMinecraftLauncher
• minecraft-launcher-cmd
69
minecraft-launcher-lib, Release 6.4
ELEVEN
CHANGELOG
11.1 6.4
11.2 6.3
• Fixed #92
• Fixed #93
11.3 6.2
11.4 6.1
11.5 6.0
71
minecraft-launcher-lib, Release 6.4
11.6 5.3
11.7 5.2
11.8 5.1
11.9 5.0
11.10 4.6
• Add is_vanilla_version()
• Install version that is inherited from
• Fix command for 1.19-pre1
• Fix type annotations
• Cache requests
• Rewrite Maven parsing
11.11 4.5
11.12 4.4
11.13 4.3
• Add get_executable_path()
• Fix using Java Runtime on Windows
11.14 4.2
11.15 4.1
• Add get_minecraft_news()
• Replace deprecated distutils.spawn.find_executable() with shutil.which()
• Add support for using a custom Java runtime in different functions (BobDotCom)
• Fix Forge for 1.12.2
• Fix find_forge_version() (BobDotCom)
• Packages can now be built without requests being installed (BobDotCom)
• Fix finding Java runtime on Mac (BobDotCom)
11.10. 4.6 73
minecraft-launcher-lib, Release 6.4
11.16 4.0
11.17 3.6
11.18 3.5
11.19 3.4
11.20 3.3
• Add is_forge_version_valid()
• Add supports_automatic_install()
• Add UnsupportedVersion exception
• Add ExternalProgramError exception
• Add callbacks to install_fabric()
• Make install_forge_version() raise VersionNotFound exception
• Fix install_fabric()
• Better codestyle
11.21 3.2
11.22 3.1
11.23 3.0
11.24 2.1
11.25 2.0
11.26 1.4
11.21. 3.2 75
minecraft-launcher-lib, Release 6.4
11.27 1.3
11.28 1.2
• Fix Typo
11.29 1.1
11.30 1.0
11.31 0.5
11.32 0.4
11.33 0.3
11.34 0.2
11.35 0.1
• First Release
11.34. 0.2 77
minecraft-launcher-lib, Release 6.4
TWELVE
HISTORY
I like the Design of the old Minecraft Launcher (2013-2016), but I don’t like the Design of the new one which was
released in 2016, so I kept using the old one. I was aware that the old Launcher is not going to be supported forever.
There are many 3rd party launcher out there so I thought: Why not writing my own Launcher that has the same GUI
as the old Launcher? So I started developing a Launcher in Python using QtWidgets from PyQt5. I chose Python,
because it’s an easy to use language. QtWidgets also allows me to write a classical styles user interface and is cross
platform as a Bonus. I finished the GUI soon. Everything except the launching was working. I looked how t do that,
but is was complicated and I run into a few problems, so I was looking for a library to do that or working Python code
that supports all edge cases. I haven’t found anything that was useable, so I decided to use mclauncher-api, which is a
Java library. I wrote a small wrapper program in Java that uses the lib and was called by my Launcher. I released it and
called it jdMinecraftLauncher, so it can also used by other who like the good old design.
I knew, this was not a good solution so I kept working on a Python code that can launch and install Minecraft. I was
able to archive this and install and launch the latest version at this time. I tried to use the code with older versions, but
I realized that the Way how to launch Minecraft changed a bit over time. I also got this part working. I remembered,
how hard it was for me to do this, so I decided to move all the functions that could also be used by others out of
jdMinecraftLauncher into a library. I am not very creative when it comes to names, so I just called the library minecraft-
launcher-lib, because it’s a library for Minecraft launchers. minecraft-launcher-lib was primarily made to meet the needs
of jdMinecraftLauncher, but I designed to library in a Way that it could be used by anyone out there and with any GUI
toolkit.
Version 0.1 was published on 2019-11-18 on GitLab together with a very minimalistic documentation and uploaded to
PyPI.
I kept working on it and added support for more and more Versions. I also tested the library more, as it was now
integreated in jdMinecraftLauncher. Version 1.0, which finally official supports all existing Versions was released on
2020-05-16.
After that, I added functions for automatically installing Forge, which was a lot of reverse engineering, and Farbric,
which is just downloading and executing the Installer. I also improved the Documentation and added tests using Pytest.
A big change came with the introduction of Microsoft Accounts. WIth old Mojang Accounts you just needed a User-
name and Password to log in. Now you need to create a Azure App before you can get started. The login also needs to
be done in a Web browser. This causes a lot of Problems.
It’s gotten even worse: Since 2023 you need to apply to get the Permission to use the Minecraft API. this makes it way
harder for people who want to try out this library.
Another big change happened in 2023: GitLab announces that inactive Repos will be deleted after one Year. This was
reversed later, but I felt like GitLab, which I was using since Microsoft bought GitHub, is no longer a good and safe
place for my Projects. So I looked for another Code hosting service and found Codeberg, which is non profit hosting
service for OpenSource Projects. After GitLab was blocking the CI for new Users, I decided that it was time to ditch
GitLab and moved the Repo to Codeberg.
79
minecraft-launcher-lib, Release 6.4
m
minecraft_launcher_lib.command, 15
minecraft_launcher_lib.exceptions, 32
minecraft_launcher_lib.fabric, 26
minecraft_launcher_lib.forge, 24
minecraft_launcher_lib.install, 16
minecraft_launcher_lib.java_utils, 23
minecraft_launcher_lib.microsoft_account, 17
minecraft_launcher_lib.microsoft_types, 39
minecraft_launcher_lib.mrpack, 31
minecraft_launcher_lib.natives, 17
minecraft_launcher_lib.quilt, 27
minecraft_launcher_lib.runtime, 28
minecraft_launcher_lib.types, 35
minecraft_launcher_lib.utils, 21
minecraft_launcher_lib.vanilla_launcher, 30
81
minecraft-launcher-lib, Release 6.4
83
minecraft-launcher-lib, Release 6.4
84 Index
minecraft-launcher-lib, Release 6.4
Index 85
minecraft-launcher-lib, Release 6.4
86 Index
minecraft-launcher-lib, Release 6.4
U
UnsupportedVersion, 32
url (InvalidChecksum attribute), 34
url_contains_auth_code() (in module
minecraft_launcher_lib.microsoft_account), 18
username (MinecraftAuthenticateResponse attribute), 40
username (MinecraftOptions attribute), 35
uuid (MinecraftOptions attribute), 35
V
vanilla_launcher_profile_to_minecraft_options()
(in module minecraft_launcher_lib.vanilla_launcher),
30
VanillaLauncherProfile (class in
minecraft_launcher_lib.types), 38
VanillaLauncherProfileResolution (class in
minecraft_launcher_lib.types), 38
version (FabricLoader attribute), 37
version (FabricMinecraftVersion attribute), 36
version (JavaInformation attribute), 38
version (QuiltLoader attribute), 37
version (QuiltMinecraftVersion attribute), 37
version (UnsupportedVersion attribute), 33
version (VanillaLauncherProfile attribute), 38
version (VersionNotFound attribute), 32
versionId (MrpackInformation attribute), 39
VersionNotFound, 32
VersionRuntimeInformation (class in
minecraft_launcher_lib.types), 39
versionType (VanillaLauncherProfile attribute), 38
videoId (Image attribute), 37
videoProvider (Image attribute), 37
videoType (Image attribute), 37
videoURL (Image attribute), 37
W
width (VanillaLauncherProfileResolution attribute), 38
Index 87