API Reference#

The following section outlines the API of steam.py’s TF2 extension module.

Client#

class steam.ext.tf2.Client(**options)#
property user: ClientUser#

Represents the connected client. None if not logged in.

property schema: Schema#

TF2’s item schema. None if the user isn’t ready.

property backpack_slots: int#

The client’s number of backpack slots.

is_premium()#

Whether or not the client’s account has TF2 premium. None if the user isn’t ready.

Return type:

bool

set_language(file)#

Set the localization files for your bot.

This isn’t necessary in most situations.

await craft(items, recipe=-2)#

Craft a set of items together with an optional recipe.

Parameters:
Returns:

The crafted items, None if crafting failed.

Return type:

list[BackpackItem[ClientUser]]

async for ... in all_apps(*, limit=None, modified_after=None, include_games=True, include_dlc=True, include_software=True, include_videos=True, include_hardware=True)#

An asynchronous iterator over all the apps on Steam.

Parameters:
  • limit (int | None) – The maximum number of apps to search through. Default is None. Setting this to None will fetch all of the apps, but this will be a very slow operation.

  • modified_after (datetime.datetime | None) – A time to search for apps after.

  • include_games (bool) – Whether to include games.

  • include_dlc (bool) – Whether to include DLC.

  • include_software (bool) – Whether to include software.

  • include_videos (bool) – Whether to include videos.

  • include_hardware (bool) – Whether to include hardware.

Yields:

AppListApp

await anonymous_login()#

Initialize a connection to a Steam CM and login anonymously.

await change_presence(*, app=None, apps=None, state=None, ui_mode=None, flags=None, force_kick=False)#

Set your status.

Parameters:
  • app (App | None) – An app to set your status as.

  • apps (Iterable[App] | None) – A list of apps to set your status to.

  • state (PersonaState | None) –

    The state to show your account as.

    Warning

    Setting your status to Offline, will stop you receiving persona state updates and by extension on_user_update() will stop being dispatched.

  • ui_mode (UIMode | None) – The UI mode to set your status to.

  • flags (PersonaStateFlag | None) – The flags to update your account with.

  • force_kick (bool) – Whether to forcefully kick any other playing sessions.

property clans: Sequence[Clan]#

A read-only list of all the clans the connected client is in.

clear()#

Clears the internal state of the bot. After this, the bot can be considered “re-opened”, i.e. is_closed() and is_ready() both return False. This also clears the internal cache.

await close()#

Close the connection to Steam.

await code()#

Get the current steam guard code.

Warning

This will read from sys.stdin if no shared_secret was passed to login().

Return type:

str

await create_clan(name, /, *, abbreviation=None, community_url=None, public=True, headline=None, summary=None, language=None, country=None, state=None, city=None, apps=None, avatar=None)#

Create a clan.

Parameters:
  • name (str) – The name of the clan.

  • avatar (Media | None) – The avatar of the clan.

  • abbreviation (str | None) – The abbreviation of the clan.

  • community_url (URL_ | str | None) – The community URL of the clan.

  • public (bool) – Whether the clan is public.

  • headline (str | None) – The headline of the clan.

  • summary (str | None) – The summary of the clan.

  • language (Language | None) – The language of the clan.

  • country (str | None) – The country of the clan.

  • state (str | None) – The state of the clan.

  • city (str | None) – The city of the clan.

  • apps (Iterable[App] | None) – The apps the clan is associated with.

Return type:

Clan

await create_group(name, /, *, members, avatar=None, tagline=None)#

Create a group.

Parameters:
  • name (str) – The name of the group.

  • members (Iterable[IndividualID]) – The members to add to the group.

  • avatar (Media | None) – The avatar of the group.

  • tagline (str | None) – The tagline of the group.

Return type:

Group

await create_post(content, /, app=None)#

Create a post.

Parameters:
  • content (str) – The content of the post.

  • app (App | None) – The app to create the post for.

Return type:

Post[ClientUser]

property effects: Sequence[ClientEffect]#

A read-only list of all the effects the client has.

property emoticons: Sequence[ClientEmoticon]#

A read-only list of all the emoticons the client has.

@event(coro)#

A decorator that registers an event to listen to.

The events must be a coroutine, if not, TypeError is raised.

Usage:

@client.event
async def on_ready():
    print("Ready!")
Raises:

TypeError – The function passed is not a coroutine.

Return type:

F

await fetch_app(id, /, *, language=None)#

Fetch an app from its ID.

Parameters:
  • id (int) – The app id of the app.

  • language (Language | None) – The language to fetch the app in. If None uses the current language.

Raises:

ValueError – Passed id isn’t for a valid app.

Return type:

FetchedApp

await fetch_bundle(id, /, *, language=None)#

Fetch a bundle from its ID.

Parameters:
  • id (int) – The ID of the bundle.

  • language (Language | None) – The language to fetch the bundle in. If None uses the current language.

Return type:

FetchedBundle

await fetch_clan(id, /)#

Fetches a clan from the websocket with a matching ID.

Parameters:

id (int) – The ID64 of the clan.

Return type:

Clan

async for ... in fetch_listings(name, app)#

Fetch the listings for an item.

Parameters:
  • name (str) – The name of the item.

  • app (App) – The app the item is from.

Return type:

AsyncGenerator[Listing, None]

await fetch_package(id, /, *, language=None)#

Fetch a package from its ID.

Parameters:
  • id (int) – The ID of the package.

  • language (Language | None) – The language to fetch the package in. If None uses the current language.

Raises:

ValueError – Passed id isn’t for a valid package.

Return type:

FetchedPackage

await fetch_price(name, app, currency=None)#

Fetch the PriceOverview for an item.

Parameters:
  • name (str) – The name of the item.

  • app (App) – The app the item is from.

  • currency (Currency | None) – The currency to fetch the price in.

Return type:

PriceOverview

await fetch_price_history(name, app, currency=None)#

Fetch the price history for an item.

Parameters:
  • name (str) – The name of the item.

  • app (App) – The app the item is from.

  • currency (Currency | None) – The currency to fetch the price in.

Return type:

list[PriceHistory]

