Client

Client

class gd.Client(*, load_after_post: bool = True, **http_args)[source]

Main class in gd.py, used for interacting with the servers of Geometry Dash.

Parameters
  • load_after_post (bool) –

    Whether to load comments/messages/requests after sending them.

    Note

    Defaults to True, in which case the following method calls will return entities:

    • send_message();

    • send_friend_request();

    • comment_level();

    • post_comment().

    Otherwise, if False or not found, these methods will return None.

  • **http_args – Arguments to pass to HTTPClient constructor.

session

Session used processing requests and responses.

Type

Session

database

Client’s database, used for working with saves. There is an alias for it called db.

Type

Database

account_id

Account ID of the client. 0 if not logged in.

Type

int

id

ID of the client. 0 if not logged in.

Type

int

name

Name of the client. Empty string if not logged in.

Type

str

password

Password of the client. Empty string if not logged in.

Type

str

edit(**attrs)gd.client.Client[source]

Edit attributes of the client.

Parameters

**attrs – Attributes to add.

Returns

Current client.

Return type

Client

is_logged()bool[source]

Check wether the client is logged in.

Returns

True if client is logged in, False otherwise.

Return type

bool

run(maybe_awaitable: Union[Awaitable[T], T])T[source]

Run given maybe awaitable object and return the result.

Parameters

maybe_awaitable (Union[Awaitable[T], T]) – Maybe awaitable object to execute.

Returns

Result of the execution.

Return type

T

property db

Same as database.

Type

Database

property http

Same as gd.Session.http.

Type

HTTPClient

property encoded_password

Encoded password for the client.

Type

str

property user

User representing current client.

Type

User

async logout()None[source]

Logout from account.

Example

>>> await client.login("user", "password")
>>> await client.logout()
>>> client.id
0
login(name: str, password: str)gd.client.LoginContextManager[source]
Async-with

Return context manager that can be used to temporarily log in, logging out on exit.

Awaiting on the context manager will act the same as actually logging in.

Example

>>> async with client.login("user", "password"):
...     async for friend in client.get_friends():
...         print(friend)
Parameters
  • name (str) – Name of an account.

  • password (str) – Password of an account.

async do_login(name: str, password: str)None[source]

Login into an account and update client’s settings.

Example

>>> await client.do_login("user", "password")
>>> client.name
"user"
>>> client.password
"password"
Parameters
  • name (str) – Name of an account.

  • password (str) – Password of an account.

unsafe_login(name: str, password: str)gd.client.LoginContextManager[source]
Async-with

Return context manager that can be used to temporarily log in unsafely, logging out on exit.

Awaiting on the context manager will act the same as actually logging in.

Example

>>> await client.unsafe_login("user", "password")
>>> client.name
"user"
>>> client.password
"password"
Parameters
  • name (str) – Name of an account.

  • password (str) – Password of an account.

async do_unsafe_login(name: str, password: str)None[source]

Login into an account and update client’s settings.

This function is not safe, because it does not use login endpoint.

Instead, it assumes that credentials are correct, and only searches for ID and Account ID.

Example

>>> await client.do_unsafe_login("user", "password")
>>> client.name
"user"
>>> client.password
"password"
Parameters
  • name (str) – Name of an account.

  • password (str) – Password of an account.

load()gd.api.database.Database[source]

Load cloud save and process it.

This returns a Database, and sets client.database to it.

Example

>>> await client.login("user", "password")
>>> database = await client.load()  # load current save
>>> print(database.user_name)  # print current user name
Raises
Returns

Loaded database.

Return type

Database

save(database: Optional[gd.api.database.Database] = None)None[source]

Send save to the cloud.

Example

>>> await client.login("user", "password")
>>> await client.load()  # load current save
>>> client.database.set_bootups(0)  # set "bootups" value to "0"
>>> await client.save()
Parameters

database (Optional[Database]) – Database to save. If not given or None, tries to use database.

Raises
update_profile(stars: Optional[int] = None, diamonds: Optional[int] = None, coins: Optional[int] = None, user_coins: Optional[int] = None, demons: Optional[int] = None, icon_type: Optional[Union[int, str, gd.enums.IconType]] = None, icon: Optional[int] = None, color_1_id: Optional[int] = None, color_2_id: Optional[int] = None, has_glow: Optional[bool] = None, cube: Optional[int] = None, ship: Optional[int] = None, ball: Optional[int] = None, ufo: Optional[int] = None, wave: Optional[int] = None, robot: Optional[int] = None, spider: Optional[int] = None, death_effect: Optional[int] = None, special: int = 0, *, set_as_user: Optional[gd.user.User] = None)None[source]

