Tibia.py

Tibia.py is a libray for parsing HTML content from Tibia.com. into python objects.

This library only performs parsing, to fetch content you need to use external libraries.

import aiohttp
import requests
import tibiapy

# Asynchronously
async def get_character(name):
   url = tibiapy.Character.get_url(name)

   try:
      async with aiohttp.ClientSession() as session:
         async with session.get(url) as resp:
            content = await resp.text()
   character = tibiapy.Character.from_content(content)
   return character

# Synchronously
def get_character_sync(name):
   url = tibiapy.Character.get_url(name)

   r = requests.get(url)
   content = r.text()
   character = tibiapy.Character.from_content(content)
   return character

Indices and tables

Classes

Character

class tibiapy.Character(name=None, world=None, vocation=None, level=0, sex=None, **kwargs)[source]

Represents a Tibia character

name

str – The name of the character.

deletion_date

Optional[datetime.datetime] – The date where the character will be deleted if it is scheduled for deletion.

former_names

List[str] – Previous names of this character.

sex

str – The character’s gender, either “male” or “female”

vocation

str – The character’s vocation.

level

int – The character’s level.

achievement_points

int – The total of points the character has.

world

str – The character’s current world

former_world

Optional[str] – The previous world where the character was in, in the last 6 months.

residence

str – The current hometown of the character.

married_to

Optional[str] – The name of the character’s spouse/husband.

house

Optional[dict] – The house currently owned by the character.

guild_membership

Optional[dict] – The guild the character is a member of. The dictionary contains a key for the rank and a key for the name.

last_login

Optional[datetime.datetime] – The last time the character logged in. It will be None if the character has never logged in.

comment

Optional[str] – The displayed comment.

account_status

str – Whether the character’s account is Premium or Free.

achievements

List[dict] – The achievements chosen to be displayed.

deaths

List[Death] – The character’s recent deaths.

account_information

dict – The character’s account information, if visible.

other_characters

List[OtherCharacter] – Other characters in the same account, if visible.

guild_name

Optional[str] – The name of the guild the character belongs to, or None.

guild_rank

Optional[str] – The character’s rank in the guild they belong to, or None.

static get_url(name)[source]

Gets the Tibia.com URl for a given character name.

Parameters:name (str) – The name of the character
Returns:The URL to the character’s page
Return type:str
static from_content(content) → Optional[tibiapy.character.Character][source]

Creates an instance of the class from the html content of the character’s page.

Parameters:content (str) – The HTML content of the page.
Returns:The character contained in the page, or None if the character doesn’t exist.
Return type:Optional[Character]
static parse_to_json(content, indent=None)[source]

Static method that creates a JSON string from the html content of the character’s page.

Parameters:
  • content (str) – The HTML content of the page.
  • indent (int) – The number of spaces to indent the output with.
Returns:

A string in JSON format.

Return type:

str

url

str – The URL of the character’s information page on Tibia.com

Death

class tibiapy.Death(name=None, level=0, **kwargs)[source]

Represents a death by a character

name

str – The name of the character this death belongs to.

level

int – The level at which the death occurred.

killers

List[Killer] – A list of all the killers involved.

assists

List[Killer] – A list of characters that were involved, without dealing damage.

time

datetime.datetime – The time at which the death occurred.

killer

Optional[Killer] – The first killer in the list.

This is usually the killer that gave the killing blow.

by_player

bool – Whether the kill involves other characters.

Guild

class tibiapy.Guild(name=None, world=None, **kwargs)[source]

Represents a Tibia guild.

name

str – The name of the guild. Names are case sensitive.

logo_url

str – The URL to the guild’s logo.

description

Optional[str] – The description of the guild.

world

str – The world where this guild is in.

founded

datetime.date – The day the guild was founded.

active

bool – Whether the guild is active or still in formation.

guildhall

Optional[dict] – The guild’s guildhall.

open_applications

bool – Whether applications are open or not.

disband_condition

Optional[str] – The reason why the guild will get disbanded.

disband_date

Optional[str] – The date when the guild will be disbanded if the condition hasn’t been meet.

homepage

str – The guild’s homepage

members

List[GuildMember] – List of guild members.

invites

List[GuildInvite] – List of invited characters.

member_count