await fetch_product_info(*, apps=(), packages=())#

Fetch product info.

Parameters:
  • apps (Collection[App]) – The apps to fetch info on.

  • packages (Collection[Package]) – The packages to fetch info on.

Return type:

list[AppInfo] | list[PackageInfo] | tuple[list[AppInfo], list[PackageInfo]]

await fetch_published_file(id, /, *, revision=PublishedFileRevision.Default, language=None)#

Fetch a published file from its ID.

Parameters:
  • id (int) – The ID of the published file.

  • revision (PublishedFileRevision) – The revision of the published file to fetch.

  • language (Language | None) – The language to fetch the published file in. If None, the current language is used.

Return type:

PublishedFile | None

await fetch_published_files(*ids, revision=PublishedFileRevision.Default, language=None)#

Fetch published files from their IDs.

Parameters:
  • ids (int) – The IDs of the published files.

  • revision (PublishedFileRevision) – The revision of the published files to fetch.

  • language (Language | None) – The language to fetch the published files in. If None, the current language is used.

Return type:

list[PublishedFile | None]

await fetch_server(*, id=None, ip=None, port=None)#

Fetch a GameServer from its ip and port or its Steam ID or None if fetching the server failed.

Parameters:
  • ip (IPAdress | str | None) – The ip of the server.

  • port (int | str | None) – The port of the server.

  • id (int | None) – The ID64 of the game server. If passed, it makes a call to the master server to fetch its ip and port.

Note

Passing an ip, port and id to this function will raise an TypeError.

Return type:

GameServer | None

await fetch_servers(query=None, /, *, limit=100)#

Query game servers.

Parameters:
  • query (str | None) – The query to match servers with. If None returns all servers.

  • limit (int) – The maximum amount of servers to return.

See also

Query.where()

Return type:

list[GameServer]

await fetch_store_item(*, apps=(), packages=(), bundles=(), language=None)#

Fetch store items.

Parameters:
  • apps (Sequence[App]) – The apps to fetch store items for.

  • packages (Sequence[Package]) – The packages to fetch store items for.

  • bundles (Sequence[Bundle]) – The bundles to fetch store items for.

  • language (Language | None) – The language to fetch the store items in. If None, the default language is used.

Return type:

Any

await fetch_trade(id, /, *, language=None)#

Fetches a trade with a matching ID or None if the trade was not found.

Parameters:
  • id (int) – The ID of the trade to search for from the API.

  • language (Language | None) – The language to fetch the trade in. None uses the current language.

Return type:

TradeOffer[Item[User], Item[ClientUser], User] | None

await fetch_user(id, /)#

Fetches a user with a matching ID.

Parameters:

id (int) – The ID64 of the user.

Return type:

User

await fetch_users(*ids)#

Fetches a list of User.

Note

The User objects returned are unlikely to retain the order they were originally in.

Parameters:

ids (int) – The user’s ID64s.

Return type:

Sequence[User]

get_app(id, /)#

Creates a PartialApp instance from its ID.

Parameters:

id (int) – The app id of the app.

Return type:

PartialApp[None]

get_bundle(id, /)#

Creates a PartialBundle instance from its ID.

Parameters:

id (int) – The ID of the bundle.

Return type:

PartialBundle

get_clan(id, /)#

Get a clan from cache with a matching ID or None if the group was not found.

Parameters:

id (int) – The ID64 of the clan.

Return type:

Clan | None

get_group(id, /)#

Get a group from cache with a matching ID or None if the group was not found.

Parameters:

id (int) – The ID64 of the group.

Return type:

Group | None

get_package(id, /)#

Creates a PartialPackage from its ID.

Parameters:

id (int) – The ID of the package.

Return type:

PartialPackage

get_trade(id, /)#

Get a trade from cache with a matching ID or None if the trade was not found.

Parameters:

id (int) – The ID of the trade to search for from the cache.

Return type:

TradeOffer | None

get_user(id, /)#

Returns a user from cache with a matching ID or None if the user was not found.

Parameters:

id (int) – The ID64 of the user.

Return type:

User | None

property groups: Sequence[Group]#

A read-only list of all the groups the connected client is in.

is_closed()#

Indicates if connection is closed to the WebSocket.

Return type:

bool

is_ready()#

Specifies if the client’s internal cache is ready for use.

Return type:

bool

property latency: float#

Measures latency between a heartbeat send and the heartbeat interval in seconds.

property licenses: Sequence[License]#

A read-only list of licenses the client has access to.

await login(*args, **kwargs)#

Initialize a connection to a Steam CM and login.

If no shared_secret is passed, you will have to manually enter a Steam guard code using code().

Parameters:
  • username – The username of the account to login to.

  • password – The password of the account to login to.

  • shared_secret – The shared secret for the account to login to.

  • identity_secret – The identity secret for the account to login to.

  • refresh_token – The refresh token of the account to login to.

property messages: Sequence[Message]#

A read-only list of all the messages the client has.

await on_announcement_create(announcement, /)#

Called when an announcement in a clan is created.

Parameters:

announcement (steam.Announcement) – The announcement that was created.

await on_authentication_ticket_update(ticket, response, state, /)#

Called when the client’s authentication ticket is updated.

Parameters:
await on_clan_join(clan, /)#

Called when the client joins a new clan.

Parameters:

clan (steam.Clan) – The joined clan.

await on_clan_leave(clan, /)#

Called when the client leaves a clan.

Parameters:

clan (steam.Clan) – The left clan.

await on_clan_update(before, after, /)#

Called when a clan is updated, due to one or more of the following attributes changing:

Parameters:
  • before (steam.Clan) – The clan’s state before it was updated.

  • after (steam.Clan) – The clan’s state now.

await on_event_create(event, /)#

Called when an event in a clan is created.

Parameters:

event (steam.Event) – The event that was created.

await on_friend_add(friend, /)#

Called when a friend is added to the client’s friends list.

Parameters:

friend (steam.Friend) – The friend that was added.

await on_friend_remove(friend, /)#

Called when you or the friend remove each other from your friends lists.

Parameters:

friend (steam.Friend) – The friend who was removed.

