Entities

Entities (or, simply, objects) are the essential part of gd.py.

Main interaction with data returned from GD servers is achieved through them.

A base class for all entities is AbstractEntity.

class gd.AbstractEntity(*, client: Optional[Client] = None, **options)[source]

Class that represents Abstract Entity. This is a base for many gd.py objects.

x == y

Check if two objects are equal. Compared by hash and type.

x != y

Check if two objects are not equal.

hash(x)

Returns hash(self.hash_str).

update_inner(**options: Any)AbstractEntityT[source]

Update self.options with options.

classmethod from_model(model: gd.model_backend.Model, *args, **kwargs)AbstractEntityT[source]

Create new entity from given model, args and kwargs.

classmethod from_models(*models: gd.model_backend.Model, **kwargs)AbstractEntityT[source]

Create new entity from given models by calling from_model with kwargs.

classmethod from_dicts(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT[source]

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_dict(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

to_dict()Dict[str, Any][source]

Convert the entity to a dictionary.

property hash_str

String used for hashing, with format <Class(ID->id)>.

Type

str

property id

ID of the Entity.

Type

int

property client

Client attached to this object. This checks if client is not present, and raises ClientException in that case.

Type

Client

property client_unchecked

Client attached to this object.

Type

Optional[Client]

attach_client(client: Optional[Client] = None)AbstractEntityT[source]

Attach client to self.

Parameters

client (Optional[gd.Client]) – Client to attach. If None or not given, will be detached.

Returns

This abstract entity.

Return type

AbstractEntity

detach_client()AbstractEntityT[source]

Detach client from self.

Same as calling:

self.attach_client(None)
Returns

This abstract entity.

Return type

AbstractEntity