int – The number of members in the guild.

online_members

List[GuildMember] – List of currently online members.

ranks

List[str] – Ranks in their hierarchical order.

url

str – The URL to the guild’s information page.

static list_from_content(content, active_only=False)[source]

Gets a list of guilds from the html content of the world guilds’ page.

The Guild objects in the list only contain the attributes: name, logo_url, world and if available, description

Parameters:
  • content (str) – The html content of the page.
  • active_only (bool) – Whether to only show active guilds or not.
Returns:

List of guilds in the current world.

Return type:

List[Guild]

static from_content(content) → Optional[tibiapy.guild.Guild][source]

Creates an instance of the class from the html content of the guild’s page.

Parameters:content (str) – The HTML content of the page.
Returns:The guild contained in the page or None if it doesn’t exist.
Return type:Optional[Guild]
static get_url(name)[source]

Gets the Tibia.com URL for a given guild name.

Parameters:name (str) – The name of the guild
Returns:The URL to the guild’s page
Return type:str
static get_world_list_url(world)[source]

Gets the Tibia.com URL for the guild section of a specific world.

Parameters:world (str) – The name of the world
Returns:The URL to the guild’s page
Return type:str
static json_list_from_content(content, active_only=False, indent=None)[source]

Creates a JSON string from the html content of the world guilds’ page.

Parameters:
  • content (str) – The html content of the page.
  • active_only (bool) – Whether to only show active guilds or not.
  • indent (int) – The number of spaces to indent the output with.
Returns:

A string in JSON format.

Return type:

str

static parse_to_json(content, indent=None)[source]

Creates a JSON string from the html content of the guild’s page.

Parameters:
  • content (str) – The HTML content of the page.
  • indent (int) – The number of spaces to indent the output with.
Returns:

A string in JSON format.

Return type:

str

Auxiliary Classes

Guild Invite

class tibiapy.GuildInvite(name=None, date=None)[source]

Represents an invited character

name

str – The name of the character

date

datetime.date – The day when the character was invited.

url

str – The URL of the character’s information page on Tibia.com

Guild Member

class tibiapy.GuildMember(name=None, rank=None, title=None, level=0, vocation=None, joined=None, online=False)[source]

Represents a guild member.

rank

str – The rank the member belongs to

name

str – The name of the guild member.

title

Optional[str] – The member’s title.

level

int – The member’s level.

vocation

str – The member’s vocation.

joined

datetime.date – The day the member joined the guild.

online

bool – Whether the member is online or not.

url

str – The URL of the character’s information page on Tibia.com

Killer

class tibiapy.Killer(name=None, player=False, summon=None)[source]

Represents a killer.

A killer can be:

  1. Another character.
  2. A creature.
  3. A creature summoned by a character.
name

str – The name of the killer.

player

bool – Whether the killer is a player or not.

summon

Optional[str] – The name of the summoned creature, if applicable.

url

Optional[str] – The URL of the character’s information page on Tibia.com, if applicable.

Other Character

class tibiapy.OtherCharacter(name=None, world=None, online=False, deleted=False)[source]

Represents other character’s displayed in the Character’s information page.

name

str – The name of the character.

world

str – The name of the world.

online

bool – Whether the character is online or not.

deleted

bool – Whether the character is scheduled for deletion or not.

url

str – The URL of the character’s information page on Tibia.com

Utility functions

tibiapy.utils.parse_tibia_datetime(datetime_str)[source]

Parses date and time from the format used in Tibia.com

Parameters:datetime_str (str) – The date and time as represented in Tibia.com
Returns:The represented datetime, in UTC.
Return type:datetime.datetime
tibiapy.utils.parse_tibia_date(date_str)[source]

Parses a date from the format used in Tibia.com

Parameters:date_str (str) – The date as represented in Tibia.com
Returns:The represended date.
Return type:datetime.date

Exceptions

exception tibiapy.TibiapyException[source]

Base exception for the tibiapy module.

All exceptions thrown by the module are inherited from this.

exception tibiapy.InvalidContent[source]

Exception thrown when the parsing couldn’t be completed due to invalid content supplied.

This usually means that the content provided belongs to a different website or section.

In some cases this can mean that Tibia.com’s format has changed and the library needs updating.