await on_group_join(group, /)#

Called when the client joins a new group.

Parameters:

group (steam.Group) – The joined group.

await on_group_leave(group, /)#

Called when the client leaves a group.

Parameters:

group (steam.Group) – The left group.

await on_group_update(before, after, /)#

Called when a group is updated.

Parameters:
  • before (steam.Group) – The group’s state before it was updated.

  • after (steam.Group) – The group’s state now.

await on_reaction_add(reaction, /)#

Called when a reaction is added to a message.

Parameters:

reaction (MessageReaction) – The reaction that was added.

await on_reaction_remove(reaction, /)#

Called when a reaction is removed from a message.

Parameters:

reaction (MessageReaction) – The reaction that was removed.

await redeem_package(id, /)#

Redeem a promotional free licenses package from its ID.

Parameters:

id (int) – The ID of the package to redeem.

Return type:

License

property refresh_token: str | None#

The refresh token for the logged in account, can be used to login.

await register_cd_key(key, /)#

Register a CD key.

Parameters:

key (str) – The CD key to register.

Return type:

TransactionReceipt

run(*args, debug=False, **kwargs)#

A blocking method to start and run the client.

Shorthand for:

async def main():
    async with client:
        await client.login(...)


asyncio.run(main())

It is not recommended to subclass this method, it is normally favourable to subclass login() as it is a coroutine.

Note

This takes the same arguments as login().

Return type:

object

async for ... in search_market(query='', *, limit=100, search_description=True, sort_by='popular', reverse=True)#

https://steamcommunity.com/market/search/render?q=&descriptions=1&category_570_Hero[]=any&category_570_Slot[]=any&category_570_Type[]=any&category_570_Quality[]=tag_unique&appid=570&norender=1

Return type:

AsyncGenerator[MarketSearchItem, None]

property stickers: Sequence[ClientSticker]#

A read-only list of all the stickers the client has.

async for ... in trade_history(*, limit=100, before=None, after=None, language=None, include_failed=True)#

An asynchronous iterator for accessing a steam.ClientUser’s steam.TradeOffer objects.

Examples

Usage:

async for trade in client.trade_history(limit=10):
    items = [getattr(item, "name", str(item.id)) for item in trade.receiving]
    items = ", ".join(items) or "Nothing"
    print("Partner:", trade.user)
    print("Sent:", items)

All parameters are optional.

Parameters:
  • limit (int | None) – The maximum number of trades to search through. Default is 100. Setting this to None will fetch all of the user’s trades, but this will be a very slow operation.

  • before (datetime.datetime | None) – A time to search for trades before.

  • after (datetime.datetime | None) – A time to search for trades after.

  • language (Language | None) – The language to fetch the trade in. None uses the current language.

  • include_failed (bool) – Whether to include trades that failed.

Yields:

TradeOffer

await trade_url(generate_new=False)#

Fetches this account’s trade url.

Parameters:

generate_new (bool) – Whether or not to generate a new trade token, defaults to False.

Return type:

TradeURLInfo

property trades: Sequence[TradeOffer[Asset[User], Asset[ClientUser], User]]#

A read-only list of all the trades the connected client can see.

async for ... in user_news(*, limit=None, before=None, after=None, app=None, flags=None, language=None)#

Fetch news for the user.

Parameters:
  • limit (int | None) – The maximum number of news entries to fetch.

  • before (datetime.datetime | None) – The date to fetch news before.

  • after (datetime.datetime | None) – The date to fetch news after.

  • app (App | None) – The app to fetch news entries related to.

  • flags (UserNewsType | None) – The type of news to fetch.

  • language (Language | None) – The language to fetch the news in. If None, the current language is used.

Return type:

AsyncGenerator[UserNews, None]

property users: Sequence[User]#

A read-only list of all the users the connected client can see.

await wait_for(event, *, check=<return_true>, timeout=None)#

Wait for the first event to be dispatched that meets the requirements, this by default is the first event with a matching event name.

Parameters:
  • event (str) – The event name from the event reference, but without the on_ prefix, to wait for.

  • check (Callable[[...], bool]) – A callable predicate that checks the received event. The arguments must match the parameters of the event being waited for and must return a bool.

  • timeout (float | None) – By default, wait_for() function does not timeout, however, in the case a timeout parameter is passed after the amount of seconds passes asyncio.TimeoutError is raised.

Raises:

asyncio.TimeoutError – If the provided timeout was reached.

Returns:

Returns None, a single argument or a tuple of multiple arguments that mirrors the parameters for the event parameter from the event reference.

Return type:

Any

await wait_until_gc_ready()#

Wait for the on_gc_ready() method to be dispatched.

See also

wait_for_ready()

await wait_until_ready()#

Waits until the client’s internal cache is all ready.

property wallet: Wallet#

The wallet info for the logged in account.

Event Reference#

These events function similar to the regular events, and all of the events there are also applicable to Client. These are however unique to the TF2 extension module.

await steam.ext.tf2.Client.on_account_update(self)#

Called when the client user’s account is updated. This can happen from any one of the below changing:

await steam.ext.tf2.Client.on_item_receive(self, item)#

Called when the client receives an item.

Parameters:

item (tf2.BackpackItem) – The received item.

await steam.ext.tf2.Client.on_item_remove(self, item)#

Called when the client has an item removed from its backpack.

Parameters:

item (tf2.BackpackItem) – The removed item.

await steam.ext.tf2.Client.on_item_update(self, before, after)#

Called when the client has an item in its backpack updated.

Parameters:
  • before (tf2.BackpackItem) – The item before being updated.

  • after (tf2.BackpackItem) – The item now.

Bot#

ext.tf2 also provides a Bot class, which is a subclass of Client and steam.ext.commands.Bot.

class steam.ext.tf2.Bot(**options)#
add_check(predicate)#

Add a global check to the bot.

Parameters:

predicate (Check) – The check to add.

await add_cog(cog)#

Add a cog to the internal list.

Parameters:

cog (Cog[Self]) – The cog to add.

add_command(command)#

Add a command to the internal commands list.

Parameters:

