Development API Reference

The following section outlines the API of gd.py for library developers.

Note

This section is only for gd.py developers, nothing interesting and useful for basic users here.

HTTP Requests Module

class gd.HTTPClient(*, url: Union[str, yarl.URL] = 'http://www.boomlings.com/database/', use_user_agent: bool = False, forwarded_for: Optional[str] = None, proxy: Optional[str] = None, proxy_auth: Optional[aiohttp.helpers.BasicAuth] = None, timeout: Union[float, int] = 150, max_requests: int = 250, debug: bool = False, **kwargs)[source]

Class that handles the main part of the entire gd.py - sending HTTP requests.

change_url(url: Union[str, yarl.URL])None[source]

Change base for requests. Default base is http://www.boomlings.com/database/, but it can be changed.

Parameters

url (str) – Base to change HTTPClient base to.

set_max_requests(value: int = 250, *, loop: Optional[asyncio.events.AbstractEventLoop] = None)None[source]

Creates an asyncio.Semaphore object with given value and loop in order to limit amount of max requests at a time.

Parameters
  • value (int) – Value to set semaphore to. Default is 250.

  • loop (asyncio.AbstractEventLoop) – Event loop to pass to semaphore’s constructor.

set_debug(debug: bool = False)None[source]

Set http client debugging.

Parameters

debug (bool) – Whether to set debug on or off.

await fetch(php: str, data: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None, get_cookies: bool = False, cookie: Optional[str] = None, custom_base: Optional[str] = None, method: Optional[str] = None) → Optional[Union[bytes, int, str]][source]

This function is a coroutine. Sends an HTTP Request to a Geometry Dash server and returns the response.

Parameters
  • php (str) –

    The endpoint for the request URL, passed like this:

    url = 'http://www.boomlings.com/database/' + php + '.php'
    

  • params (Union[dict, str]) – Parameters to send with the request. Type dict is prefered.

  • get_cookies (bool) – Indicates whether to fetch a cookie. This is used in different account management actions.

  • cookie (str) – Cookie, represented as string. Technically should be catched with get_cookies set to True.

  • custom_base ([str, yarl.URL]) – Custom base using different Geometry Dash IP. By default self.base is used.

  • method (str) – Method to use when requesting. This parameter is case insensetive. By default, if parameters is or empty, GET is used, otherwise POST is used.

Returns

res with the following rules: Returns an int, representing server error code, e.g. -1, if server responded with error. Otherwise, returns response from a server as a str if successfully decodes it, and on fail returns bytes. If a cookie is requested, returns a pair (res, c) where c is a str cookie.

Return type

Union[bytes, str, int]

Raises

HTTPError – An exception occured during handling request/response.

await request(route: str, data: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None, custom_base: Optional[str] = None, method: Optional[str] = None, error_codes: Optional[Dict[int, Exception]] = None, exclude: Tuple[Type[BaseException]] = (), should_map: bool = False, get_cookies: bool = False, cookie: Optional[str] = None) → Optional[Union[bytes, int, str]][source]

This function is a coroutine. A handy shortcut for fetching response from a server and formatting it. Basically does HTTPClient.fetch() and operates on its result.

Parameters
  • error_codes (Dict[int, Exception]) – A dictionary that response is checked against. Exception can be any Exception.

  • exclude (Tuple[Type[BaseException]]) – Types of errors to ignore.

Raises
  • HTTPError – GD Server has destroyed the connection, or machine has no connection.

  • Exception – Exception specified in error_codes, if present.

Returns

If error_codes is omitted, return type is same as return of HTTPClient.fetch() call. If error is raised and it is in exclude, returns None.

Return type

Optional[Union[int, bytes, str]]

await normal_request(url: str, data: Optional[Union[dict, str]] = None, params: Optional[Union[dict, str]] = None, method: Optional[str] = None, **kwargs)bytes[source]

This function is a coroutine. Same as doing aiohttp.ClientSession.request(), where method is either given one or "GET" if data is None or omitted, and "POST" otherwise.

class gd.Session(**http_args)[source]

Implements all requests-related functionality. No docstrings here yet…

Note

See source of the session for more information.

Parameters Creating

class gd.Parameters[source]

Class that allows step-by-step parameter creation. Used in almost all HTTP Requests.

A common usage of this class looks like that:

parameters = (
    Parameters().create_new()
    .put_definer('song', str(...))
    .finish()
)
await http.request(..., parameters)

...
gameVersion

Current game version.

Type

str

binaryVersion

Current binary version.

Type

str

secret

Secret used in requests.

Type

str

level_secret

Secret used in level operations (e.g. Level.delete())

Type

str

login_secret

Secret used in login requests.

Type

str

mod_secret

Secret used in moderator requests.

Type

str

dict

Dictionary where parameters are stored.

Type

dict

create_new(game_version: int = 21, binary_version: int = 35, add_basic: bool = True) → gd.utils.params.Parameters[source]

Start forming a new dictionary.

Parameters

type (str) – Type of start, use ‘web’ to start with an empty dictionary. When omitted or None, adds gameVersion, binaryVersion and gdw to a dict.

