Code Monkey home page Code Monkey logo

mojang's Introduction

PyPI version PyPI - Python Version

Read the Docs MIT License PyPI - Monthly Downloads

Documentation

Mojang is a Python package for accessing Mojang's services. This library can be used to convert UUIDs, get a profile's information, change your Minecraft username or skin, and much more.

There are 2 components to this package, which are imported in different ways:

  • Public API - Used to parse information about Minecraft profiles and more. Authentication is not required.
  • Client API - Used to login to a Mojang account and access it.

At the moment, the Client API only supports authenticating to a Minecraft account via Microsoft's authentication scheme, so your Minecraft account must already be migrated. Alternatively, you may authenticate to a Mojang account directly with a Bearer token.

Installation

Python 3.7 or higher is required.

The easiest way to install the library is using pip. Just run the following console command:

python -m pip install mojang

Public API Quickstart

from mojang import API

# Create a Public API instance
api = API()

uuid = api.get_uuid("Notch")

if not uuid:
    print("Notch is not a taken username.")
else:
    print(f"Notch's UUID is {uuid}")

    profile = api.get_profile(uuid)
    print(f"Notch's skin URL is {profile.skin_url}")
    print(f"Notch's skin variant is {profile.skin_variant}")
    print(f"Notch's cape URL is {profile.cape_url}")

Client API Quickstart

To log into a Mojang account, the account must already be migrated to Microsoft. This means that you will be using your Microsoft credentials to login.

from mojang import Client

client = Client("YOUR_MICROSOFT_EMAIL", "YOUR_PASSWORD")

# Get the account's profile information
profile = client.get_profile()

print(profile.id)
print(profile.name)

for skin in profile.skins:
    print(skin.id)
    print(skin.enabled)
    print(skin.url)
    print(skin.variant)

Alternatively, supply a Bearer token and skip the Microsoft authentication process.

client = Client(bearer_token="MOJANG_BEARER_TOKEN_HERE")

If authentication fails, such as due to an incorrect email or password, a LoginFailure exception will occur.

mojang's People

Contributors

summer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mojang's Issues

"get_drop_timestamp" always returns ValueError

The get_drop_timestamp() function always returns a ValueError, as it attempts to convert the username to a UUID, however since drop timestamps only work on names that aren't currently set to any profile, this makes it impossible to work.

Example:

drop_timestamp = MojangAPI.get_drop_timestamp(mazurr)
print(drop_timestamp)

Returns:

ValueError: Username is invalid. Failed to convert username to UUID

Hello, can you consult git space

你好,可以咨询下git空间吗,summer可以出让给我吗?微信或者QQ联系

Hello, can you inquire about git space? Can Summer sell it to me? WeChat or QQ contact

Getting Bearer Token

Is there a way to input login: (Email, Password)
and getting it to print the bearer token?

"mojang.errors.NotFound: HTTP 404. This resource does not exist." On login with bearer token

When trying to login with a bearer token, It throws a 404 not found error.
This is my code, i am trying to use 2 accounts:

        try:
            client1 = Client("EMAIL", "PASS")
        except errors.LoginFailure:
            QtWidgets.QMessageBox.about(self, "Error", "Invalid main account")
            return

        try:
            client2 = Client(bearer_token = "TOKEN")
        
        except errors.LoginFailure:
            QtWidgets.QMessageBox.about(self, "Error", "Invalid second account")
            return

It should be a valid token. Its 435 characters long and contains a dot.

problem with `get_name_history`

  name_data_dict["name"] = data["name"]
TypeError: string indices must be integers

getting this error anytime i call the MojangAPI.get_name_history(uuid)

json.decoder.JSONDecodeError when querying a uuid that isnt a player

When you query a profile:

profile = MojangAPI.get_profile("20e21989-5521-49df-9750-a4ef8bd5441b")

, expected output is None if the profile doesn't exist or UserProfile if it does, however, if you put a valid UUID, but one that isn't a player, the method throws json.decoder.JSONDecodeError

profile = MojangAPI.get_profile("20e21989-5521-49df-9750-a4ef8bd5441a") # This will error out!

Grrr

It's me dancers, you should add my new account. (I got terminated 😢)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.