command (Command[CogT]) – The command to register.

add_listener(func, name=None)#

Add a function from the internal listeners list.

Parameters:
  • func (Callable[[~P], Coroutine[Any, Any, R]]) – The listener event to listen for.

  • name (str | None) – The name of the event to listen for. Defaults to func.__name__.

after_invoke(coro)#

Register a coroutine to be ran after a command has been invoked.

Return type:

BotInvokeT

async for ... in all_apps(*, limit=None, modified_after=None, include_games=True, include_dlc=True, include_software=True, include_videos=True, include_hardware=True)#

An asynchronous iterator over all the apps on Steam.

Parameters:
  • limit (int | None) – The maximum number of apps to search through. Default is None. Setting this to None will fetch all of the apps, but this will be a very slow operation.

  • modified_after (datetime.datetime | None) – A time to search for apps after.

  • include_games (bool) – Whether to include games.

  • include_dlc (bool) – Whether to include DLC.

  • include_software (bool) – Whether to include software.

  • include_videos (bool) – Whether to include videos.

  • include_hardware (bool) – Whether to include hardware.

Yields:

AppListApp

property all_commands: list[Command[CogT]]#

A list of the loaded commands.

await anonymous_login()#

Initialize a connection to a Steam CM and login anonymously.

property backpack_slots: int#

The client’s number of backpack slots.

before_invoke(coro)#

Register a coroutine to be ran before any arguments are parsed.

Return type:

BotInvokeT

await can_run(ctx)#

Whether or not the context’s command can be ran.

Parameters:

ctx (Context) – The invocation context.

Return type:

bool

await change_presence(*, app=None, apps=None, state=None, ui_mode=None, flags=None, force_kick=False)#

Set your status.

Parameters:
  • app (App | None) – An app to set your status as.

  • apps (Iterable[App] | None) – A list of apps to set your status to.

  • state (PersonaState | None) –

    The state to show your account as.

    Warning

    Setting your status to Offline, will stop you receiving persona state updates and by extension on_user_update() will stop being dispatched.

  • ui_mode (UIMode | None) – The UI mode to set your status to.

  • flags (PersonaStateFlag | None) – The flags to update your account with.

  • force_kick (bool) – Whether to forcefully kick any other playing sessions.

check(predicate)#

Register a global check for all commands. This is similar to commands.check().

Return type:

Check[MaybeBool]

property children: Sequence[Command[CogT]]#

The commands children.

property clans: Sequence[Clan]#

A read-only list of all the clans the connected client is in.

clear()#

Clears the internal state of the bot. After this, the bot can be considered “re-opened”, i.e. is_closed() and is_ready() both return False. This also clears the internal cache.

await close()#

Unloads any extensions and cogs, then closes the connection to Steam.

await code()#

Get the current steam guard code.

Warning

This will read from sys.stdin if no shared_secret was passed to login().

Return type:

str

property cogs: MappingProxyType[str, Cog[Self]]#

A read only mapping of any loaded cogs.

@command(callback=None, /, *, name=None, cls=<class 'steam.ext.commands.commands.Command'>, **attrs)#

A decorator that could be called. A decorator that invokes command() and adds the created Command to the internal command list.

Parameters:
  • name (str | None) – The name of the command. Will default to callback.__name__.

  • cls (type[Command]) – The class to construct the command from. Defaults to Command.

  • attrs (Any) – The parameters to pass to the command’s __init__.

Returns:

The created command.

Return type:

Callable[[CoroFuncT], C] | C

property commands: set[Command[CogT]]#

A set of the loaded commands without duplicates.

property converters: MappingProxyType[type[Any], Sequence[Converters]]#

A read only mapping of registered converters.

await craft(items, recipe=-2)#

Craft a set of items together with an optional recipe.

Parameters:
Returns:

The crafted items, None if crafting failed.

Return type:

list[BackpackItem[ClientUser]]

await create_clan(name, /, *, abbreviation=None, community_url=None, public=True, headline=None, summary=None, language=None, country=None, state=None, city=None, apps=None, avatar=None)#

Create a clan.

Parameters:
  • name (str) – The name of the clan.

  • avatar (Media | None) – The avatar of the clan.

  • abbreviation (str | None) – The abbreviation of the clan.

  • community_url (URL_ | str | None) – The community URL of the clan.

  • public (bool) – Whether the clan is public.

  • headline (str | None) – The headline of the clan.

  • summary (str | None) – The summary of the clan.

  • language (Language | None) – The language of the clan.

  • country (str | None) – The country of the clan.

  • state (str | None) – The state of the clan.

  • city (str | None) – The city of the clan.

  • apps (Iterable[App] | None) – The apps the clan is associated with.

Return type:

Clan

await create_group(name, /, *, members, avatar=None, tagline=None)#

Create a group.

Parameters:
  • name (str) – The name of the group.

  • members (Iterable[IndividualID]) – The members to add to the group.

  • avatar (Media | None) – The avatar of the group.

  • tagline (str | None) – The tagline of the group.

Return type:

Group

await create_post(content, /, app=None)#

Create a post.

Parameters:
  • content (str) – The content of the post.

  • app (App | None) – The app to create the post for.

Return type:

Post[ClientUser]

property effects: Sequence[ClientEffect]#

A read-only list of all the effects the client has.

property emoticons: Sequence[ClientEmoticon]#

A read-only list of all the emoticons the client has.

@event(coro)#

A decorator that registers an event to listen to.

The events must be a coroutine, if not, TypeError is raised.

Usage:

@client.event
async def on_ready():
    print("Ready!")
Raises:

TypeError – The function passed is not a coroutine.

Return type:

F

property extensions: mappingproxy[str, module]#

A read only mapping of any loaded extensions.

await fetch_app(id, /, *, language=None)#

Fetch an app from its ID.

Parameters:
  • id (int) – The app id of the app.

  • language (Language | None) – The language to fetch the app in. If None uses the current language.

Raises:

ValueError – Passed id isn’t for a valid app.

Return type:

FetchedApp

await fetch_bundle(id, /, *, language=None)#

Fetch a bundle from its ID.

