Client reference¶
- class topstats.client.Client(token: str, *, session: ClientSession | None = None)¶
Interact with the API’s endpoints.
- Parameters:
token (
str) – The API token to use. To retrieve it, see https://docs.topstats.gg/authentication/tokens/.session (
ClientSession|None) – Whether to use an existingClientSessionfor requesting or not. Defaults toNone(creates a new one instead)
- Raises:
TypeError – The specified token is not a string.
ValueError – The specified token is empty.
- async close() None¶
Closes the
Clientobject. Nothing will happen if the client uses a pre-existingClientSessionor if the session is already closed.
- async compare_bot_monthly_votes(period: Period | int | None, *ids: int) Iterable[tuple[Timestamped, ...]]¶
Fetches and yields several Discord bots’ historical monthly vote count for a certain period of time.
- Parameters:
- Raises:
IndexError – The amount of IDs provided are not within range.
Error – The client is already closed.
RequestError – One of the specified bots do not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of monthly vote counts to compare.
- Return type:
Iterable[tuple[
Timestamped, …]]
- async compare_bot_review_count(period: Period | int | None, *ids: int) Iterable[tuple[Timestamped, ...]]¶
Fetches and yields several Discord bots’ historical review count for a certain period of time.
- Parameters:
- Raises:
IndexError – The amount of IDs provided are not within range.
Error – The client is already closed.
RequestError – One of the specified bots do not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of review counts to compare.
- Return type:
Iterable[tuple[
Timestamped, …]]
- async compare_bot_server_count(period: Period | int | None, *ids: int) Iterable[tuple[Timestamped, ...]]¶
Fetches and yields several Discord bots’ historical server count for a certain period of time.
- Parameters:
- Raises:
IndexError – The amount of IDs provided are not within range.
Error – The client is already closed.
RequestError – One of the specified bots do not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of server counts to compare.
- Return type:
Iterable[tuple[
Timestamped, …]]
- async compare_bot_total_votes(period: Period | int | None, *ids: int) Iterable[tuple[Timestamped, ...]]¶
Fetches and yields several Discord bots’ historical total vote count for a certain period of time.
- Parameters:
- Raises:
IndexError – The amount of IDs provided are not within range.
Error – The client is already closed.
RequestError – One of the specified bots do not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of total vote counts to compare.
- Return type:
Iterable[tuple[
Timestamped, …]]
- async compare_bots(*ids: int) Iterable[Bot]¶
Fetches and yields several Discord bots from a set of IDs.
- Parameters:
ids (
int) – Set of bot IDs to compare. The API currently only accepts 2 to 4 IDs.- Raises:
IndexError – The amount of IDs provided are not within range.
Error – The client is already closed.
RequestError – One of the specified bots do not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of bots to compare.
- Return type:
Iterable[
Bot]
- async get_bot(id: int) Bot¶
Fetches a Discord bot from its ID.
- Parameters:
id (
int) – The requested bot’s ID.- Raises:
Error – The client is already closed.
RequestError – The specified bot does not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested bot.
- Return type:
- async get_historical_bot_monthly_votes(id: int, period: Period | None = None) Iterable[Timestamped]¶
Fetches and yields a Discord bot’s historical monthly vote count for a certain period of time.
- Parameters:
id (
int) – The requested bot’s ID.period (
Period|None) – The requested time period. Defaults toPeriod.ALL_TIME.
- Raises:
Error – The client is already closed.
RequestError – The specified bot does not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of this bot’s monthly vote counts.
- Return type:
Iterable[
Timestamped]
- async get_historical_bot_review_count(id: int, period: Period | None = None) Iterable[Timestamped]¶
Fetches and yields a Discord bot’s historical review count for a certain period of time.
- Parameters:
id (
int) – The requested bot’s ID.period (
Period|None) – The requested time period. Defaults toPeriod.ALL_TIME.
- Raises:
Error – The client is already closed.
RequestError – The specified bot does not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of this bot’s review counts.
- Return type:
Iterable[
Timestamped]
- async get_historical_bot_server_count(id: int, period: Period | None = None) Iterable[Timestamped]¶
Fetches and yields a Discord bot’s historical server count for a certain period of time.
- Parameters:
id (
int) – The requested bot’s ID.period (
Period|None) – The requested time period. Defaults toPeriod.ALL_TIME.
- Raises:
Error – The client is already closed.
RequestError – The specified bot does not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of this bot’s server counts.
- Return type:
Iterable[
Timestamped]
- async get_historical_bot_total_votes(id: int, period: Period | None = None) Iterable[Timestamped]¶
Fetches and yields a Discord bot’s historical total vote count for a certain period of time.
- Parameters:
id (
int) – The requested bot’s ID.period (
Period|None) – The requested time period. Defaults toPeriod.ALL_TIME.
- Raises:
Error – The client is already closed.
RequestError – The specified bot does not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of this bot’s total vote counts.
- Return type:
Iterable[
Timestamped]
- async get_recent_bot_stats(id: int) RecentBotStats¶
Fetches recent stats of a Discord bot for the past 30 hours and past month.
- Parameters:
id (
int) – The requested bot’s ID.- Raises:
Error – The client is already closed.
RequestError – The client received a non-favorable response from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested recent bot stats for the past 30 hours and past month.
- Return type:
- async get_top_bots(sort_by: SortBy, *, limit: int | None = None) Iterable[PartialBot]¶
Fetches and yields top Discord bots based on a certain criteria.
- Parameters:
- Raises:
TypeError – The requested sorting criteria’s type is invalid.
Error – The client is already closed.
RequestError – The client received a non-favorable response from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of top bots based on the requested criteria.
- Return type:
Iterable[
PartialBot]
- async get_users_bot(id: int) Iterable[Bot]¶
Fetches a Discord user’s Discord bots from their ID.
- Warning:
Data returned by this method may be inaccurate! This is because bots moved to a team will remain on a user’s account irrespective of ownership.
- Parameters:
id (
int) – The requested user’s ID.- Raises:
Error – The client is already closed.
RequestError – The specified user has not logged in to Top.gg or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of bots made by this user.
- Return type:
Iterable[
Bot]
- async search_bots(*, name: str | None = None, tag: str | None = None, offset: int | None = None, limit: int | None = None, include_deleted: bool = False) Iterable[Bot]¶
Fetches and yields several Discord bots from their name or tag.
- Parameters:
name (
str|None) – The requested bot name. IfNone, defaults to the tag parameter.tag (
str|None) – The requested bot tag. IfNone, defaults to the name parameter.limit (
int|None) – The maximum amount of bots to be queried. Defaults to50or100depending on the parameter. This can’t exceed the default value.include_deleted (
bool) – Whether to include deleted bots or not. Defaults toFalse.
- Raises:
Error – The client is already closed or both the name and tag parameters are unspecified.
RequestError – The specified bot does not exist or the client has received other non-favorable responses from the API.
Ratelimited – Ratelimited from sending more requests.
- Returns:
The requested list of bots that matches the specified query.
- Return type:
Iterable[
Bot]
- class topstats.data.Period¶
The requested time period for fetching historical bot stats.
- ALL_TIME = 'alltime'¶
- LAST_12_HOURS = '12h'¶
- LAST_3_DAYS = '3d'¶
- LAST_3_MONTHS = '90d'¶
- LAST_3_YEARS = '3y'¶
- LAST_5_YEARS = '5y'¶
- LAST_6_HOURS = '6h'¶
- LAST_6_MONTHS = '180d'¶
- LAST_9_MONTHS = '270d'¶
- LAST_DAY = '1d'¶
- LAST_MONTH = '30d'¶
- LAST_WEEK = '7d'¶
- LAST_YEAR = '1y'¶
- class topstats.data.SortBy¶
The requested sorting method for sorting Discord bots.
- static monthly_votes(*, ascending: bool = False) SortBy¶
Sorts Discord bots by their monthly vote count.
- Parameters:
ascending (
bool) – Whether to sort by ascending or not. Defaults to sort by descending.
- static review_count(*, ascending: bool = False) SortBy¶
Sorts Discord bots by their review count.
- Parameters:
ascending (
bool) – Whether to sort by ascending or not. Defaults to sort by descending.