Data API Reference¶
- class topgg.data.DataContainerMixin[source]¶
A class that holds data.
This is useful for injecting some data so that they’re available as arguments in your functions.
- get_data(type_: Type[topgg.data.T]) Optional[topgg.data.T][source]¶
- get_data(type_: Type[topgg.data.T], default: Any = None) Any
Gets the injected data.
- set_data(data_: Any, *, override: bool = False) topgg.data.DataContainerT[source]¶
Sets data to be available in your functions.
- Parameters
data_ (
typing.Any) – The data to be injected.override (
bool) – Whether or not to override another instance that already exists.
- Raises
TopGGException – If override is False and another instance of the same type exists.
- topgg.data.data(type_: Type[topgg.data.T]) topgg.data.T[source]¶
Represents the injected data. This should be set as the parameter’s default value.
- Parameters
type_ (
type[T]) – The type of the injected data.- Returns
The injected data of type T.
- Return type
T- Example
import topgg # In this example, we fetch the stats from a Discord client instance. client = Client(...) dblclient = topgg.DBLClient(TOKEN).set_data(client) autopost: topgg.AutoPoster = dblclient.autopost() @autopost.stats() def get_stats(client: Client = topgg.data(Client)): return topgg.StatsWrapper(guild_count=len(client.guilds), shard_count=len(client.shards))