Parameters:
  • id (int) – The ID of the bundle.

  • language (Language | None) – The language to fetch the bundle in. If None uses the current language.

Return type:

FetchedBundle

await fetch_clan(id, /)#

Fetches a clan from the websocket with a matching ID.

Parameters:

id (int) – The ID64 of the clan.

Return type:

Clan

async for ... in fetch_listings(name, app)#

Fetch the listings for an item.

Parameters:
  • name (str) – The name of the item.

  • app (App) – The app the item is from.

Return type:

AsyncGenerator[Listing, None]

await fetch_package(id, /, *, language=None)#

Fetch a package from its ID.

Parameters:
  • id (int) – The ID of the package.

  • language (Language | None) – The language to fetch the package in. If None uses the current language.

Raises:

ValueError – Passed id isn’t for a valid package.

Return type:

FetchedPackage

await fetch_price(name, app, currency=None)#

Fetch the PriceOverview for an item.

Parameters:
  • name (str) – The name of the item.

  • app (App) – The app the item is from.

  • currency (Currency | None) – The currency to fetch the price in.

Return type:

PriceOverview

await fetch_price_history(name, app, currency=None)#

Fetch the price history for an item.

Parameters:
  • name (str) – The name of the item.

  • app (App) – The app the item is from.

  • currency (Currency | None) – The currency to fetch the price in.

Return type:

list[PriceHistory]

await fetch_product_info(*, apps=(), packages=())#

Fetch product info.

Parameters:
  • apps (Collection[App]) – The apps to fetch info on.

  • packages (Collection[Package]) – The packages to fetch info on.

Return type:

list[AppInfo] | list[PackageInfo] | tuple[list[AppInfo], list[PackageInfo]]

await fetch_published_file(id, /, *, revision=PublishedFileRevision.Default, language=None)#

Fetch a published file from its ID.

Parameters:
  • id (int) – The ID of the published file.

  • revision (PublishedFileRevision) – The revision of the published file to fetch.

  • language (Language | None) – The language to fetch the published file in. If None, the current language is used.

Return type:

PublishedFile | None

await fetch_published_files(*ids, revision=PublishedFileRevision.Default, language=None)#

Fetch published files from their IDs.

Parameters:
  • ids (int) – The IDs of the published files.

  • revision (PublishedFileRevision) – The revision of the published files to fetch.

  • language (Language | None) – The language to fetch the published files in. If None, the current language is used.

Return type:

list[PublishedFile | None]

await fetch_server(*, id=None, ip=None, port=None)#

Fetch a GameServer from its ip and port or its Steam ID or None if fetching the server failed.

Parameters:
  • ip (IPAdress | str | None) – The ip of the server.

  • port (int | str | None) – The port of the server.

  • id (int | None) – The ID64 of the game server. If passed, it makes a call to the master server to fetch its ip and port.

Note

Passing an ip, port and id to this function will raise an TypeError.

Return type:

GameServer | None

await fetch_servers(query=None, /, *, limit=100)#

Query game servers.

Parameters:
  • query (str | None) – The query to match servers with. If None returns all servers.

  • limit (int) – The maximum amount of servers to return.

See also

Query.where()

Return type:

list[GameServer]

await fetch_store_item(*, apps=(), packages=(), bundles=(), language=None)#

Fetch store items.

Parameters:
  • apps (Sequence[App]) – The apps to fetch store items for.

  • packages (Sequence[Package]) – The packages to fetch store items for.

  • bundles (Sequence[Bundle]) – The bundles to fetch store items for.

  • language (Language | None) – The language to fetch the store items in. If None, the default language is used.

Return type:

Any

await fetch_trade(id, /, *, language=None)#

Fetches a trade with a matching ID or None if the trade was not found.

Parameters:
  • id (int) – The ID of the trade to search for from the API.

  • language (Language | None) – The language to fetch the trade in. None uses the current language.

Return type:

TradeOffer[Item[User], Item[ClientUser], User] | None

await fetch_user(id, /)#

Fetches a user with a matching ID.

Parameters:

id (int) – The ID64 of the user.

Return type:

User

await fetch_users(*ids)#

Fetches a list of User.

Note

The User objects returned are unlikely to retain the order they were originally in.

Parameters:

ids (int) – The user’s ID64s.

Return type:

Sequence[User]

get_app(id, /)#

Creates a PartialApp instance from its ID.

Parameters:

id (int) – The app id of the app.

Return type:

PartialApp[None]

get_bundle(id, /)#

Creates a PartialBundle instance from its ID.

Parameters:

id (int) – The ID of the bundle.

Return type:

PartialBundle

get_clan(id, /)#

Get a clan from cache with a matching ID or None if the group was not found.

Parameters:

id (int) – The ID64 of the clan.

Return type:

Clan | None

get_cog(name)#

Get a loaded cog or None.

Parameters:

name (str) – The name of the cog.

Return type:

Cog[Self] | None

get_command(name)#

Get a command.

Parameters:

name (str) – The name of the command.

Returns:

The found command or None.

Return type:

Command[CogT] | None

await get_context(message, *, cls=<class 'steam.ext.commands.context.Context'>)#

Get the context for a certain message.

Parameters:
  • message (Message[Any]) – The message to get the context for.

  • cls (type[C]) – The class to construct the context with, this is the type of the return type

Return type:

C

get_group(id, /)#

Get a group from cache with a matching ID or None if the group was not found.

Parameters:

id (int) – The ID64 of the group.

Return type:

Group | None

get_package(id, /)#

Creates a PartialPackage from its ID.

Parameters:

id (int) – The ID of the package.

Return type:

PartialPackage

await get_prefix(message)#

Get the command prefix for a certain message.

Parameters:

message (Message) – The message to get the prefix for.

Return type:

str | None

get_trade(id, /)#

Get a trade from cache with a matching ID or None if the trade was not found.

Parameters:

id (int) – The ID of the trade to search for from the cache.

Return type:

TradeOffer | None

get_user(id, /)#

Returns a user from cache with a matching ID or None if the user was not found.

Parameters:

id (int) – The ID64 of the user.

Return type:

User | None