Update profile of the client.

Example

>>> await client.update_profile(has_glow=True)  # enable glow outline
Parameters
  • stars (Optional[int]) – Amount of stars to set.

  • diamonds (Optional[int]) – Amount of diamonds to set.

  • coins (Optional[int]) – Amount of coins to set.

  • user_coins (Optional[int]) – Amount of user coins to set.

  • demons (Optional[int]) – Amount of demons to set.

  • icon_type (Optional[Union[int, str, IconType]]) – Icon type to use. See IconType for more info.

  • icon (Optional[int]) – Icon ID to set.

  • color_1_id (Optional[int]) – ID of primary color to use.

  • color_2_id (Optional[int]) – ID of secondary color to use.

  • has_glow (Optional[bool]) – Whether to use glow outline.

  • cube (Optional[int]) – ID of cube to use.

  • ship (Optional[int]) – ID of ship to use.

  • ball (Optional[int]) – ID of ball to use.

  • ufo (Optional[int]) – ID of ufo to use.

  • wave (Optional[int]) – ID of wave to use.

  • robot (Optional[int]) – ID of robot to use.

  • spider (Optional[int]) – ID of spider to use.

  • death_effect (Optional[int]) – ID of death effect to use.

  • special (int) – Special number to use. Default is 0.

  • set_as_user (Optional[User]) –

    User to get all missing parameters from. If not given or None, user is used, which implies that:

    await client.update_profile()
    

    Will cause no effect.

update_settings(message_state: Optional[Union[int, str, gd.enums.MessageState]] = None, friend_request_state: Optional[Union[int, str, gd.enums.FriendRequestState]] = None, comment_state: Optional[Union[int, str, gd.enums.CommentState]] = None, youtube: Optional[str] = None, twitter: Optional[str] = None, twitch: Optional[str] = None, *, set_as_user: Optional[gd.user.User] = None)None[source]

Update profile of the client.

Example

>>> await client.update_settings(comment_state="open_to_all")  # open comments to everyone
Parameters
  • message_state (Optional[Union[int, str, MessageState]]) – Message state to set. See MessageState.

  • friend_request_state (Optional[Union[ int, str, FriendRequestState]]) – Friend request state to set. See FriendRequestState.

  • comment_state (Optional[Union[int, str, CommentState]]) – Comment state to set. See CommentState.

  • youtube (Optional[str]) – YouTube channel ID to set. In link: https://youtube.com/channel/{youtube}.

  • twitter (Optional[str]) – Twitter ID to set. In link: https://twitter.com/{twitter}.

  • twitch (Optional[str]) – Twitch ID to set. In link https://twitch.tv/{twitch}.

  • set_as_user (Optional[User]) –

    User to get all missing parameters from. If not given or None, user is used, which implies that:

    await client.update_settings()
    

    Will cause no effect.

async on_daily(level: gd.level.Level)T[source]

This is the event that is fired when a new daily level is set. See Event Reference for more info.

async on_weekly(level: gd.level.Level)T[source]

This is the event that is fired when a new weekly demon is assigned. See Event Reference for more info.

async on_rate(level: gd.level.Level)T[source]

This is the event that is fired when a new level is rated. See Event Reference for more info.

async on_unrate(level: gd.level.Level)T[source]

This is the event that is fired when a level is unrated. See Event Reference for more info.

async on_message(message: gd.message.Message)T[source]

This is the event that is fired when a logged in client gets a message. See Event Reference for more info.

async on_friend_request(friend_request: gd.friend_request.FriendRequest)T[source]

This is the event that is fired when a logged in client gets a friend request. See Event Reference for more info.

async on_level_comment(level: gd.level.Level, comment: gd.comment.Comment)T[source]

This is the event that is fired when a comment is posted on some level. See Event Reference for more info.

async dispatch(event_name: str, *args, **kwargs)None[source]

Dispatch an event given by event_name with *args and **kwargs.

Parameters
  • event_name (str) – Name of event to dispatch without on_ prefix, e.g. "new_daily".

  • *args – Args to call handler with.

  • **kwargs – Keyword args to call handler with.

event(function: Callable[[], Union[T, Awaitable[T]]])Callable[[], Union[T, Awaitable[T]]][source]

A decorator that registers an event to listen to:

@client.event
async def on_level_rated(level: gd.Level) -> None:
    print(level.name)