Skip to content

Models API Models

CoreSetting

Bases: BaseModel

No description given by bungie.

None Attributes: child_settings: No description given by bungie. display_name: No description given by bungie. identifier: No description given by bungie. image_path: No description given by bungie. is_default: No description given by bungie. summary: No description given by bungie.

Source code in src/bungio/models/bungie/common/models.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@custom_define()
class CoreSetting(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        child_settings: _No description given by bungie._
        display_name: _No description given by bungie._
        identifier: _No description given by bungie._
        image_path: _No description given by bungie._
        is_default: _No description given by bungie._
        summary: _No description given by bungie._
    """

    child_settings: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    display_name: str = custom_field()
    identifier: str = custom_field()
    image_path: str = custom_field()
    is_default: bool = custom_field()
    summary: str = 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

CoreSettingsConfiguration

Bases: BaseModel

No description given by bungie.

None Attributes: clan_banner_decal_colors: No description given by bungie. clan_banner_decals: No description given by bungie. clan_banner_gonfalon_colors: No description given by bungie. clan_banner_gonfalon_detail_colors: No description given by bungie. clan_banner_gonfalon_details: No description given by bungie. clan_banner_gonfalons: No description given by bungie. clan_banner_standards: No description given by bungie. default_group_theme: No description given by bungie. destiny2_core_settings: No description given by bungie. destiny_membership_types: No description given by bungie. email_settings: No description given by bungie. environment: No description given by bungie. fireteam_activities: No description given by bungie. forum_categories: No description given by bungie. group_avatars: No description given by bungie. ignore_reasons: No description given by bungie. recruitment_activities: No description given by bungie. recruitment_misc_tags: No description given by bungie. recruitment_platform_tags: No description given by bungie. system_content_locales: No description given by bungie. systems: No description given by bungie. user_content_locales: No description given by bungie.

Source code in src/bungio/models/bungie/common/models.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@custom_define()
class CoreSettingsConfiguration(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        clan_banner_decal_colors: _No description given by bungie._
        clan_banner_decals: _No description given by bungie._
        clan_banner_gonfalon_colors: _No description given by bungie._
        clan_banner_gonfalon_detail_colors: _No description given by bungie._
        clan_banner_gonfalon_details: _No description given by bungie._
        clan_banner_gonfalons: _No description given by bungie._
        clan_banner_standards: _No description given by bungie._
        default_group_theme: _No description given by bungie._
        destiny2_core_settings: _No description given by bungie._
        destiny_membership_types: _No description given by bungie._
        email_settings: _No description given by bungie._
        environment: _No description given by bungie._
        fireteam_activities: _No description given by bungie._
        forum_categories: _No description given by bungie._
        group_avatars: _No description given by bungie._
        ignore_reasons: _No description given by bungie._
        recruitment_activities: _No description given by bungie._
        recruitment_misc_tags: _No description given by bungie._
        recruitment_platform_tags: _No description given by bungie._
        system_content_locales: _No description given by bungie._
        systems: _No description given by bungie._
        user_content_locales: _No description given by bungie._
    """

    clan_banner_decal_colors: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    clan_banner_decals: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    clan_banner_gonfalon_colors: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    clan_banner_gonfalon_detail_colors: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    clan_banner_gonfalon_details: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    clan_banner_gonfalons: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    clan_banner_standards: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    default_group_theme: "CoreSetting" = custom_field()
    destiny2_core_settings: "Destiny2CoreSettings" = custom_field()
    destiny_membership_types: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    email_settings: "EmailSettings" = custom_field()
    environment: str = custom_field()
    fireteam_activities: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    forum_categories: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    group_avatars: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    ignore_reasons: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    recruitment_activities: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    recruitment_misc_tags: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    recruitment_platform_tags: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    system_content_locales: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})
    systems: dict[str, "CoreSystem"] = custom_field(metadata={"type": """dict[str, CoreSystem]"""})
    user_content_locales: list["CoreSetting"] = custom_field(metadata={"type": """list[CoreSetting]"""})

_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

CoreSystem

Bases: BaseModel

No description given by bungie.

None Attributes: enabled: No description given by bungie. parameters: No description given by bungie.

Source code in src/bungio/models/bungie/common/models.py
82
83
84
85
86
87
88
89
90
91
92
93
94
@custom_define()
class CoreSystem(BaseModel):
    """
    _No description given by bungie._

    None
    Attributes:
        enabled: _No description given by bungie._
        parameters: _No description given by bungie._
    """

    enabled: bool = custom_field()
    parameters: dict[str, str] = custom_field(metadata={"type": """dict[str, str]"""})

_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

Destiny2CoreSettings

Bases: BaseModel

No description given by bungie.

Manifest Information