@group(callback=None, /, *, name=None, cls=None, **attrs)#

A decorator that invokes group() and adds the created Group to the internal command list.

Parameters:
  • name (str | None) – The name of the command. Will default to callback.__name__.

  • cls (type[Group]) – The class to construct the command from. Defaults to Group.

  • attrs (Any) – The parameters to pass to the command’s __init__.

Returns:

The created group command.

Return type:

Callable[[CoroFuncT], G] | G

property groups: Sequence[Group]#

A read-only list of all the groups the connected client is in.

property help_command: HelpCommand | None#

The bot’s help command.

await invoke(ctx)#

Invoke a command. This will parse arguments, checks, cooldowns etc. correctly.

Parameters:

ctx (Context) – The invocation context.

is_closed()#

Indicates if connection is closed to the WebSocket.

Return type:

bool

is_premium()#

Whether or not the client’s account has TF2 premium. None if the user isn’t ready.

Return type:

bool

is_ready()#

Specifies if the client’s internal cache is ready for use.

Return type:

bool

property latency: float#

Measures latency between a heartbeat send and the heartbeat interval in seconds.

property licenses: Sequence[License]#

A read-only list of licenses the client has access to.

@listen(name=None, /)#

A decorator that could be called. Register a function as a listener. Calls add_listener(). Similar to Cog.listener()

Parameters:

name (str) – The name of the event to listen for. Will default to func.__name__.

Return type:

Callable[[F], F] | F

await load_extension(extension)#

Load an extension.

Parameters:

extension (str | PathLike[str]) – The name of the extension to load.

Raises:

ImportError – The extension is missing a setup function.

await login(*args, **kwargs)#

Initialize a connection to a Steam CM and login.

If no shared_secret is passed, you will have to manually enter a Steam guard code using code().

Parameters:
  • username – The username of the account to login to.

  • password – The password of the account to login to.

  • shared_secret – The shared secret for the account to login to.

  • identity_secret – The identity secret for the account to login to.

  • refresh_token – The refresh token of the account to login to.

property messages: Sequence[Message]#

A read-only list of all the messages the client has.

await on_account_update()#

Called when the client user’s account is updated. This can happen from any one of the below changing:

await on_announcement_create(announcement, /)#

Called when an announcement in a clan is created.

Parameters:

announcement (steam.Announcement) – The announcement that was created.

await on_authentication_ticket_update(ticket, response, state, /)#

Called when the client’s authentication ticket is updated.

Parameters:
await on_clan_join(clan, /)#

Called when the client joins a new clan.

Parameters:

clan (steam.Clan) – The joined clan.

await on_clan_leave(clan, /)#

Called when the client leaves a clan.

Parameters:

clan (steam.Clan) – The left clan.

await on_clan_update(before, after, /)#

Called when a clan is updated, due to one or more of the following attributes changing:

Parameters:
  • before (steam.Clan) – The clan’s state before it was updated.

  • after (steam.Clan) – The clan’s state now.

await on_event_create(event, /)#

Called when an event in a clan is created.

Parameters:

event (steam.Event) – The event that was created.

await on_friend_add(friend, /)#

Called when a friend is added to the client’s friends list.

Parameters:

friend (steam.Friend) – The friend that was added.

await on_friend_remove(friend, /)#

Called when you or the friend remove each other from your friends lists.

Parameters:

friend (steam.Friend) – The friend who was removed.

await on_group_join(group, /)#

Called when the client joins a new group.

Parameters:

group (steam.Group) – The joined group.

await on_group_leave(group, /)#

Called when the client leaves a group.

Parameters:

group (steam.Group) – The left group.

await on_group_update(before, after, /)#

Called when a group is updated.

Parameters:
  • before (steam.Group) – The group’s state before it was updated.

  • after (steam.Group) – The group’s state now.

await on_item_update(before, after)#

Called when the client has an item in its backpack updated.

Parameters:
  • before (tf2.BackpackItem) – The item before being updated.

  • after (tf2.BackpackItem) – The item now.

await on_reaction_add(reaction, /)#

Called when a reaction is added to a message.

Parameters:

reaction (MessageReaction) – The reaction that was added.

await on_reaction_remove(reaction, /)#

Called when a reaction is removed from a message.

Parameters:

reaction (MessageReaction) – The reaction that was removed.

await process_commands(message, /)#

A method to process commands for a message.

Warning

This is vital for commands to function. If you have an on_message() as a registered event using event() commands will not be dispatched. Remember to add a call to this in your on_message() event.

Parameters:

message (Message) – The message to get the context for.

await redeem_package(id, /)#

Redeem a promotional free licenses package from its ID.

Parameters:

id (int) – The ID of the package to redeem.

Return type:

License

property refresh_token: str | None#

The refresh token for the logged in account, can be used to login.

await register_cd_key(key, /)#

Register a CD key.

Parameters:

key (str) – The CD key to register.

Return type:

TransactionReceipt

await reload_extension(extension)#

Atomically reload an extension. If any error occurs during the reload the extension will be reverted to its original state.

Parameters:

extension (str | PathLike[str]) – The name of the extension to reload.

Raises:

ModuleNotFoundError – The extension wasn’t found in the loaded extensions.

remove_check(predicate)#

Remove a global check from the bot.

Parameters:

predicate (Check) – The check to remove.

await remove_cog(cog)#

Remove a cog from the internal list.

Parameters:

cog (Cog[Self]) – The cog to remove.

remove_command(name)#

Remove a command from the internal commands list.

Parameters:

name (str) – The name of the command to remove.

Returns:

The removed command or None if the command was not found.

Return type:

Command[CogT] | None

remove_listener(func, name=None)#

Remove a function from the internal listeners list.

Parameters:
  • func (Callable[[~P], Coroutine[Any, Any, R]]) – The listener to remove.

  • name (str | None) – The name of the event to remove. Defaults to func.__name__.

run(*args, debug=False, **kwargs)#

A blocking method to start and run the client.

Shorthand for:

async def main():
    async with client:
        await client.login(...)


asyncio.run(main())

It is not recommended to subclass this method, it is normally favourable to subclass login() as it is a coroutine.

