Player¶
Class representing a Minecraft player. This class is used to fetch and store player data from the Mojang API.
Note
This class needs an active network connection.
Basic Usage¶
from minepi import Player
p = Player(name="sucr_kolli") # get player by name
await p.initialize() # fetch all data
API Reference¶
- class Player(uuid: str | None = None, name: str | None = None, raw_skin: Image | None = None, raw_cape: Image | None = None, session: ClientSession | None = None)¶
Class representing a minecraft player This has to be created before a skin can be rendered
- Parameters:
uuid (str) – UUID of the player (Not needed if name is given
name (str) – Username of the player (Not needed if UUID is given)
raw_skin (PIL.Image.Image) – Raw skin image of the player (64x64px)
raw_cape (PIL.Image.Image) – Raw cape image of the player (64x32px)
session (aiohttp.ClientSession) – ClientSession to use for requests
Attributes:
The players UUID
The players name
The players
SkinA dict representing this player's capes
The player's mojang cape
The player's optifine cape
The player's labymod cape
The player's MinecraftCapes cape
The player's 5Zig cape
The player's TLauncher cape
Methods:
Manually overwrite/set this players skin
Initializes the player class
Returns as soon as the initialize function finished
Fetches the players optifine cape and stores it to
Player.optifine_capeFetches the players labymod cape and stores it to
Player.labymod_capeFetches the players MinecraftCapes cape and stores it to
Player.minecraftcapes_capeFetches the players 5Zig cape and stores it to
Player.zig_capeFetches the players TLauncher cape and stores it to
Player.tlauncher_cape- property uuid¶
The players UUID
Either passed when creating this class or fetched from the MojangAPI
- property name¶
The players name
- property capes¶
A dict representing this player’s capes
- property mojang_cape¶
The player’s mojang cape
- property optifine_cape¶
The player’s optifine cape
- property labymod_cape¶
The player’s labymod cape
- property minecraftcapes_cape¶
The player’s MinecraftCapes cape
- property zig_cape¶
The player’s 5Zig cape
- property tlauncher_cape¶
The player’s TLauncher cape
- set_skin(skin: Skin)¶
Manually overwrite/set this players skin
- Parameters:
skin (Skin) – The new skin
- async initialize()¶
Initializes the player class
This function is an initializer which helps to get various details about the player with just one method. Once this function has finished running, the corresponding
Playerobject is guaranteed to have a name, UUID and skin (includes the cape if available) associated to it (if the given username and/or UUID is valid of course).Warning
- This function does one to four API calls to the mojang API:
-> (1.) Obtain the players UUID by name (Only if no UUID is given)
-> 2. Get the players profile
-> (3.) Get the players skin (Only if no skin is given)
-> (4.) Get the players cape (Only if the player actually has a cape)
Rate limits of the API are unknown but expected to be somewhere close to 6000 requests per 10 minutes.
- Raises:
errors.InvalidPlayer – Player does not seem to be valid
- async wait_for_fully_constructed()¶
Returns as soon as the initialize function finished
Waiting for this guarantees that the skin has been fetched from the api
- async fetch_optifine_cape()¶
Fetches the players optifine cape and stores it to
Player.optifine_capeThis is basically just an alias for
utils.fetch_optifine_cape()
- async fetch_labymod_cape()¶
Fetches the players labymod cape and stores it to
Player.labymod_capeThis is basically just an alias for
utils.fetch_labymod_cape()
- async fetch_minecraftcapes_cape()¶
Fetches the players MinecraftCapes cape and stores it to
Player.minecraftcapes_capeThis is basically just an alias for
utils.fetch_minecraftcapes_cape()
- async fetch_5zig_cape()¶
Fetches the players 5Zig cape and stores it to
Player.zig_capeThis is basically just an alias for
utils.fetch_5zig_cape()
- async fetch_tlauncher_cape()¶
Fetches the players TLauncher cape and stores it to
Player.tlauncher_capeThis is basically just an alias for
utils.fetch_tlauncher_cape()
Skin¶
Class representing a Minecraft skin
Note
Everything in this class works completely offline, even the render itself.
Basic Usage¶
from minepi import Skin
from PIL import Image
raw_skin = Image.open(path_to_skin)
raw_cape = Image.open(path_to_cape) # Optional
s = Skin(raw_skin=raw_skin, raw_cape=raw_cape)
await s.render_skin()
s.skin.show()
API Reference¶
- class Skin(raw_skin, raw_cape=None, raw_skin_url=None, raw_cape_url=None, name=None)¶
Tip
It’s best practice to save the players skin to a database using
encodeb64()and then reinitialize this class usingdecodeb64(). This way no API call is needed.Alternatively you can manually instantiate by passing a raw skin image.
- Parameters:
raw_skin (PIL.Image.Image) – The raw skin image
raw_cape (PIL.Image.Image) – The raw cape image
Attributes:
The last skin which has been rendered using
render_skin()The last head which has been rendered using
render_head()The players raw skin image
The players skins url.
The players raw cape image
The players capes url.
Whether the player has a cape
Whether the skin is slim (Alex type) or classic (Steve type)
Methods:
Change the players cape
Shows the last rendered skin
Base64 encodes the players skin and cape
Create an instance of this class from a saved b64 string
Render a full body skin
Render the players head
- property skin¶
The last skin which has been rendered using
render_skin()
- property head¶
The last head which has been rendered using
render_head()
- property raw_skin¶
The players raw skin image
- property raw_skin_url¶
The players skins url. Returns None if the skin has been manually passed
- property raw_cape¶
The players raw cape image
- property raw_cape_url¶
The players capes url. Returns None if the player doesn’t have a cape or the cape has been manually passed
- property has_cape¶
Whether the player has a cape
- property is_slim¶
Whether the skin is slim (Alex type) or classic (Steve type)
Only difference being the width of the arms (3px - 4px)
- set_cape(cape: Image)¶
Change the players cape
- Parameters:
cape (PIL.Image.Image) – The new cape image (64x32px)
- show()¶
Shows the last rendered skin
Alias for
Skin.skin.show()- Raises:
NoRenderedSkin – No skin present. Generate a render using
render_skin()
- encodeb64()¶
Base64 encodes the players skin and cape
This allows for better caching and persistent storage in a database A
Skinclass can then be recreated usingdecodeb64()- Returns:
The players skin and cape in format {raw_skin}-{raw_cape}
- Return type:
- classmethod decodeb64(b64: str)¶
Create an instance of this class from a saved b64 string
- Parameters:
b64 (str) – The base64 encoded raw_skin image or raw_skin and raw_cape separated with a “;”. Can be obtained from
encodeb64()- Return type:
- async render_skin(vr: int = 25, hr: int = 35, hrh: int = 0, vrll: int = 0, vrrl: int = 0, vrla: int = 0, vrra: int = 0, vrc: int = 30, ratio: int = 12, display_hair: bool = True, display_second_layer: bool = True, display_cape: bool = True, aa: bool = False) Image | None¶
Render a full body skin
- Parameters:
vr (int) – Vertical rotation of the output image
hr (int) – Horizontal rotation of the output image
hrh (int) – Horizontal head rotation
vrll (int) – Vertical rotation of the left leg
vrrl (int) – Vertical rotation of the right leg
vrla (int) – Vertical rotation of the left arm
vrra (int) – Vertical rotation of the right arm
vrc (int) – Vertical rotation of the cape Not actually in degrees, use random values please until you find one you like
ratio (int) – Resolution of the returned image
display_hair (bool) – Whether the second head layer is displayed
display_second_layer (bool) – Whether the second skin layer is displayed
display_cape (bool) – Whether the player’s cape is shown
aa (bool) – Antialiasing: smoothens the corners a bit
- Returns:
The rendered skin
- Return type:
Utils¶
API Reference¶
Functions:
Converts a not dashed UUID to a dashed one |
|
Converts a dashed UUID to a not dashed one |
|
Convert a minecraft name to a UUID |
|
Convert a UUID to a minecraft name |
|
Fetch a players skin |
|
Fetch a players optifine cape |
|
Fetch a players labymod cape |
|
Fetch a players 5Zig cape |
|
Fetch a players MinecraftCapes cape |
|
Fetch a players TLauncher cape |
|
Useful helper function to get multiple |
- async name_to_uuid(name: str, session: ClientSession | None = None) str | None¶
Convert a minecraft name to a UUID
- Parameters:
name (str) – The minecraft name to get the UUID for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given name is invalid
- Return type:
Optional[str]
- async uuid_to_name(uuid: str, session: ClientSession | None = None) str | None¶
Convert a UUID to a minecraft name
- Parameters:
uuid (str) – The UUID to get the minecraft name for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given UUID is invalid
- Return type:
Optional[str]
- async fetch_skin(player: Player = None, name: str = None, uuid: str = None, session: ClientSession = None) Skin | None¶
Fetch a players skin
Note
This function also returns the players mojang cape (if available).
Tip
Passing a
minepi.Playeris recommended. If none is available, a name or UUID can be passed. UUIDs are preferred over names in this case since they require one API call less.- Parameters:
player (Player) – The player to fetch the skin for
name (str) – Minecraft username to fetch the skin for
uuid (str) – UUID to fetch the skin for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
A fully functional
minepi.Skinclass- Return type:
- Raises:
ValueError – No
minepi.Player, name or UUID has been passed
- async fetch_optifine_cape(player: Player = None, name: str = None, uuid: str = None, session: ClientSession = None) Image | None¶
Fetch a players optifine cape
Tip
Passing a
minepi.Playerobject is recommended. If none is available, a name or UUID can be passed. Names are preferred over UUIDs in this case since they require one API call less.- Parameters:
player (Player) – The player to fetch the optifine cape for
name (str) – Minecraft username to fetch the optifine cape for
uuid (str) – UUID to fetch the optifine cape for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given player has no optifine cape
- Return type:
Optional[PIL.Image.Image]
- Raises:
ValueError – No
minepi.Player, name or UUID has been passed
- async fetch_labymod_cape(player: Player = None, name: str = None, uuid: str = None, session: ClientSession = None) Image | None¶
Fetch a players labymod cape
Tip
Passing a
minepi.Playerobject is recommended. If none is available, a name or UUID can be passed. UUIDs are preferred over names in this case since they require one API call less.- Parameters:
player (Player) – The player to fetch the labymod cape for
name (str) – Minecraft username to fetch the labymod cape for
uuid (str) – UUID to fetch the labymod cape for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given player has no labymod cape
- Return type:
Optional[PIL.Image.Image]
- Raises:
ValueError – No
minepi.Player, name or UUID has been passed
- async fetch_5zig_cape(player: Player = None, name: str = None, uuid: str = None, session: ClientSession = None) Image | None¶
Fetch a players 5Zig cape
Tip
Passing a
minepi.Playerobject is recommended. If none is available, a name or UUID can be passed. UUIDs are preferred over names in this case since they require one API call less.Warning
5zig capes are not guaranteed to work yet. If you own an account with 5zigreborn cape, it would be very helpful if you could send us the username.
- Parameters:
player (Player) – The player to fetch the 5Zig cape for
name (str) – Minecraft username to fetch the 5Zig cape for
uuid (str) – UUID to fetch the 5Zig cape for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given player has no 5Zig cape
- Return type:
Optional[PIL.Image.Image]
- Raises:
ValueError – No
minepi.Player, name or UUID has been passed
- async fetch_minecraftcapes_cape(player: Player = None, name: str = None, uuid: str = None, session: ClientSession = None) Image | None¶
Fetch a players MinecraftCapes cape
Tip
Passing a
minepi.Playerobject is recommended. If none is available, a name or UUID can be passed. UUIDs are preferred over names in this case since they require one API call less.Warning
Animated MinecraftCapes capes are not supported yet
- Parameters:
player (Player) – The player to fetch the MinecraftCapes cape for
name (str) – Minecraft username to fetch the MinecraftCapes cape for
uuid (str) – UUID to fetch the MinecraftCapes cape for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given player has no MinecraftCapes cape
- Return type:
Optional[PIL.Image.Image]
- Raises:
ValueError – No
minepi.Player, name or UUID has been passed
- async fetch_tlauncher_cape(player: Player = None, name: str = None, uuid: str = None, session: ClientSession = None) Image | None¶
Fetch a players TLauncher cape
Tip
Passing a
minepi.Playerobject is recommended. If none is available, a name or UUID can be passed. Names are preferred over UUIDs in this case since they require one API call less.Warning
TLauncher capes are still experimental and not guaranteed to work. If you want to help implement them further, please get in touch with me. If you could share a few account names with TLauncher capes (especially animated ones), that would help us a lot.
- Parameters:
player (Player) – The player to fetch the TLauncher cape for
name (str) – Minecraft username to fetch the TLauncher cape for
uuid (str) – UUID to fetch the TLauncher cape for
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
None if the given player has no TLauncher cape
- Return type:
Optional[PIL.Image.Image]
- Raises:
ValueError – No
minepi.Player, name or UUID has been passed
- async get_players_by_name(names: list, session: ClientSession | None = None)¶
Useful helper function to get multiple
minepi.PlayerobjectsOnly does one API call for the entire list instead of one per player This is recommended to be used if you have a list of usernames
- Parameters:
names (list) – A list of minecraft usernames
session (aiohttp.ClientSession) – The ClientSession to use for requests Defaults to a new session which is closed again after handling all requests
- Returns:
A list of
minepi.Playerobjects- Return type: