Skip to content

Forum API Models

CommunityContentSortMode

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
300
301
302
303
304
305
306
307
308
309
310
class CommunityContentSortMode(BaseEnum):
    """
    _No description given by bungie._
    """

    TRENDING = 0
    """_No description given by bungie._ """
    LATEST = 1
    """_No description given by bungie._ """
    HIGHEST_RATED = 2
    """_No description given by bungie._ """

HIGHEST_RATED = 2 class-attribute instance-attribute

No description given by bungie.

LATEST = 1 class-attribute instance-attribute

No description given by bungie.

TRENDING = 0 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumMediaType

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
119
120
121
122
123
124
125
126
127
128
129
130
131
class ForumMediaType(BaseEnum):
    """
    _No description given by bungie._
    """

    NONE = 0
    """_No description given by bungie._ """
    IMAGE = 1
    """_No description given by bungie._ """
    VIDEO = 2
    """_No description given by bungie._ """
    YOUTUBE = 3
    """_No description given by bungie._ """

IMAGE = 1 class-attribute instance-attribute

No description given by bungie.

NONE = 0 class-attribute instance-attribute

No description given by bungie.

VIDEO = 2 class-attribute instance-attribute

No description given by bungie.

YOUTUBE = 3 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumPostPopularity

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class ForumPostPopularity(BaseEnum):
    """
    _No description given by bungie._
    """

    EMPTY = 0
    """_No description given by bungie._ """
    DEFAULT = 1
    """_No description given by bungie._ """
    DISCUSSED = 2
    """_No description given by bungie._ """
    COOL_STORY = 3
    """_No description given by bungie._ """
    HEATING_UP = 4
    """_No description given by bungie._ """
    HOT = 5
    """_No description given by bungie._ """

COOL_STORY = 3 class-attribute instance-attribute

No description given by bungie.

DEFAULT = 1 class-attribute instance-attribute

No description given by bungie.

DISCUSSED = 2 class-attribute instance-attribute

No description given by bungie.

EMPTY = 0 class-attribute instance-attribute

No description given by bungie.

HEATING_UP = 4 class-attribute instance-attribute

No description given by bungie.

HOT = 5 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumPostSortEnum

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
289
290
291
292
293
294
295
296
297
class ForumPostSortEnum(BaseEnum):
    """
    _No description given by bungie._
    """

    DEFAULT = 0
    """_No description given by bungie._ """
    OLDEST_FIRST = 1
    """_No description given by bungie._ """

DEFAULT = 0 class-attribute instance-attribute

No description given by bungie.

OLDEST_FIRST = 1 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumRecruitmentDetail

Bases: BaseModel

No description given by bungie.