Note

This takes the same arguments as login().

Return type:

object

property schema: Schema#

TF2’s item schema. None if the user isn’t ready.

async for ... in search_market(query='', *, limit=100, search_description=True, sort_by='popular', reverse=True)#

https://steamcommunity.com/market/search/render?q=&descriptions=1&category_570_Hero[]=any&category_570_Slot[]=any&category_570_Type[]=any&category_570_Quality[]=tag_unique&appid=570&norender=1

Return type:

AsyncGenerator[MarketSearchItem, None]

set_language(file)#

Set the localization files for your bot.

This isn’t necessary in most situations.

property stickers: Sequence[ClientSticker]#

A read-only list of all the stickers the client has.

async for ... in trade_history(*, limit=100, before=None, after=None, language=None, include_failed=True)#

An asynchronous iterator for accessing a steam.ClientUser’s steam.TradeOffer objects.

Examples

Usage:

async for trade in client.trade_history(limit=10):
    items = [getattr(item, "name", str(item.id)) for item in trade.receiving]
    items = ", ".join(items) or "Nothing"
    print("Partner:", trade.user)
    print("Sent:", items)

All parameters are optional.

Parameters:
  • limit (int | None) – The maximum number of trades to search through. Default is 100. Setting this to None will fetch all of the user’s trades, but this will be a very slow operation.

  • before (datetime.datetime | None) – A time to search for trades before.

  • after (datetime.datetime | None) – A time to search for trades after.

  • language (Language | None) – The language to fetch the trade in. None uses the current language.

  • include_failed (bool) – Whether to include trades that failed.

Yields:

TradeOffer

await trade_url(generate_new=False)#

Fetches this account’s trade url.

Parameters:

generate_new (bool) – Whether or not to generate a new trade token, defaults to False.

Return type:

TradeURLInfo

property trades: Sequence[TradeOffer[Asset[User], Asset[ClientUser], User]]#

A read-only list of all the trades the connected client can see.

await unload_extension(extension)#

Unload an extension.

Parameters:

extension (str | PathLike[str]) – The name of the extension to unload.

Raises:

ModuleNotFoundError – The extension wasn’t found in the loaded extensions.

property user: ClientUser#

Represents the connected client. None if not logged in.

async for ... in user_news(*, limit=None, before=None, after=None, app=None, flags=None, language=None)#

Fetch news for the user.

Parameters:
  • limit (int | None) – The maximum number of news entries to fetch.

  • before (datetime.datetime | None) – The date to fetch news before.

  • after (datetime.datetime | None) – The date to fetch news after.

  • app (App | None) – The app to fetch news entries related to.

  • flags (UserNewsType | None) – The type of news to fetch.

  • language (Language | None) – The language to fetch the news in. If None, the current language is used.

Return type:

AsyncGenerator[UserNews, None]

property users: Sequence[User]#

A read-only list of all the users the connected client can see.

await wait_for(event, *, check=<return_true>, timeout=None)#

Wait for the first event to be dispatched that meets the requirements, this by default is the first event with a matching event name.

Parameters:
  • event (str) – The event name from the event reference, but without the on_ prefix, to wait for.

  • check (Callable[[...], bool]) – A callable predicate that checks the received event. The arguments must match the parameters of the event being waited for and must return a bool.

  • timeout (float | None) – By default, wait_for() function does not timeout, however, in the case a timeout parameter is passed after the amount of seconds passes asyncio.TimeoutError is raised.

Raises:

asyncio.TimeoutError – If the provided timeout was reached.

Returns:

Returns None, a single argument or a tuple of multiple arguments that mirrors the parameters for the event parameter from the event reference.

Return type:

Any

await wait_until_gc_ready()#

Wait for the on_gc_ready() method to be dispatched.

See also

wait_for_ready()

await wait_until_ready()#

Waits until the client’s internal cache is all ready.

property wallet: Wallet#

The wallet info for the logged in account.

Enumerations#

class steam.ext.tf2.ItemQuality#
Normal = 0#
Genuine = 1#
Vintage = 3#
Rarity3 = 4#
Unusual = 5#
Unique = 6#
Community = 7#
Valve = 8#
SelfMade = 9#
Customized = 10#
Strange = 11#
Completed = 12#
Haunted = 13#
Collectors = 14#
DecoratedWeapon = 15#
class steam.ext.tf2.ItemFlags#
CannotTrade = 1#
CannotCraft = 2#
CanBeTradedByFreeAccounts = 4#
NotEcon = 8#

Items that cannot interact in the economy (can’t be traded, gift-wrapped, crafted, etc.)

PurchasedAfterStoreCraftabilityChanges2012 = 16#

Cosmetic items coming from the store are now usable in crafting