This model has some attributes which can be filled with additional information found in the manifest (manifest_...). Without additional work, these attributes will be None, since they require additional requests and database lookups.

To fill the manifest dependent attributes, either:

  • Run await ThisClass.fetch_manifest_information(), see here
  • Set Client.always_return_manifest_information to True, see here

Attributes:

Name Type Description
active_seals_root_node_hash int

No description given by bungie.

active_triumphs_root_node_hash int

No description given by bungie.

ammo_type_heavy_icon str

No description given by bungie.

ammo_type_primary_icon str

No description given by bungie.

ammo_type_special_icon str

No description given by bungie.

armor_archetype_plug_set_hash int

No description given by bungie.

badges_root_node int

No description given by bungie.

collection_root_node int

No description given by bungie.

crafting_root_node_hash int

No description given by bungie.

current_rank_progression_hashes list[int]

No description given by bungie.

current_season_hash int

No description given by bungie.

current_season_pass_hash int

No description given by bungie.

current_seasonal_artifact_hash int

No description given by bungie.

enabled_fireteam_finder_activity_graph_hashes list[int]

No description given by bungie.

exotic_catalysts_root_node_hash int

No description given by bungie.

featured_items_list_hash int

No description given by bungie.

fireteam_finder_constants_hash int

No description given by bungie.

future_season_hashes list[int]

No description given by bungie.

global_constants_hash int

No description given by bungie.

guardian_rank_constants_hash int

No description given by bungie.

guardian_ranks_root_node_hash int

No description given by bungie.

insert_plug_free_blocked_socket_type_hashes list[int]

No description given by bungie.

insert_plug_free_protected_plug_item_hashes list[int]

No description given by bungie.

inventory_item_constants_hash int

No description given by bungie.

legacy_seals_root_node_hash int

No description given by bungie.

legacy_triumphs_root_node_hash int

No description given by bungie.

loadout_constants_hash int

No description given by bungie.

lore_root_node_hash int

No description given by bungie.

medals_root_node int

No description given by bungie.

medals_root_node_hash int

No description given by bungie.

metrics_root_node int

No description given by bungie.

past_season_hashes list[int]

No description given by bungie.

records_root_node int

No description given by bungie.

seasonal_challenges_presentation_node_hash int

No description given by bungie.

seasonal_hub_event_card_hash int

No description given by bungie.

undiscovered_collectible_image str

No description given by bungie.

manifest_active_seals_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for active_seals_root_node_hash

manifest_active_triumphs_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for active_triumphs_root_node_hash

manifest_armor_archetype_plug_set_hash Optional[DestinyPlugSetDefinition]

Manifest information for armor_archetype_plug_set_hash

manifest_badges_root_node Optional[DestinyPresentationNodeDefinition]

Manifest information for badges_root_node

manifest_collection_root_node Optional[DestinyPresentationNodeDefinition]

Manifest information for collection_root_node

manifest_crafting_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for crafting_root_node_hash

manifest_current_season_hash Optional[DestinySeasonDefinition]

Manifest information for current_season_hash

manifest_current_season_pass_hash Optional[DestinySeasonPassDefinition]

Manifest information for current_season_pass_hash

manifest_current_seasonal_artifact_hash Optional[DestinyVendorDefinition]

Manifest information for current_seasonal_artifact_hash

manifest_exotic_catalysts_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for exotic_catalysts_root_node_hash

manifest_featured_items_list_hash Optional[DestinyItemFilterDefinition]

Manifest information for featured_items_list_hash

manifest_fireteam_finder_constants_hash Optional[DestinyFireteamFinderConstantsDefinition]

Manifest information for fireteam_finder_constants_hash

manifest_global_constants_hash Optional[DestinyGlobalConstantsDefinition]

Manifest information for global_constants_hash

manifest_guardian_rank_constants_hash Optional[DestinyGuardianRankConstantsDefinition]

Manifest information for guardian_rank_constants_hash

manifest_guardian_ranks_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for guardian_ranks_root_node_hash

manifest_inventory_item_constants_hash Optional[DestinyInventoryItemConstantsDefinition]

Manifest information for inventory_item_constants_hash

manifest_legacy_seals_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for legacy_seals_root_node_hash

manifest_legacy_triumphs_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for legacy_triumphs_root_node_hash

manifest_loadout_constants_hash Optional[DestinyLoadoutConstantsDefinition]

Manifest information for loadout_constants_hash

manifest_lore_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for lore_root_node_hash

manifest_medals_root_node Optional[DestinyPresentationNodeDefinition]

Manifest information for medals_root_node

manifest_medals_root_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for medals_root_node_hash

manifest_metrics_root_node Optional[DestinyPresentationNodeDefinition]

Manifest information for metrics_root_node

manifest_records_root_node Optional[DestinyPresentationNodeDefinition]