None Attributes: approved: No description given by bungie. conversation_id: No description given by bungie. fireteam: No description given by bungie. intensity: No description given by bungie. kicked_player_ids: No description given by bungie. microphone_required: No description given by bungie. player_slots_remaining: No description given by bungie. player_slots_total: No description given by bungie. tone: No description given by bungie. topic_id: No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
@custom_define()
class ForumRecruitmentDetail(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        approved: _No description given by bungie._
        conversation_id: _No description given by bungie._
        fireteam: _No description given by bungie._
        intensity: _No description given by bungie._
        kicked_player_ids: _No description given by bungie._
        microphone_required: _No description given by bungie._
        player_slots_remaining: _No description given by bungie._
        player_slots_total: _No description given by bungie._
        tone: _No description given by bungie._
        topic_id: _No description given by bungie._
    """

    approved: bool = custom_field()
    conversation_id: int = custom_field(metadata={"int64": True})
    fireteam: list["GeneralUser"] = custom_field(metadata={"type": """list[GeneralUser]"""})
    intensity: Union["ForumRecruitmentIntensityLabel", int] = custom_field(
        converter=enum_converter("ForumRecruitmentIntensityLabel")
    )
    kicked_player_ids: list[int] = custom_field(metadata={"type": """list[int]"""})
    microphone_required: bool = custom_field()
    player_slots_remaining: int = custom_field()
    player_slots_total: int = custom_field()
    tone: Union["ForumRecruitmentToneLabel", int] = custom_field(converter=enum_converter("ForumRecruitmentToneLabel"))
    topic_id: int = custom_field(metadata={"int64": True})

_convert_to_bungie_case(string) cached staticmethod

Convert a string to how it is represented by bungie: my_name_string -> myNameString

Parameters:

Name Type Description Default
string str

The og string

required

Returns:

Type Description
str

The bungie string

Source code in src/bungio/models/base.py
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
@staticmethod
@functools.cache
def _convert_to_bungie_case(string: str) -> str:
    """
    Convert a string to how it is represented by bungie: my_name_string -> myNameString

    Args:
        string: The og string

    Returns:
        The bungie string
    """

    if "_" not in string:
        return string
    else:
        split = string.split("_")
        return "".join((split[0], *(s.capitalize() for s in split[1:])))

fetch_manifest_information(include=None, exclude=None, _cache=None) async

Fill the model in-place with information from the manifest.

Example

Fill every attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information()
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is not None

Fill only some attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is None
1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is None
assert model.manifest_reference_id is not None

Parameters:

Name Type Description Default
include Optional[list[str]]

A list of attributes you want to include. Excludes everything not mentioned

None
exclude Optional[list[str]]

A list of attributes you want to exclude. Includes everything not mentioned

None
Source code in src/bungio/models/base.py
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
async def fetch_manifest_information(
    self, include: Optional[list[str]] = None, exclude: Optional[list[str]] = None, _cache: Optional[dict] = None
):
    """
    Fill the model in-place with information from the manifest.

    Example:
        Fill every attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information()
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is not None
        ```

        Fill only some attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is None
        ```
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is None
        assert model.manifest_reference_id is not None
        ```

    Args:
        include: A list of attributes you want to include. Excludes everything not mentioned
        exclude:  A list of attributes you want to exclude. Includes everything not mentioned
    """

    if not isinstance(self._client.manifest_storage, AsyncEngine):
        raise ValueError("Client.manifest_storage must be set up to use this")

    if not _cache:
        _cache = {}

    class_definition = attrs.fields_dict(type(self))  # noqa

    # loop through the class attributes
    for name in self.__dir__():
        if name.startswith("__"):
            continue

        if include and name not in include:
            continue
        if exclude and name in exclude:
            continue

        # manifest entries
        if name.startswith("manifest_"):
            striped_name = name.removeprefix("manifest_")
            value = getattr(self, striped_name)

            if value is MISSING:
                return

            # check the cache to avoid infinite recursion
            if cached := _cache.get(value, None):
                manifest_value = cached

            else:
                attr_definition = class_definition[name]
                manifest_class_name = attr_definition.type.__str__().removesuffix("')]").split("'")[-1]
                manifest_value = await self._client.manifest.fetch(
                    manifest_class=getattr(models, manifest_class_name), value=value
                )

                _cache[value] = manifest_value

                # check if the model has manifest models itself
                if manifest_value:
                    await manifest_value.fetch_manifest_information(_cache=_cache)

            setattr(self, name, manifest_value)

        # sub models which may have manifest entries too
        elif hasattr((value := getattr(self, name)), "fetch_manifest_information"):
            await value.fetch_manifest_information(_cache=_cache)

from_dict(data, client, recursive=False, *args, **kwargs) async classmethod

Convert json data to this model

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required
recursive bool

If this was called recursively

False

Returns:

Type Description
BaseModel

The model

Source code in src/bungio/models/base.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@classmethod
async def from_dict(cls, data: dict, client: "Client", recursive: bool = False, *args, **kwargs) -> BaseModel:
    """
    Convert json data to this model

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj
        recursive: If this was called recursively

    Returns:
        The model
    """

    if isinstance(data, cls):
        return data

    if not isinstance(data, dict):
        raise ValueError

    if "Response" in data:
        data = data["Response"]

    # also use the kwargs as data
    data = kwargs | data
    data = cls.process_dict(data=data, client=client)

    prepared = {}
    for name, field in attrs.fields_dict(cls).items():
        if field.init and name != "_client":
            default = field.default

            # get the value we want. This also skips the manifest_... entries since they have no value and a default
            bungie_name = cls._convert_to_bungie_case(name)
            value = data.get(bungie_name, attrs.NOTHING)

            # bungie is veeery inconsistent and sometimes like to start their params with an upper case for some reason
            # only sometimes tho :)
            if value is attrs.NOTHING:
                value = data.get(f"{bungie_name[0].capitalize()}{bungie_name[1:]}", attrs.NOTHING)

            # sadly bungie sometimes does not return info without marking that fact in the api specs
            if value is attrs.NOTHING and default is attrs.NOTHING:
                default = MISSING

            if value is attrs.NOTHING:
                value = default

            else:
                value = await cls._convert_to_type(
                    field_type=field.type, field_metadata=field.metadata, value=value, client=client
                )

            # set the attr
            prepared[name] = value

    res = cls(**prepared)  # noqa

    # fill the manifest information
    if not recursive and res._client.always_return_manifest_information:
        await res.fetch_manifest_information()

    return res

process_dict(data, client, *args, **kwargs) staticmethod

Model specific cleanup

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
dict

Clean json

Source code in src/bungio/models/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
@staticmethod
def process_dict(data: dict, client: "Client", *args, **kwargs) -> dict:
    """
    Model specific cleanup

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj

    Returns:
        Clean json
    """
    return data

to_dict(_return_to_bungie_case=True)

Convert the model into a dict representation bungie accepts

Returns:

Type Description
dict

A dict which can be sent to bungie

Source code in src/bungio/models/base.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def to_dict(self, _return_to_bungie_case: bool = True) -> dict:
    """
    Convert the model into a dict representation bungie accepts

    Returns:
        A dict which can be sent to bungie
    """

    result = {}

    for name, field in attrs.fields_dict(type(self)).items():
        if name.startswith("_") or name.startswith("manifest_"):
            continue

        value = getattr(self, name)
        if _return_to_bungie_case:
            name = self._convert_to_bungie_case(name)

        if inspect.ismethod(value) or inspect.isfunction(value):
            continue

        elif isinstance(value, dict):
            raise NotImplementedError(
                "Nested dict conversion is not currently implemented, since bungie does never require that info"
            )

        elif isinstance(value, list):
            list_results = []
            for entry in value:
                if hasattr(entry, "to_dict"):
                    list_results.append(entry.to_dict())
                else:
                    list_results.append(entry)

            result[name] = list_results

        else:
            if hasattr(value, "to_dict"):
                result[name] = value.to_dict()
            else:
                # convert to string if they are int64
                if field.metadata.get("int64", None) is True:
                    value = str(value)

                result[name] = value

    return result

ForumRecruitmentIntensityLabel

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
263
264
265
266
267
268
269
270
271
272
273
class ForumRecruitmentIntensityLabel(BaseEnum):
    """
    _No description given by bungie._
    """

    NONE = 0
    """_No description given by bungie._ """
    CASUAL = 1
    """_No description given by bungie._ """
    PROFESSIONAL = 2
    """_No description given by bungie._ """

CASUAL = 1 class-attribute instance-attribute

No description given by bungie.

NONE = 0 class-attribute instance-attribute

No description given by bungie.

PROFESSIONAL = 2 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumRecruitmentToneLabel

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
276
277
278
279
280
281
282
283
284
285
286
class ForumRecruitmentToneLabel(BaseEnum):
    """
    _No description given by bungie._
    """

    NONE = 0
    """_No description given by bungie._ """
    FAMILY_FRIENDLY = 1
    """_No description given by bungie._ """
    ROWDY = 2
    """_No description given by bungie._ """

FAMILY_FRIENDLY = 1 class-attribute instance-attribute

No description given by bungie.

NONE = 0 class-attribute instance-attribute

No description given by bungie.

ROWDY = 2 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumTopicsCategoryFiltersEnum

Bases: BaseFlagEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class ForumTopicsCategoryFiltersEnum(BaseFlagEnum):
    """
    _No description given by bungie._
    """

    NONE = 0
    """_No description given by bungie._ """
    LINKS = 1
    """_No description given by bungie._ """
    QUESTIONS = 2
    """_No description given by bungie._ """
    ANSWERED_QUESTIONS = 4
    """_No description given by bungie._ """
    MEDIA = 8
    """_No description given by bungie._ """
    TEXT_ONLY = 16
    """_No description given by bungie._ """
    ANNOUNCEMENT = 32
    """_No description given by bungie._ """
    BUNGIE_OFFICIAL = 64
    """_No description given by bungie._ """
    POLLS = 128
    """_No description given by bungie._ """

ANNOUNCEMENT = 32 class-attribute instance-attribute

No description given by bungie.

ANSWERED_QUESTIONS = 4 class-attribute instance-attribute

No description given by bungie.

BUNGIE_OFFICIAL = 64 class-attribute instance-attribute

No description given by bungie.

No description given by bungie.

MEDIA = 8 class-attribute instance-attribute

No description given by bungie.

NONE = 0 class-attribute instance-attribute

No description given by bungie.

POLLS = 128 class-attribute instance-attribute

No description given by bungie.

QUESTIONS = 2 class-attribute instance-attribute

No description given by bungie.

TEXT_ONLY = 16 class-attribute instance-attribute

No description given by bungie.

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumTopicsQuickDateEnum

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class ForumTopicsQuickDateEnum(BaseEnum):
    """
    _No description given by bungie._
    """

    ALL = 0
    """_No description given by bungie._ """
    LAST_YEAR = 1
    """_No description given by bungie._ """
    LAST_MONTH = 2
    """_No description given by bungie._ """
    LAST_WEEK = 3
    """_No description given by bungie._ """
    LAST_DAY = 4
    """_No description given by bungie._ """

ALL = 0 class-attribute instance-attribute

No description given by bungie.

LAST_DAY = 4 class-attribute instance-attribute

No description given by bungie.

LAST_MONTH = 2 class-attribute instance-attribute

No description given by bungie.

LAST_WEEK = 3 class-attribute instance-attribute

No description given by bungie.

LAST_YEAR = 1 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

ForumTopicsSortEnum

Bases: BaseEnum

No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class ForumTopicsSortEnum(BaseEnum):
    """
    _No description given by bungie._
    """

    DEFAULT = 0
    """_No description given by bungie._ """
    LAST_REPLIED = 1
    """_No description given by bungie._ """
    MOST_REPLIED = 2
    """_No description given by bungie._ """
    POPULARITY = 3
    """_No description given by bungie._ """
    CONTROVERSIALITY = 4
    """_No description given by bungie._ """
    LIKED = 5
    """_No description given by bungie._ """
    HIGHEST_RATED = 6
    """_No description given by bungie._ """
    MOST_UPVOTED = 7
    """_No description given by bungie._ """

CONTROVERSIALITY = 4 class-attribute instance-attribute

No description given by bungie.

DEFAULT = 0 class-attribute instance-attribute

No description given by bungie.

HIGHEST_RATED = 6 class-attribute instance-attribute

No description given by bungie.

LAST_REPLIED = 1 class-attribute instance-attribute

No description given by bungie.

LIKED = 5 class-attribute instance-attribute

No description given by bungie.

MOST_REPLIED = 2 class-attribute instance-attribute

No description given by bungie.

MOST_UPVOTED = 7 class-attribute instance-attribute

No description given by bungie.

POPULARITY = 3 class-attribute instance-attribute

No description given by bungie.

display_name property

Format the instance name so that it looks like in-game.

Example

name="HAND_CANNON" -> "Hand Cannon"

Returns:

Type Description
str

The formatted name

from_dict(data, client, *args, **kwargs) async classmethod

Convert data to this enum

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
EnumMixin | UnknownEnumValue

The enum

Source code in src/bungio/models/base.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@classmethod
async def from_dict(cls, data: int | str, client: "Client", *args, **kwargs) -> EnumMixin | UnknownEnumValue:
    """
    Convert data to this enum

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        The enum
    """

    if isinstance(data, cls):
        return data

    data = cls.process_dict(data=data, client=client)

    # catch unknown values
    try:
        return cls(data)
    except ValueError:
        return UnknownEnumValue(value=data, enum=cls)

process_dict(data, client, *args, **kwargs) staticmethod

Enum specific cleanup

Parameters:

Name Type Description Default
data int | str

The int / str representation of the enum, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
int | str

Clean int / str representation

Source code in src/bungio/models/base.py
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def process_dict(data: int | str, client: "Client", *args, **kwargs) -> int | str:
    """
    Enum specific cleanup

    Args:
        data: The int / str representation of the enum, usually received by bungie
        client: The client obj

    Returns:
        Clean int / str representation
    """
    return data

to_dict()

Convert the enum into a representation bungie accepts

Returns:

Type Description
Any

The value which can be sent to bungie

Source code in src/bungio/models/base.py
172
173
174
175
176
177
178
179
180
def to_dict(self) -> Any:
    """
    Convert the enum into a representation bungie accepts

    Returns:
        The value which can be sent to bungie
    """

    return self.value

PollResponse

Bases: BaseModel

No description given by bungie.

None Attributes: results: No description given by bungie. topic_id: No description given by bungie. total_votes: No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@custom_define()
class PollResponse(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        results: _No description given by bungie._
        topic_id: _No description given by bungie._
        total_votes: _No description given by bungie._
    """

    results: list["PollResult"] = custom_field(metadata={"type": """list[PollResult]"""})
    topic_id: int = custom_field(metadata={"int64": True})
    total_votes: int = custom_field()

_convert_to_bungie_case(string) cached staticmethod

Convert a string to how it is represented by bungie: my_name_string -> myNameString

Parameters:

Name Type Description Default
string str

The og string

required

Returns:

Type Description
str

The bungie string

Source code in src/bungio/models/base.py
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
@staticmethod
@functools.cache
def _convert_to_bungie_case(string: str) -> str:
    """
    Convert a string to how it is represented by bungie: my_name_string -> myNameString

    Args:
        string: The og string

    Returns:
        The bungie string
    """

    if "_" not in string:
        return string
    else:
        split = string.split("_")
        return "".join((split[0], *(s.capitalize() for s in split[1:])))

fetch_manifest_information(include=None, exclude=None, _cache=None) async

Fill the model in-place with information from the manifest.

Example

Fill every attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information()
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is not None

Fill only some attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is None
1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is None
assert model.manifest_reference_id is not None

Parameters:

Name Type Description Default
include Optional[list[str]]

A list of attributes you want to include. Excludes everything not mentioned

None
exclude Optional[list[str]]

A list of attributes you want to exclude. Includes everything not mentioned

None
Source code in src/bungio/models/base.py
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
async def fetch_manifest_information(
    self, include: Optional[list[str]] = None, exclude: Optional[list[str]] = None, _cache: Optional[dict] = None
):
    """
    Fill the model in-place with information from the manifest.

    Example:
        Fill every attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information()
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is not None
        ```

        Fill only some attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is None
        ```
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is None
        assert model.manifest_reference_id is not None
        ```

    Args:
        include: A list of attributes you want to include. Excludes everything not mentioned
        exclude:  A list of attributes you want to exclude. Includes everything not mentioned
    """

    if not isinstance(self._client.manifest_storage, AsyncEngine):
        raise ValueError("Client.manifest_storage must be set up to use this")

    if not _cache:
        _cache = {}

    class_definition = attrs.fields_dict(type(self))  # noqa

    # loop through the class attributes
    for name in self.__dir__():
        if name.startswith("__"):
            continue

        if include and name not in include:
            continue
        if exclude and name in exclude:
            continue

        # manifest entries
        if name.startswith("manifest_"):
            striped_name = name.removeprefix("manifest_")
            value = getattr(self, striped_name)

            if value is MISSING:
                return

            # check the cache to avoid infinite recursion
            if cached := _cache.get(value, None):
                manifest_value = cached

            else:
                attr_definition = class_definition[name]
                manifest_class_name = attr_definition.type.__str__().removesuffix("')]").split("'")[-1]
                manifest_value = await self._client.manifest.fetch(
                    manifest_class=getattr(models, manifest_class_name), value=value
                )

                _cache[value] = manifest_value

                # check if the model has manifest models itself
                if manifest_value:
                    await manifest_value.fetch_manifest_information(_cache=_cache)

            setattr(self, name, manifest_value)

        # sub models which may have manifest entries too
        elif hasattr((value := getattr(self, name)), "fetch_manifest_information"):
            await value.fetch_manifest_information(_cache=_cache)

from_dict(data, client, recursive=False, *args, **kwargs) async classmethod

Convert json data to this model

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required
recursive bool

If this was called recursively

False

Returns:

Type Description
BaseModel

The model

Source code in src/bungio/models/base.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@classmethod
async def from_dict(cls, data: dict, client: "Client", recursive: bool = False, *args, **kwargs) -> BaseModel:
    """
    Convert json data to this model

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj
        recursive: If this was called recursively

    Returns:
        The model
    """

    if isinstance(data, cls):
        return data

    if not isinstance(data, dict):
        raise ValueError

    if "Response" in data:
        data = data["Response"]

    # also use the kwargs as data
    data = kwargs | data
    data = cls.process_dict(data=data, client=client)

    prepared = {}
    for name, field in attrs.fields_dict(cls).items():
        if field.init and name != "_client":
            default = field.default

            # get the value we want. This also skips the manifest_... entries since they have no value and a default
            bungie_name = cls._convert_to_bungie_case(name)
            value = data.get(bungie_name, attrs.NOTHING)

            # bungie is veeery inconsistent and sometimes like to start their params with an upper case for some reason
            # only sometimes tho :)
            if value is attrs.NOTHING:
                value = data.get(f"{bungie_name[0].capitalize()}{bungie_name[1:]}", attrs.NOTHING)

            # sadly bungie sometimes does not return info without marking that fact in the api specs
            if value is attrs.NOTHING and default is attrs.NOTHING:
                default = MISSING

            if value is attrs.NOTHING:
                value = default

            else:
                value = await cls._convert_to_type(
                    field_type=field.type, field_metadata=field.metadata, value=value, client=client
                )

            # set the attr
            prepared[name] = value

    res = cls(**prepared)  # noqa

    # fill the manifest information
    if not recursive and res._client.always_return_manifest_information:
        await res.fetch_manifest_information()

    return res

process_dict(data, client, *args, **kwargs) staticmethod

Model specific cleanup

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
dict

Clean json

Source code in src/bungio/models/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
@staticmethod
def process_dict(data: dict, client: "Client", *args, **kwargs) -> dict:
    """
    Model specific cleanup

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj

    Returns:
        Clean json
    """
    return data

to_dict(_return_to_bungie_case=True)

Convert the model into a dict representation bungie accepts

Returns:

Type Description
dict

A dict which can be sent to bungie

Source code in src/bungio/models/base.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def to_dict(self, _return_to_bungie_case: bool = True) -> dict:
    """
    Convert the model into a dict representation bungie accepts

    Returns:
        A dict which can be sent to bungie
    """

    result = {}

    for name, field in attrs.fields_dict(type(self)).items():
        if name.startswith("_") or name.startswith("manifest_"):
            continue

        value = getattr(self, name)
        if _return_to_bungie_case:
            name = self._convert_to_bungie_case(name)

        if inspect.ismethod(value) or inspect.isfunction(value):
            continue

        elif isinstance(value, dict):
            raise NotImplementedError(
                "Nested dict conversion is not currently implemented, since bungie does never require that info"
            )

        elif isinstance(value, list):
            list_results = []
            for entry in value:
                if hasattr(entry, "to_dict"):
                    list_results.append(entry.to_dict())
                else:
                    list_results.append(entry)

            result[name] = list_results

        else:
            if hasattr(value, "to_dict"):
                result[name] = value.to_dict()
            else:
                # convert to string if they are int64
                if field.metadata.get("int64", None) is True:
                    value = str(value)

                result[name] = value

    return result

PollResult

Bases: BaseModel

No description given by bungie.

None Attributes: answer_slot: No description given by bungie. answer_text: No description given by bungie. last_vote_date: No description given by bungie. requesting_user_voted: No description given by bungie. votes: No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
@custom_define()
class PollResult(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        answer_slot: _No description given by bungie._
        answer_text: _No description given by bungie._
        last_vote_date: _No description given by bungie._
        requesting_user_voted: _No description given by bungie._
        votes: _No description given by bungie._
    """

    answer_slot: int = custom_field()
    answer_text: str = custom_field()
    last_vote_date: datetime = custom_field()
    requesting_user_voted: bool = custom_field()
    votes: int = custom_field()

_convert_to_bungie_case(string) cached staticmethod

Convert a string to how it is represented by bungie: my_name_string -> myNameString

Parameters:

Name Type Description Default
string str

The og string

required

Returns:

Type Description
str

The bungie string

Source code in src/bungio/models/base.py
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
@staticmethod
@functools.cache
def _convert_to_bungie_case(string: str) -> str:
    """
    Convert a string to how it is represented by bungie: my_name_string -> myNameString

    Args:
        string: The og string

    Returns:
        The bungie string
    """

    if "_" not in string:
        return string
    else:
        split = string.split("_")
        return "".join((split[0], *(s.capitalize() for s in split[1:])))

fetch_manifest_information(include=None, exclude=None, _cache=None) async

Fill the model in-place with information from the manifest.

Example

Fill every attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information()
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is not None

Fill only some attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is None
1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is None
assert model.manifest_reference_id is not None

Parameters:

Name Type Description Default
include Optional[list[str]]

A list of attributes you want to include. Excludes everything not mentioned

None
exclude Optional[list[str]]

A list of attributes you want to exclude. Includes everything not mentioned

None
Source code in src/bungio/models/base.py
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
async def fetch_manifest_information(
    self, include: Optional[list[str]] = None, exclude: Optional[list[str]] = None, _cache: Optional[dict] = None
):
    """
    Fill the model in-place with information from the manifest.

    Example:
        Fill every attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information()
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is not None
        ```

        Fill only some attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is None
        ```
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is None
        assert model.manifest_reference_id is not None
        ```

    Args:
        include: A list of attributes you want to include. Excludes everything not mentioned
        exclude:  A list of attributes you want to exclude. Includes everything not mentioned
    """

    if not isinstance(self._client.manifest_storage, AsyncEngine):
        raise ValueError("Client.manifest_storage must be set up to use this")

    if not _cache:
        _cache = {}

    class_definition = attrs.fields_dict(type(self))  # noqa

    # loop through the class attributes
    for name in self.__dir__():
        if name.startswith("__"):
            continue

        if include and name not in include:
            continue
        if exclude and name in exclude:
            continue

        # manifest entries
        if name.startswith("manifest_"):
            striped_name = name.removeprefix("manifest_")
            value = getattr(self, striped_name)

            if value is MISSING:
                return

            # check the cache to avoid infinite recursion
            if cached := _cache.get(value, None):
                manifest_value = cached

            else:
                attr_definition = class_definition[name]
                manifest_class_name = attr_definition.type.__str__().removesuffix("')]").split("'")[-1]
                manifest_value = await self._client.manifest.fetch(
                    manifest_class=getattr(models, manifest_class_name), value=value
                )

                _cache[value] = manifest_value

                # check if the model has manifest models itself
                if manifest_value:
                    await manifest_value.fetch_manifest_information(_cache=_cache)

            setattr(self, name, manifest_value)

        # sub models which may have manifest entries too
        elif hasattr((value := getattr(self, name)), "fetch_manifest_information"):
            await value.fetch_manifest_information(_cache=_cache)

from_dict(data, client, recursive=False, *args, **kwargs) async classmethod

Convert json data to this model

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required
recursive bool

If this was called recursively

False

Returns:

Type Description
BaseModel

The model

Source code in src/bungio/models/base.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@classmethod
async def from_dict(cls, data: dict, client: "Client", recursive: bool = False, *args, **kwargs) -> BaseModel:
    """
    Convert json data to this model

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj
        recursive: If this was called recursively

    Returns:
        The model
    """

    if isinstance(data, cls):
        return data

    if not isinstance(data, dict):
        raise ValueError

    if "Response" in data:
        data = data["Response"]

    # also use the kwargs as data
    data = kwargs | data
    data = cls.process_dict(data=data, client=client)

    prepared = {}
    for name, field in attrs.fields_dict(cls).items():
        if field.init and name != "_client":
            default = field.default

            # get the value we want. This also skips the manifest_... entries since they have no value and a default
            bungie_name = cls._convert_to_bungie_case(name)
            value = data.get(bungie_name, attrs.NOTHING)

            # bungie is veeery inconsistent and sometimes like to start their params with an upper case for some reason
            # only sometimes tho :)
            if value is attrs.NOTHING:
                value = data.get(f"{bungie_name[0].capitalize()}{bungie_name[1:]}", attrs.NOTHING)

            # sadly bungie sometimes does not return info without marking that fact in the api specs
            if value is attrs.NOTHING and default is attrs.NOTHING:
                default = MISSING

            if value is attrs.NOTHING:
                value = default

            else:
                value = await cls._convert_to_type(
                    field_type=field.type, field_metadata=field.metadata, value=value, client=client
                )

            # set the attr
            prepared[name] = value

    res = cls(**prepared)  # noqa

    # fill the manifest information
    if not recursive and res._client.always_return_manifest_information:
        await res.fetch_manifest_information()

    return res

process_dict(data, client, *args, **kwargs) staticmethod

Model specific cleanup

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
dict

Clean json

Source code in src/bungio/models/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
@staticmethod
def process_dict(data: dict, client: "Client", *args, **kwargs) -> dict:
    """
    Model specific cleanup

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj

    Returns:
        Clean json
    """
    return data

to_dict(_return_to_bungie_case=True)

Convert the model into a dict representation bungie accepts

Returns:

Type Description
dict

A dict which can be sent to bungie

Source code in src/bungio/models/base.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def to_dict(self, _return_to_bungie_case: bool = True) -> dict:
    """
    Convert the model into a dict representation bungie accepts

    Returns:
        A dict which can be sent to bungie
    """

    result = {}

    for name, field in attrs.fields_dict(type(self)).items():
        if name.startswith("_") or name.startswith("manifest_"):
            continue

        value = getattr(self, name)
        if _return_to_bungie_case:
            name = self._convert_to_bungie_case(name)

        if inspect.ismethod(value) or inspect.isfunction(value):
            continue

        elif isinstance(value, dict):
            raise NotImplementedError(
                "Nested dict conversion is not currently implemented, since bungie does never require that info"
            )

        elif isinstance(value, list):
            list_results = []
            for entry in value:
                if hasattr(entry, "to_dict"):
                    list_results.append(entry.to_dict())
                else:
                    list_results.append(entry)

            result[name] = list_results

        else:
            if hasattr(value, "to_dict"):
                result[name] = value.to_dict()
            else:
                # convert to string if they are int64
                if field.metadata.get("int64", None) is True:
                    value = str(value)

                result[name] = value

    return result

PostResponse

Bases: BaseModel

No description given by bungie.

None Attributes: ignore_status: No description given by bungie. is_active: No description given by bungie. is_announcement: No description given by bungie. is_pinned: No description given by bungie. last_reply_timestamp: No description given by bungie. latest_reply_author_id: No description given by bungie. latest_reply_post_id: No description given by bungie. locale: No description given by bungie. popularity: No description given by bungie. thumbnail: No description given by bungie. url_media_type: No description given by bungie. user_has_muted_post: No description given by bungie. user_has_rated: No description given by bungie. user_rating: No description given by bungie.

Source code in src/bungio/models/bungie/forum.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@custom_define()
class PostResponse(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        ignore_status: _No description given by bungie._
        is_active: _No description given by bungie._
        is_announcement: _No description given by bungie._
        is_pinned: _No description given by bungie._
        last_reply_timestamp: _No description given by bungie._
        latest_reply_author_id: _No description given by bungie._
        latest_reply_post_id: _No description given by bungie._
        locale: _No description given by bungie._
        popularity: _No description given by bungie._
        thumbnail: _No description given by bungie._
        url_media_type: _No description given by bungie._
        user_has_muted_post: _No description given by bungie._
        user_has_rated: _No description given by bungie._
        user_rating: _No description given by bungie._
    """

    ignore_status: "IgnoreResponse" = custom_field()
    is_active: bool = custom_field()
    is_announcement: bool = custom_field()
    is_pinned: bool = custom_field()
    last_reply_timestamp: datetime = custom_field()
    latest_reply_author_id: int = custom_field(metadata={"int64": True})
    latest_reply_post_id: int = custom_field(metadata={"int64": True})
    locale: str = custom_field()
    popularity: Union["ForumPostPopularity", int] = custom_field(converter=enum_converter("ForumPostPopularity"))
    thumbnail: str = custom_field()
    url_media_type: Union["ForumMediaType", int] = custom_field(converter=enum_converter("ForumMediaType"))
    user_has_muted_post: bool = custom_field()
    user_has_rated: bool = custom_field()
    user_rating: int = custom_field()

_convert_to_bungie_case(string) cached staticmethod

Convert a string to how it is represented by bungie: my_name_string -> myNameString

Parameters:

Name Type Description Default
string str

The og string

required

Returns:

Type Description
str

The bungie string

Source code in src/bungio/models/base.py
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
@staticmethod
@functools.cache
def _convert_to_bungie_case(string: str) -> str:
    """
    Convert a string to how it is represented by bungie: my_name_string -> myNameString

    Args:
        string: The og string

    Returns:
        The bungie string
    """

    if "_" not in string:
        return string
    else:
        split = string.split("_")
        return "".join((split[0], *(s.capitalize() for s in split[1:])))

fetch_manifest_information(include=None, exclude=None, _cache=None) async

Fill the model in-place with information from the manifest.

Example

Fill every attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information()
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is not None

Fill only some attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is None
1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is None
assert model.manifest_reference_id is not None

Parameters:

Name Type Description Default
include Optional[list[str]]

A list of attributes you want to include. Excludes everything not mentioned

None
exclude Optional[list[str]]

A list of attributes you want to exclude. Includes everything not mentioned

None
Source code in src/bungio/models/base.py
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
async def fetch_manifest_information(
    self, include: Optional[list[str]] = None, exclude: Optional[list[str]] = None, _cache: Optional[dict] = None
):
    """
    Fill the model in-place with information from the manifest.

    Example:
        Fill every attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information()
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is not None
        ```

        Fill only some attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is None
        ```
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is None
        assert model.manifest_reference_id is not None
        ```

    Args:
        include: A list of attributes you want to include. Excludes everything not mentioned
        exclude:  A list of attributes you want to exclude. Includes everything not mentioned
    """

    if not isinstance(self._client.manifest_storage, AsyncEngine):
        raise ValueError("Client.manifest_storage must be set up to use this")

    if not _cache:
        _cache = {}

    class_definition = attrs.fields_dict(type(self))  # noqa

    # loop through the class attributes
    for name in self.__dir__():
        if name.startswith("__"):
            continue

        if include and name not in include:
            continue
        if exclude and name in exclude:
            continue

        # manifest entries
        if name.startswith("manifest_"):
            striped_name = name.removeprefix("manifest_")
            value = getattr(self, striped_name)

            if value is MISSING:
                return

            # check the cache to avoid infinite recursion
            if cached := _cache.get(value, None):
                manifest_value = cached

            else:
                attr_definition = class_definition[name]
                manifest_class_name = attr_definition.type.__str__().removesuffix("')]").split("'")[-1]
                manifest_value = await self._client.manifest.fetch(
                    manifest_class=getattr(models, manifest_class_name), value=value
                )

                _cache[value] = manifest_value

                # check if the model has manifest models itself
                if manifest_value:
                    await manifest_value.fetch_manifest_information(_cache=_cache)

            setattr(self, name, manifest_value)

        # sub models which may have manifest entries too
        elif hasattr((value := getattr(self, name)), "fetch_manifest_information"):
            await value.fetch_manifest_information(_cache=_cache)

from_dict(data, client, recursive=False, *args, **kwargs) async classmethod

Convert json data to this model

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required
recursive bool

If this was called recursively

False

Returns:

Type Description
BaseModel

The model

Source code in src/bungio/models/base.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@classmethod
async def from_dict(cls, data: dict, client: "Client", recursive: bool = False, *args, **kwargs) -> BaseModel:
    """
    Convert json data to this model

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj
        recursive: If this was called recursively

    Returns:
        The model
    """

    if isinstance(data, cls):
        return data

    if not isinstance(data, dict):
        raise ValueError

    if "Response" in data:
        data = data["Response"]

    # also use the kwargs as data
    data = kwargs | data
    data = cls.process_dict(data=data, client=client)

    prepared = {}
    for name, field in attrs.fields_dict(cls).items():
        if field.init and name != "_client":
            default = field.default

            # get the value we want. This also skips the manifest_... entries since they have no value and a default
            bungie_name = cls._convert_to_bungie_case(name)
            value = data.get(bungie_name, attrs.NOTHING)

            # bungie is veeery inconsistent and sometimes like to start their params with an upper case for some reason
            # only sometimes tho :)
            if value is attrs.NOTHING:
                value = data.get(f"{bungie_name[0].capitalize()}{bungie_name[1:]}", attrs.NOTHING)

            # sadly bungie sometimes does not return info without marking that fact in the api specs
            if value is attrs.NOTHING and default is attrs.NOTHING:
                default = MISSING

            if value is attrs.NOTHING:
                value = default

            else:
                value = await cls._convert_to_type(
                    field_type=field.type, field_metadata=field.metadata, value=value, client=client
                )

            # set the attr
            prepared[name] = value

    res = cls(**prepared)  # noqa

    # fill the manifest information
    if not recursive and res._client.always_return_manifest_information:
        await res.fetch_manifest_information()

    return res

process_dict(data, client, *args, **kwargs) staticmethod

Model specific cleanup

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
dict

Clean json

Source code in src/bungio/models/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
@staticmethod
def process_dict(data: dict, client: "Client", *args, **kwargs) -> dict:
    """
    Model specific cleanup

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj

    Returns:
        Clean json
    """
    return data

to_dict(_return_to_bungie_case=True)

Convert the model into a dict representation bungie accepts

Returns:

Type Description
dict

A dict which can be sent to bungie

Source code in src/bungio/models/base.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def to_dict(self, _return_to_bungie_case: bool = True) -> dict:
    """
    Convert the model into a dict representation bungie accepts

    Returns:
        A dict which can be sent to bungie
    """

    result = {}

    for name, field in attrs.fields_dict(type(self)).items():
        if name.startswith("_") or name.startswith("manifest_"):
            continue

        value = getattr(self, name)
        if _return_to_bungie_case:
            name = self._convert_to_bungie_case(name)

        if inspect.ismethod(value) or inspect.isfunction(value):
            continue

        elif isinstance(value, dict):
            raise NotImplementedError(
                "Nested dict conversion is not currently implemented, since bungie does never require that info"
            )

        elif isinstance(value, list):
            list_results = []
            for entry in value:
                if hasattr(entry, "to_dict"):
                    list_results.append(entry.to_dict())
                else:
                    list_results.append(entry)

            result[name] = list_results

        else:
            if hasattr(value, "to_dict"):
                result[name] = value.to_dict()
            else:
                # convert to string if they are int64
                if field.metadata.get("int64", None) is True:
                    value = str(value)

                result[name] = value

    return result

PostSearchResponse

Bases: BaseModel

No description given by bungie.

None Attributes: authors: No description given by bungie. available_pages: No description given by bungie. groups: No description given by bungie. has_more: No description given by bungie. polls: No description given by bungie. query: No description given by bungie. recruitment_details: No description given by bungie. related_posts: No description given by bungie. replacement_continuation_token: No description given by bungie. results: No description given by bungie. searched_tags: No description given by bungie. total_results: No description given by bungie. use_total_results: If useTotalResults is true, then totalResults represents an accurate count. If False, it does not, and may be estimated/only the size of the current page. Either way, you should probably always only trust hasMore. This is a long-held historical throwback to when we used to do paging with known total results. Those queries toasted our database, and we were left to hastily alter our endpoints and create backward- compatible shims, of which useTotalResults is one.

Source code in src/bungio/models/bungie/forum.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@custom_define()
class PostSearchResponse(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        authors: _No description given by bungie._
        available_pages: _No description given by bungie._
        groups: _No description given by bungie._
        has_more: _No description given by bungie._
        polls: _No description given by bungie._
        query: _No description given by bungie._
        recruitment_details: _No description given by bungie._
        related_posts: _No description given by bungie._
        replacement_continuation_token: _No description given by bungie._
        results: _No description given by bungie._
        searched_tags: _No description given by bungie._
        total_results: _No description given by bungie._
        use_total_results: If useTotalResults is true, then totalResults represents an accurate count. If False, it does not, and may be estimated/only the size of the current page. Either way, you should probably always only trust hasMore. This is a long-held historical throwback to when we used to do paging with known total results. Those queries toasted our database, and we were left to hastily alter our endpoints and create backward- compatible shims, of which useTotalResults is one.
    """

    authors: list["GeneralUser"] = custom_field(metadata={"type": """list[GeneralUser]"""})
    available_pages: int = custom_field()
    groups: list["GroupResponse"] = custom_field(metadata={"type": """list[GroupResponse]"""})
    has_more: bool = custom_field()
    polls: list["PollResponse"] = custom_field(metadata={"type": """list[PollResponse]"""})
    query: "PagedQuery" = custom_field()
    recruitment_details: list["ForumRecruitmentDetail"] = custom_field(
        metadata={"type": """list[ForumRecruitmentDetail]"""}
    )
    related_posts: list["PostResponse"] = custom_field(metadata={"type": """list[PostResponse]"""})
    replacement_continuation_token: str = custom_field()
    results: list["PostResponse"] = custom_field(metadata={"type": """list[PostResponse]"""})
    searched_tags: list["TagResponse"] = custom_field(metadata={"type": """list[TagResponse]"""})
    total_results: int = custom_field()
    use_total_results: bool = custom_field()

_convert_to_bungie_case(string) cached staticmethod

Convert a string to how it is represented by bungie: my_name_string -> myNameString

Parameters:

Name Type Description Default
string str

The og string

required

Returns:

Type Description
str

The bungie string

Source code in src/bungio/models/base.py
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
@staticmethod
@functools.cache
def _convert_to_bungie_case(string: str) -> str:
    """
    Convert a string to how it is represented by bungie: my_name_string -> myNameString

    Args:
        string: The og string

    Returns:
        The bungie string
    """

    if "_" not in string:
        return string
    else:
        split = string.split("_")
        return "".join((split[0], *(s.capitalize() for s in split[1:])))

fetch_manifest_information(include=None, exclude=None, _cache=None) async

Fill the model in-place with information from the manifest.

Example

Fill every attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information()
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is not None

Fill only some attribute

1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is not None
assert model.manifest_reference_id is None
1
2
3
4
model: DestinyHistoricalStatsActivity
await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
assert model.manifest_director_activity_hash is None
assert model.manifest_reference_id is not None

Parameters:

Name Type Description Default
include Optional[list[str]]

A list of attributes you want to include. Excludes everything not mentioned

None
exclude Optional[list[str]]

A list of attributes you want to exclude. Includes everything not mentioned

None
Source code in src/bungio/models/base.py
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
async def fetch_manifest_information(
    self, include: Optional[list[str]] = None, exclude: Optional[list[str]] = None, _cache: Optional[dict] = None
):
    """
    Fill the model in-place with information from the manifest.

    Example:
        Fill every attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information()
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is not None
        ```

        Fill only some attribute
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(include=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is not None
        assert model.manifest_reference_id is None
        ```
        ```py
        model: DestinyHistoricalStatsActivity
        await model.fetch_manifest_information(exclude=["manifest_director_activity_hash"])
        assert model.manifest_director_activity_hash is None
        assert model.manifest_reference_id is not None
        ```

    Args:
        include: A list of attributes you want to include. Excludes everything not mentioned
        exclude:  A list of attributes you want to exclude. Includes everything not mentioned
    """

    if not isinstance(self._client.manifest_storage, AsyncEngine):
        raise ValueError("Client.manifest_storage must be set up to use this")

    if not _cache:
        _cache = {}

    class_definition = attrs.fields_dict(type(self))  # noqa

    # loop through the class attributes
    for name in self.__dir__():
        if name.startswith("__"):
            continue

        if include and name not in include:
            continue
        if exclude and name in exclude:
            continue

        # manifest entries
        if name.startswith("manifest_"):
            striped_name = name.removeprefix("manifest_")
            value = getattr(self, striped_name)

            if value is MISSING:
                return

            # check the cache to avoid infinite recursion
            if cached := _cache.get(value, None):
                manifest_value = cached

            else:
                attr_definition = class_definition[name]
                manifest_class_name = attr_definition.type.__str__().removesuffix("')]").split("'")[-1]
                manifest_value = await self._client.manifest.fetch(
                    manifest_class=getattr(models, manifest_class_name), value=value
                )

                _cache[value] = manifest_value

                # check if the model has manifest models itself
                if manifest_value:
                    await manifest_value.fetch_manifest_information(_cache=_cache)

            setattr(self, name, manifest_value)

        # sub models which may have manifest entries too
        elif hasattr((value := getattr(self, name)), "fetch_manifest_information"):
            await value.fetch_manifest_information(_cache=_cache)

from_dict(data, client, recursive=False, *args, **kwargs) async classmethod

Convert json data to this model

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required
recursive bool

If this was called recursively

False

Returns:

Type Description
BaseModel

The model

Source code in src/bungio/models/base.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@classmethod
async def from_dict(cls, data: dict, client: "Client", recursive: bool = False, *args, **kwargs) -> BaseModel:
    """
    Convert json data to this model

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj
        recursive: If this was called recursively

    Returns:
        The model
    """

    if isinstance(data, cls):
        return data

    if not isinstance(data, dict):
        raise ValueError

    if "Response" in data:
        data = data["Response"]

    # also use the kwargs as data
    data = kwargs | data
    data = cls.process_dict(data=data, client=client)

    prepared = {}
    for name, field in attrs.fields_dict(cls).items():
        if field.init and name != "_client":
            default = field.default

            # get the value we want. This also skips the manifest_... entries since they have no value and a default
            bungie_name = cls._convert_to_bungie_case(name)
            value = data.get(bungie_name, attrs.NOTHING)

            # bungie is veeery inconsistent and sometimes like to start their params with an upper case for some reason
            # only sometimes tho :)
            if value is attrs.NOTHING:
                value = data.get(f"{bungie_name[0].capitalize()}{bungie_name[1:]}", attrs.NOTHING)

            # sadly bungie sometimes does not return info without marking that fact in the api specs
            if value is attrs.NOTHING and default is attrs.NOTHING:
                default = MISSING

            if value is attrs.NOTHING:
                value = default

            else:
                value = await cls._convert_to_type(
                    field_type=field.type, field_metadata=field.metadata, value=value, client=client
                )

            # set the attr
            prepared[name] = value

    res = cls(**prepared)  # noqa

    # fill the manifest information
    if not recursive and res._client.always_return_manifest_information:
        await res.fetch_manifest_information()

    return res

process_dict(data, client, *args, **kwargs) staticmethod

Model specific cleanup

Parameters:

Name Type Description Default
data dict

The json representation of the model, usually received by bungie

required
client 'Client'

The client obj

required

Returns:

Type Description
dict

Clean json

Source code in src/bungio/models/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
@staticmethod
def process_dict(data: dict, client: "Client", *args, **kwargs) -> dict:
    """
    Model specific cleanup

    Args:
        data: The json representation of the model, usually received by bungie
        client: The client obj

    Returns:
        Clean json
    """
    return data

to_dict(_return_to_bungie_case=True)

Convert the model into a dict representation bungie accepts

Returns:

Type Description
dict

A dict which can be sent to bungie

Source code in src/bungio/models/base.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def to_dict(self, _return_to_bungie_case: bool = True) -> dict:
    """
    Convert the model into a dict representation bungie accepts

    Returns:
        A dict which can be sent to bungie
    """

    result = {}

    for name, field in attrs.fields_dict(type(self)).items():
        if name.startswith("_") or name.startswith("manifest_"):
            continue

        value = getattr(self, name)
        if _return_to_bungie_case:
            name = self._convert_to_bungie_case(name)

        if inspect.ismethod(value) or inspect.isfunction(value):
            continue

        elif isinstance(value, dict):
            raise NotImplementedError(
                "Nested dict conversion is not currently implemented, since bungie does never require that info"
            )

        elif isinstance(value, list):
            list_results = []
            for entry in value:
                if hasattr(entry, "to_dict"):
                    list_results.append(entry.to_dict())
                else:
                    list_results.append(entry)

            result[name] = list_results

        else:
            if hasattr(value, "to_dict"):
                result[name] = value.to_dict()
            else:
                # convert to string if they are int64
                if field.metadata.get("int64", None) is True:
                    value = str(value)

                result[name] = value

    return result