Returns

self

Return type

Parameters

finish() → Dict[str, str][source]

Finishes creating parameters dictionary, and adds secret parameter.

Puts Parameters.secret as secret parameter.

Returns

Fully formatted dictionary.

Return type

dict

finish_level() → Dict[str, str][source]

Same as Parameters.finish(), but adds Parameters.level_secret instead.

Returns

Fully formatted dictionary.

Return type

dict

finish_login() → Dict[str, str][source]

Same as Parameters.finish(), but adds Parameters.login_secret instead.

Returns

Fully formatted dictionary.

Return type

dict

finish_mod() → Dict[str, str][source]

Same as Parameters.finish(), but adds Parameters.mod_secret instead.

Returns

Fully formatted dictionary.

Return type

dict

close() → Dict[str, str][source]

Finishes creating parameters dictionary, without adding anything.

Returns

Fully formatted parameters dictionary.

Return type

dict

put_definer(for_what: str, item: Any) → gd.utils.params.Parameters[source]

Puts a definer.

Parameters
  • for_what (str) –

    Type of parameter to add, represented as string.

    Follows this mapping:

    'song'       -> 'songID'
    'user'       -> 'targetAccountID'
    'search'     -> 'str'
    'gauntlet'   -> 'gauntlet'
    'password'   -> 'password'
    'levelid'    -> 'levelID'
    'accountid'  -> 'accountID'
    'itemid'     -> 'itemID'
    'messageid'  -> 'messageID'
    'commentid'  -> 'commentID'
    'requestid'  -> 'requestID'
    'userid'     -> 'userID'
    'reward'     -> 'rewardType'
    'stars'      -> 'stars'
    'rating'     -> 'rating'
    

  • item (Any) – Parameter to put.

Returns

self

Return type

Parameters

put_recipient(account_id: int) → gd.utils.params.Parameters[source]

Puts recipient of a message/friend request/…

Parameters

account_id (int) – An account ID of the recipient.

Returns

self

Return type

Parameters

put_is_sender(t: str) → gd.utils.params.Parameters[source]

Puts ‘isSender’ parameter.

Parameters

t (str) – Either 'normal' or 'sent'. If 'sent', adds isSender=1.

Returns

self

Return type

Parameters

put_message(subject: str, body: str) → gd.utils.params.Parameters[source]

Puts message’s subject and body.

Parameters
  • subject (str) – NOT ENCODED message subject.

  • body (str) – NOT ENCODED message body.

Returns

self

Return type

Parameters

put_password(item: str) → gd.utils.params.Parameters[source]

Self explanatory. Puts ‘gjp’ parameter.

Parameters

item (str) – A password to put.

Returns

self

Return type

Parameters

put_username(item: str) → gd.utils.params.Parameters[source]

Self explanatory. Puts ‘userName’ parameter.

Parameters

item (str) – A username to put.

Returns

self

Return type

Parameters

put_fr_comment(item: str) → gd.utils.params.Parameters[source]

Pretty self explanatory. Puts ‘comment’ parameter.

Parameters

item (str) – A comment to put.

Returns

self

Return type

Parameters

put_save_data(data_seq: Sequence[Union[bytes, str]]) → gd.utils.params.Parameters[source]

Self explanatory. Puts ‘saveData’ parameter.

Parameters

data_seq (Sequence[Union[bytes, str]]) – Data to put.

Returns

self

Return type

Parameters

put_type(number: Union[int, str] = 0) → gd.utils.params.Parameters[source]

Sets ‘type’ parameter to a given number or string.

Parameters

number (Union[int, str]) – A number or string to set type to.

Returns

self

Return type

Parameters