Manifest information for records_root_node

manifest_seasonal_challenges_presentation_node_hash Optional[DestinyPresentationNodeDefinition]

Manifest information for seasonal_challenges_presentation_node_hash

manifest_seasonal_hub_event_card_hash Optional[DestinyEventCardDefinition]

Manifest information for seasonal_hub_event_card_hash

Source code in src/bungio/models/bungie/common/models.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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
261
262
263
264
265
266
267
268
@custom_define()
class Destiny2CoreSettings(BaseModel):
    """
    _No description given by bungie._

    Tip: Manifest Information
        This model has some attributes which can be filled with additional information found in the manifest (`manifest_...`).
        Without additional work, these attributes will be `None`, since they require additional requests and database lookups.

        To fill the manifest dependent attributes, either:

        - Run `await ThisClass.fetch_manifest_information()`, see [here](/API Reference/Models/base)
        - Set `Client.always_return_manifest_information` to `True`, see [here](/API Reference/client)

    Attributes:
        active_seals_root_node_hash: _No description given by bungie._
        active_triumphs_root_node_hash: _No description given by bungie._
        ammo_type_heavy_icon: _No description given by bungie._
        ammo_type_primary_icon: _No description given by bungie._
        ammo_type_special_icon: _No description given by bungie._
        armor_archetype_plug_set_hash: _No description given by bungie._
        badges_root_node: _No description given by bungie._
        collection_root_node: _No description given by bungie._
        crafting_root_node_hash: _No description given by bungie._
        current_rank_progression_hashes: _No description given by bungie._
        current_season_hash: _No description given by bungie._
        current_season_pass_hash: _No description given by bungie._
        current_seasonal_artifact_hash: _No description given by bungie._
        enabled_fireteam_finder_activity_graph_hashes: _No description given by bungie._
        exotic_catalysts_root_node_hash: _No description given by bungie._
        featured_items_list_hash: _No description given by bungie._
        fireteam_finder_constants_hash: _No description given by bungie._
        future_season_hashes: _No description given by bungie._
        global_constants_hash: _No description given by bungie._
        guardian_rank_constants_hash: _No description given by bungie._
        guardian_ranks_root_node_hash: _No description given by bungie._
        insert_plug_free_blocked_socket_type_hashes: _No description given by bungie._
        insert_plug_free_protected_plug_item_hashes: _No description given by bungie._
        inventory_item_constants_hash: _No description given by bungie._
        legacy_seals_root_node_hash: _No description given by bungie._
        legacy_triumphs_root_node_hash: _No description given by bungie._
        loadout_constants_hash: _No description given by bungie._
        lore_root_node_hash: _No description given by bungie._
        medals_root_node: _No description given by bungie._
        medals_root_node_hash: _No description given by bungie._
        metrics_root_node: _No description given by bungie._
        past_season_hashes: _No description given by bungie._
        records_root_node: _No description given by bungie._
        seasonal_challenges_presentation_node_hash: _No description given by bungie._
        seasonal_hub_event_card_hash: _No description given by bungie._
        undiscovered_collectible_image: _No description given by bungie._
        manifest_active_seals_root_node_hash: Manifest information for `active_seals_root_node_hash`
        manifest_active_triumphs_root_node_hash: Manifest information for `active_triumphs_root_node_hash`
        manifest_armor_archetype_plug_set_hash: Manifest information for `armor_archetype_plug_set_hash`
        manifest_badges_root_node: Manifest information for `badges_root_node`
        manifest_collection_root_node: Manifest information for `collection_root_node`
        manifest_crafting_root_node_hash: Manifest information for `crafting_root_node_hash`
        manifest_current_season_hash: Manifest information for `current_season_hash`
        manifest_current_season_pass_hash: Manifest information for `current_season_pass_hash`
        manifest_current_seasonal_artifact_hash: Manifest information for `current_seasonal_artifact_hash`
        manifest_exotic_catalysts_root_node_hash: Manifest information for `exotic_catalysts_root_node_hash`
        manifest_featured_items_list_hash: Manifest information for `featured_items_list_hash`
        manifest_fireteam_finder_constants_hash: Manifest information for `fireteam_finder_constants_hash`
        manifest_global_constants_hash: Manifest information for `global_constants_hash`
        manifest_guardian_rank_constants_hash: Manifest information for `guardian_rank_constants_hash`
        manifest_guardian_ranks_root_node_hash: Manifest information for `guardian_ranks_root_node_hash`
        manifest_inventory_item_constants_hash: Manifest information for `inventory_item_constants_hash`
        manifest_legacy_seals_root_node_hash: Manifest information for `legacy_seals_root_node_hash`
        manifest_legacy_triumphs_root_node_hash: Manifest information for `legacy_triumphs_root_node_hash`
        manifest_loadout_constants_hash: Manifest information for `loadout_constants_hash`
        manifest_lore_root_node_hash: Manifest information for `lore_root_node_hash`
        manifest_medals_root_node: Manifest information for `medals_root_node`
        manifest_medals_root_node_hash: Manifest information for `medals_root_node_hash`
        manifest_metrics_root_node: Manifest information for `metrics_root_node`
        manifest_records_root_node: Manifest information for `records_root_node`
        manifest_seasonal_challenges_presentation_node_hash: Manifest information for `seasonal_challenges_presentation_node_hash`
        manifest_seasonal_hub_event_card_hash: Manifest information for `seasonal_hub_event_card_hash`
    """

    active_seals_root_node_hash: int = custom_field()
    active_triumphs_root_node_hash: int = custom_field()
    ammo_type_heavy_icon: str = custom_field()
    ammo_type_primary_icon: str = custom_field()
    ammo_type_special_icon: str = custom_field()
    armor_archetype_plug_set_hash: int = custom_field()
    badges_root_node: int = custom_field()
    collection_root_node: int = custom_field()
    crafting_root_node_hash: int = custom_field()
    current_rank_progression_hashes: list[int] = custom_field(metadata={"type": """list[int]"""})
    current_season_hash: int = custom_field()
    current_season_pass_hash: int = custom_field()
    current_seasonal_artifact_hash: int = custom_field()
    enabled_fireteam_finder_activity_graph_hashes: list[int] = custom_field(metadata={"type": """list[int]"""})
    exotic_catalysts_root_node_hash: int = custom_field()
    featured_items_list_hash: int = custom_field()
    fireteam_finder_constants_hash: int = custom_field()
    future_season_hashes: list[int] = custom_field(metadata={"type": """list[int]"""})
    global_constants_hash: int = custom_field()
    guardian_rank_constants_hash: int = custom_field()
    guardian_ranks_root_node_hash: int = custom_field()
    insert_plug_free_blocked_socket_type_hashes: list[int] = custom_field(metadata={"type": """list[int]"""})
    insert_plug_free_protected_plug_item_hashes: list[int] = custom_field(metadata={"type": """list[int]"""})
    inventory_item_constants_hash: int = custom_field()
    legacy_seals_root_node_hash: int = custom_field()
    legacy_triumphs_root_node_hash: int = custom_field()
    loadout_constants_hash: int = custom_field()
    lore_root_node_hash: int = custom_field()
    medals_root_node: int = custom_field()
    medals_root_node_hash: int = custom_field()
    metrics_root_node: int = custom_field()
    past_season_hashes: list[int] = custom_field(metadata={"type": """list[int]"""})
    records_root_node: int = custom_field()
    seasonal_challenges_presentation_node_hash: int = custom_field()
    seasonal_hub_event_card_hash: int = custom_field()
    undiscovered_collectible_image: str = custom_field()
    manifest_active_seals_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_active_triumphs_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_armor_archetype_plug_set_hash: Optional["DestinyPlugSetDefinition"] = custom_field(default=None)
    manifest_badges_root_node: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_collection_root_node: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_crafting_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_current_season_hash: Optional["DestinySeasonDefinition"] = custom_field(default=None)
    manifest_current_season_pass_hash: Optional["DestinySeasonPassDefinition"] = custom_field(default=None)
    manifest_current_seasonal_artifact_hash: Optional["DestinyVendorDefinition"] = custom_field(default=None)
    manifest_exotic_catalysts_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_featured_items_list_hash: Optional["DestinyItemFilterDefinition"] = custom_field(default=None)
    manifest_fireteam_finder_constants_hash: Optional["DestinyFireteamFinderConstantsDefinition"] = custom_field(
        default=None
    )
    manifest_global_constants_hash: Optional["DestinyGlobalConstantsDefinition"] = custom_field(default=None)
    manifest_guardian_rank_constants_hash: Optional["DestinyGuardianRankConstantsDefinition"] = custom_field(
        default=None
    )
    manifest_guardian_ranks_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_inventory_item_constants_hash: Optional["DestinyInventoryItemConstantsDefinition"] = custom_field(
        default=None
    )
    manifest_legacy_seals_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_legacy_triumphs_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_loadout_constants_hash: Optional["DestinyLoadoutConstantsDefinition"] = custom_field(default=None)
    manifest_lore_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_medals_root_node: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_medals_root_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_metrics_root_node: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_records_root_node: Optional["DestinyPresentationNodeDefinition"] = custom_field(default=None)
    manifest_seasonal_challenges_presentation_node_hash: Optional["DestinyPresentationNodeDefinition"] = custom_field(
        default=None
    )
    manifest_seasonal_hub_event_card_hash: Optional["DestinyEventCardDefinition"] = custom_field(default=None)

_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