ForceBlueTeam = 32#
StoreItem = 64#
Preview = 128#
class steam.ext.tf2.ItemOrigin#
Invalid = -1#
Drop = 0#
Achievement = 1#
Purchased = 2#
Traded = 3#
Crafted = 4#
StorePromotion = 5#
Gifted = 6#
SupportGranted = 7#
FoundInCrate = 8#
Earned = 9#
ThirdPartyPromotion = 10#
GiftWrapped = 11#
HalloweenDrop = 12#
PackageItem = 13#
Foreign = 14#
CDKey = 15#
CollectionReward = 16#
PreviewItem = 17#
SteamWorkshopContribution = 18#
PeriodicScoreReward = 19#
MvMMissionCompletionReward = 20#
MvMSquadSurplusReward = 21#
RecipeOutput = 22#
QuestDrop = 23#
QuestLoanerItem = 24#
TradeUp = 25#
ViralCompetitiveBetaPassSpread = 26#
Max = 27#
class steam.ext.tf2.Mercenary#
Scout = 1#
Sniper = 2#
Soldier = 3#
Demoman = 4#
Medic = 5#
Heavy = 6#
Pyro = 7#
Spy = 8#
Engineer = 9#
class steam.ext.tf2.ItemSlot#
Primary = 0#
Secondary = 1#
Melee = 2#
Sapper = 4#
PDA = 5#
PDA2 = 6#
Cosmetic1 = 7#
Cosmetic2 = 8#
Action = 9#
Cosmetic3 = 10#
Taunt1 = 11#
Taunt2 = 12#
Taunt3 = 13#
Taunt4 = 14#
Taunt5 = 15#
Taunt6 = 16#
Taunt7 = 17#
Taunt8 = 18#
Misc = 100#
Gift = 101#
CraftItem = 102#
class steam.ext.tf2.WearLevel#
FactoryNew = '(Factory New)'#
MinimalWear = '(Minimal Wear)'#
FieldTested = '(Field-Tested)'#
WellWorn = '(Well-Worn)'#
BattleScarred = '(Battle Scarred)'#
class steam.ext.tf2.BackpackSortType#
Name = 1#
Defindex = 2#
Rarity = 3#
Type = 4#
Date = 5#
Class = 101#
Slot = 102#
class steam.ext.tf2.Part#
KillAssists = 2#
ScoutsKilled = 10#
SnipersKilled = 11#
SoldiersKilled = 12#
DemomenKilled = 13#
HeaviesKilled = 14#
PyrosKilled = 15#
SpiesKilled = 16#
EngineersKilled = 17#
MedicsKilled = 18#
BuildingsDestroyed = 19#
ProjectilesReflected = 20#
HeadshotKills = 21#
AirborneEnemyKills = 22#
GibKills = 23#
KillsUnderAFullMoon = 27#
Dominations = 28#
Revenges = 30#
PosthumousKills = 31#
TeammatesExtinguished = 32#
CriticalKills = 33#
KillsWhileExplosiveJumping = 34#
SappersDestroyed = 36#
CloakedSpiesKilled = 37#
MedicsKilledThatHaveFullÜberCharge = 38#
RobotsDestroyed = 39#
GiantRobotsDestroyed = 40#
KillsWhileLowHealth = 44#
KillsDuringHalloween = 45#
RobotsKilledDuringHalloween = 46#
DefenderKills = 47#
SubmergedEnemyKills = 48#
TanksDestroyed = 61#
LongDistanceKills = 62#
KillsduringVictoryTime = 67#
RobotScoutsDestroyed = 68#
RobotSpiesDestroyed = 74#
TauntKills = 77#
UnusualWearingPlayerKills = 78#
BurningPlayerKills = 79#
KillstreaksEnded = 80#
FreezecamTauntAppearances = 81#
DamageDealt = 82#
FiresSurvived = 83#
AlliedHealingDone = 84#
PointBlankKills = 85#
Kills = 87#
FullHealthKills = 88#
TauntingPlayerKills = 89#
NotCritnorMiniCritKills = 93#
PlayerHits = 94#
Assists = 95#
Kills_ = 97#
class steam.ext.tf2.Spell#
VoicesFromBelow = 1006#
PumpkinBombs = 1007#
HalloweenFire = 1008#
Exorcism = 1009#
PutrescentPigmentation = 8900#
DieJob = 8901#
ChromaticCorruption = 8902#
SpectralSpectrum = 8903#
SinisterStaining = 8904#
TeamSpiritFootprints = 8914#
GangreenFootprints = 8915#
CorpseGrayFootprints = 8916#
ViolentVioletFootprints = 8917#
RottenOrangeFootprints = 8918#
BruisedPurpleFootprints = 8919#
HeadlessHorseshoe = 8920#
indices = {1004: {0: Spell.DieJob, 1: Spell.ChromaticCorruption, 2: Spell.PutrescentPigmentation, 3: Spell.SpectralSpectrum, 4: Spell.SinisterStaining}, 1005: {1: Spell.TeamSpiritFootprints, 2: Spell.HeadlessHorseshoe, 3100495: Spell.CorpseGrayFootprints, 5322826: Spell.ViolentVioletFootprints, 8208497: Spell.BruisedPurpleFootprints, 8421376: Spell.GangreenFootprints, 13595446: Spell.RottenOrangeFootprints}}#
class steam.ext.tf2.Sheen#
TeamShine = 1#
DeadlyDaffodil = 2#
Manndarin = 3#
MeanGreen = 4#
AgonizingEmerald = 5#
VillainousViolet = 6#
HotRod = 7#
class steam.ext.tf2.Killstreak#
FireHorns = 2002#
CerebralDischarge = 2003#
Tornado = 2004#
Flames = 2005#
Singularity = 2006#
Incinerator = 2007#
HypnoBeam = 2008#
class steam.ext.tf2.Attribute#
Paint = 1031#
CustomTexture = 1051#
MakersMark = 1053#
Killstreak = 1094#
GiftedBy = 2570#
Festivizer = 2572#

Models#

class steam.ext.tf2.Backpack#

A class to represent the client’s backpack.

property metal: Metal#

Returns the amount of metal in this inventory

await set_positions(items_and_positions)#

Set the positions of items in the inventory.

Parameters:

items_and_positions (Iterable[tuple[BackpackItem[ClientUser], int]]) – A list of (item, position) pairs to set the positions for. This is 0 indexed.

await sort(type)#

Sort this inventory.

Parameters:

type (BackpackSortType) – The sort type to sort by, only types visible in game are usable.

await trade_up(*items)#

Trade up these items. Into a new item.

Note

The TF2 wiki for more info.

Currency#

As working with refined is so common in TF2, ext.tf2 provides a Metal class to make working with it easier.

class steam.ext.tf2.Metal#

A class to represent some metal in TF2.

The value used as the denominator corresponds to one scrap metal.

Examples

Metal("1.22") == Metal(1.22)
Metal(1.22) == Metal(1.22)
Metal(1) == Metal(1.00)

Note

When working with large floating point numbers, it’s recommended to pass a str to avoid precision loss.

classmethod extract_scrap(value)#
Return type:

int

classmethod from_items(items)#

The amount of metal in the items.

Example

their_inventory = await user.inventory(steam.TF2)
their_metal = Metal.from_items(their_inventory)
our_inventory = await client.user.inventory(steam.TF2)
await user.send(f"I have {'more' if our_inventory.metal > their_metal else 'less'} metal than you")
Return type:

Self