put_percent(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘percent’.

put_page(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘page’.

put_weekly(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘weekly’.

put_total(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘total’.

put_mode(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘mode’.

put_like(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘like’.

put_count(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘count’.

put_feature(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘feature’.

put_special(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘special’.

put_local(number: int = 0) → gd.utils.params.Parameters[source]

Same as Parameters.put_type(), but for ‘local’.

put_seed(seed: Union[int, str], prefix: str = 'seed', suffix: str = '') → gd.utils.params.Parameters[source]

Puts '{prefix}{suffix}' parameter.

Parameters
  • seed (Union[int, str]) – The seed to put, as string.

  • prefix (Any) – The prefix to use as a parameter.

  • suffix (Any) – The suffix to append to prefix.

Returns

self

Return type

Parameters

put_rs(rs: str) → gd.utils.params.Parameters[source]

Self explanatory. Puts 'rs' parameter.

Parameters

rs (str) – Random Seed parameter, as string.

Returns

self

Return type

Parameters

put_chk(chk: str) → gd.utils.params.Parameters[source]

Self explanatory. Puts 'chk' parameter.

Parameters

chk (str) – Check parameter, as string.

Returns

self

Return type

Parameters

put_comment(content: str, values: List[Any]) → gd.utils.params.Parameters[source]

Puts a comment.

Parameters
  • content (str) – The content of the comment.

  • values (list) – A list of values to generate a chk parameter with.

Returns

self

Return type

Parameters

comment_for(type: str, number: int = 0) → gd.utils.params.Parameters[source]

Defines type of a comment, and puts parameters required for it.

Parameters
  • type (str) – A type of the comment, either 'profile' or 'level'. 'profile' sets cType=1, while 'level' sets levelID=str(number).

  • number (int) – A number to put. Used as mentioned above.

Returns

self

Return type

Parameters

put_login_definer(username: str, password: str) → gd.utils.params.Parameters[source]

Puts parameters for a login request.

Parameters
Returns

self

Return type

Parameters

put_udid(udid_string: Optional[str] = None) → gd.utils.params.Parameters[source]

Puts 'udid' parameter.

Parameters

udid_string (str) – UDID to put.

Returns

self

Return type

Parameters

put_uuid(uuid_string: Optional[str] = None) → gd.utils.params.Parameters[source]

Same as Parameters.put_udid(), but puts 'uuid'.

Parameters

uuid_string (str) – UUID to put.

Returns

self

Return type

Parameters

put_level_desc(content: str) → gd.utils.params.Parameters[source]

Encodes given content and puts 'levelDesc'.

Parameters

content (str) – Content of the new description, NOT encoded in Base64.

Returns

self

Return type

Parameters

put_profile_upd(msg: int, friend_req: int, comments: int, youtube: str, twitter: str, twitch: str) → gd.utils.params.Parameters[source]

Puts all parameters required for profile update.

Parameters
  • msg (int) – Message indicator. Mapped in as ‘mS’.

  • friend_req (int) – Friend request indicator. Mapped in as ‘frS’.

  • comments (int) – Comment history indicator. Mapped in as ‘cS’.

  • youtube (str) – Youtube username. Mapped in as ‘yt’.

  • twitter (str) – Twitter username. Mapped in as ‘twitter’.

  • twitch (str) – Twitch username. Mapped in as ‘twitch’.

Returns

self

Return type

Parameters

put_filters(filters: Union[dict, gd.utils.filters.Filters]) → gd.utils.params.Parameters[source]

Appends level filters.

Parameters

filters (Union[dict, Filters]) – All filters as a dictionary or as a Filters object.

Returns

self

Return type

Parameters

get_sent(indicator: int) → gd.utils.params.Parameters[source]

Put 'getSent' parameter if needed.

Parameters

indicator (int) – Indicates whether to put the parameter.

Returns

self

Return type

Parameters

Ciphers and Coders

class gd.utils.crypto.xor_cipher.XORCipher[source]
staticmethod cipher(key: Union[bytes, int, str], string: str)str[source]

Ciphers a string with XOR using key given.

Due to the fact that XOR ^ operation is being used, the following is true:

xor = XORCipher
xor.cipher('93582', xor.cipher('93582', 'NeKit')) == 'NeKit'  # True
Parameters
  • key (Union[bytes, int, str]) – A key to XOR cipher with, e.g. '59361'.

  • string (str) – A string to apply XOR on.

Returns

A string after XOR operation.

Return type

str

gd.xor

alias of gd.utils.crypto.xor_cipher.XORCipher

class gd.Coder[source]
classmethod gen_rs(length: int = 10, charset: str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')str[source]

Generates a random string of required length.

Parameters
  • length (int) – Amount of characters for a string to have.

  • charset (str) – Character set to use. [A-Za-z0-9] by default.

Returns

Generated string.

Return type

str

classmethod encode(type: str, string: str)str[source]

Encodes a string, combining XOR and Base64 encode methods.

Used in different aspects of gd.py.

Parameters
  • type (str) – String representation of type, e.g. 'levelpass'. Used to define a XOR key.

  • string (str) – String to encode.

Returns

Encoded string.

Return type

str

classmethod decode(type: str, string: str, use_bytes: bool = False)str[source]

Decodes a XOR -> Base64 ciphered string.

Note

Due to the fact that decode and encode work almost the same, the following is true:

Coder.decode('message', Coder.encode('message', 'NeKit')) == 'NeKit'  # True
Parameters
  • type (str) – String representation of a type, e.g. 'level'. Used to define a XOR key.

  • string (str) – String to decode.

Returns

Decoded string.

Return type

str

classmethod gen_chk(type: str, values: List[Union[int, str]])str[source]

Generates a “chk” value, used in different requests to GD servers.

The method is: combine_values -> add salt -> sha1 hash -> XOR -> Base64 encode -> return

Parameters
  • type (str) – String representation of type, e.g. 'comment'. Used to define salt and XOR key.

  • values (List[Union[int, str]]) – List of values to generate a chk with.

Returns

Generated 'chk', represented as string.

Return type

str

classmethod unzip(string: Union[bytes, str]) → Union[bytes, str][source]

Decompresses a level string.

Used to unzip level data.

Parameters

string (Union[bytes, str]) – String to unzip, encoded in Base64.

Returns

Unzipped level data, as a stream.

Return type

Union[bytes, str]