Skip to content

Documentation

Contains all the errors used in Pyrinth.

InvalidParamError

Bases: Exception

Used when a parameter is invalid.

InvalidRequestError

Bases: Exception

Used when an invalid request is sent.

NoAuthorizationError

Bases: Exception

Used when a user isn't authorized.

NotFoundError

Bases: Exception

Used when something isn't found.


Contains all models used in Pyrinth.

ProjectModel

Bases: _Model

The model used for the Project class.

Attributes:

Name Type Description
slug str

The slug of the project, used for vanity URLs. Regex: ^[\w!@\(()`.+,"\-']{3,64}\)

title str

The title or name of the project

description str

A short description of the project

categories list[str]

A list of categories that the project has

client_side str

The client side support of the project

server_side str

The server side support of the project

body str

A long form description of the project

additional_categories list[str]

A list of categories which are searchable but non-primary

issues_url str

An optional link to where to submit bugs or issues with the project

source_url str

An optional link to the source code of the project

wiki_url str

An optional link to the project's wiki page or other relevant information

discord_url str

An optional invite link to the project's discord

donation_urls list[dict]

A list of donations for the project

project_type str

The project type

downloads int

The total number of downloads of the project

icon_url str

The URL of the project's icon

color str

The RGB color of the project, automatically generated from the project icon

id str

The ID of the project, encoded as a base62 string

team str

The ID of the team that has ownership of this project

moderator_message dict

A message that a moderator sent regarding the project

published str

The date the project was published

updated str

The date the project was last updated

approved str

The date of the project's status was set to approved or unlisted

followers int

The total number of users following the project

status str

The status of the project

license dict

The license of the project

version_ids list[str]

A list of version IDs of the project (will never be empty unless draft status)

game_versions list[str]

A list of all the game versions supported by the project

loaders list[str]

A list of all the loaders supported by the project

gallery list[dict]

A list of images that have been uploaded to the project's gallery

auth str

The project's authorization token

VersionModel

Bases: _Model

The model used for the Version class.

Attributes:

Name Type Description
name str

The name of this version

version_number str

The version number. Ideally will follow semantic versioning

changelog str

The changelog for this version

dependencies list[dict]

A list of specific versions of projects that this version depends on

game_versions list[str]

A list of versions of Minecraft that this version supports

version_type str

The release channel for this version

loaders list[str]

The mod loaders that this version supports

featured bool

Whether the version is featured or not

status str

The version's status

requested_status str

The version's requested status

files list[dict]

A list of files avaliable for download for this version

project_id str

The ID of the project this version is for

id str

The ID of the version, encoded as base62 string

author_id str

The ID of the author who published this version

date_published str

When the version was published

downloads int

The number of times this version has been downloaded


Modrinth

Source code in src/pyrinth/modrinth.py
class Modrinth:
    @staticmethod
    def project_exists(id: str) -> bool:
        """Check if a project exists.

        Args:
            id (str): The ID or slug of the project

        Raises:
            InvalidRequestError: Invalid request
            NotFoundError: The requested project was not found

        Returns:
            (bool): Whether the project exists
        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/project/{id}/check", timeout=60
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError("The requested project was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return response.get("id", False)

    @staticmethod
    def get_random_projects(count: int = 1) -> list[_projects.Project]:
        """Get a certain number of random projects.

        Args:
            count (int, optional): The number of random projects to return

        Raises:
            (src.pyrinth.exceptions.InvalidRequestError): Invalid request

        Returns:
            (list[Project]): The projects that were randomly found
        """
        raw_response = _requests.get(
            "https://api.modrinth.com/v2/projects_random",
            params={"count": count},
            timeout=60,
        )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            _projects.Project(_models.ProjectModel._from_json(project_json))
            for project_json in response
        ]

    @property
    def statistics(self) -> Modrinth._Statistics:
        return Modrinth._Statistics()

    class _Statistics:
        @classmethod  # type: ignore
        @property
        def authors(cls) -> int:
            raw_response = _requests.get(
                "https://api.modrinth.com/v2/statistics", timeout=60
            )
            response: dict = raw_response.json()
            return response.get("authors", ...)

        @classmethod  # type: ignore
        @property
        def files(cls) -> int:
            raw_response = _requests.get(
                "https://api.modrinth.com/v2/statistics", timeout=60
            )
            response: dict = raw_response.json()
            return response.get("files", ...)

        @classmethod  # type: ignore
        @property
        def projects(cls) -> int:
            raw_response = _requests.get(
                "https://api.modrinth.com/v2/statistics", timeout=60
            )
            response: dict = raw_response.json()
            return response.get("projects", ...)

        @classmethod  # type: ignore
        @property
        def versions(cls) -> int:
            raw_response = _requests.get(
                "https://api.modrinth.com/v2/statistics", timeout=60
            )
            response: dict = raw_response.json()
            return response.get("versions", ...)

get_random_projects(count=1) staticmethod

Get a certain number of random projects.

Parameters:

Name Type Description Default
count int

The number of random projects to return

1

Raises:

Type Description
src.pyrinth.exceptions.InvalidRequestError

Invalid request

Returns:

Type Description
list[Project]

The projects that were randomly found

Source code in src/pyrinth/modrinth.py
@staticmethod
def get_random_projects(count: int = 1) -> list[_projects.Project]:
    """Get a certain number of random projects.

    Args:
        count (int, optional): The number of random projects to return

    Raises:
        (src.pyrinth.exceptions.InvalidRequestError): Invalid request

    Returns:
        (list[Project]): The projects that were randomly found
    """
    raw_response = _requests.get(
        "https://api.modrinth.com/v2/projects_random",
        params={"count": count},
        timeout=60,
    )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    return [
        _projects.Project(_models.ProjectModel._from_json(project_json))
        for project_json in response
    ]

project_exists(id) staticmethod

Check if a project exists.

Parameters:

Name Type Description Default
id str

The ID or slug of the project

required

Raises:

Type Description
InvalidRequestError

Invalid request

NotFoundError

The requested project was not found

Returns:

Type Description
bool

Whether the project exists

Source code in src/pyrinth/modrinth.py
@staticmethod
def project_exists(id: str) -> bool:
    """Check if a project exists.

    Args:
        id (str): The ID or slug of the project

    Raises:
        InvalidRequestError: Invalid request
        NotFoundError: The requested project was not found

    Returns:
        (bool): Whether the project exists
    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/project/{id}/check", timeout=60
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError("The requested project was not found")
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    return response.get("id", False)

Project can be mods or modpacks and are created by users.

Project

Project can be mods or modpacks and are created by users.

Attributes:

Name Type Description
model ProjectModel

The project's model

Source code in src/pyrinth/projects.py
  18
  19
  20
  21
  22
  23
  24
  25
  26
  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
  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
 117
 118
 119
 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
 269
 270
 271
 272
 273
 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
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 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
 528
 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
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
class Project:
    """Project can be mods or modpacks and are created by users.

    Attributes:
        model (ProjectModel): The project's model
    """

    def __init__(self, project_model: _models.ProjectModel) -> None:
        self.project_model = project_model

    @property
    def donations(self) -> list[Project.Donation]:
        return _util.list_to_object(Project.Donation, self.project_model.donation_urls)

    def _get_auth(self, auth: str | None) -> str:
        if auth:
            return auth
        return self.project_model.auth

    @staticmethod
    def get(id: str, authorization: str = "") -> Project:
        """Get a project by ID or slug.

        Args:
            id (str): The ID or slug of the project
            authorization (str, optional): An optional authorization token when getting the project

        Raises:
            NotFoundError: The requested project wasn't found or no authorization to see this project
            InvalidRequestError: Invalid request

        Returns:
            (Project): The project that was found
        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/project/{id}",
            headers={"authorization": authorization},
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        response.update({"authorization": authorization})
        return Project(_models.ProjectModel._from_json(response))

    @staticmethod
    def get_multiple(ids: list[str]) -> list[Project]:
        """Get multiple projects.

        Args:
            ids (list[str]): The IDs of the projects

        Raises:
            InvalidRequestError: Invalid request

        Returns:
            (list[Project]): The projects that were found
        """
        raw_response = _requests.get(
            "https://api.modrinth.com/v2/projects",
            params={"ids": _json.dumps(ids)},
            timeout=60,
        )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            Project(_models.ProjectModel._from_json(project_json))
            for project_json in response
        ]

    def get_latest_version(
        self,
        loaders: list[_literals.loader_literal] | None = None,
        game_versions: list[_literals.game_version_literal] | None = None,
        featured: bool | None = None,
        type: _literals.version_type_literal | None = None,
        auth: str | None = None,
    ) -> Project.Version | None:
        """Get the projects latest version.

        Args:
            loaders (list[str], optional): The loaders filter. Defaults to None
            game_versions (list[str], optional): The game versions filter. Defaults to None
            featured (bool, optional): The is featured filter. Defaults to None
            type (Literal["release", "beta", "alpha"], optional): The types filter. Defaults to None
            auth (str, optional): The authorization token. Defaults to None

        Returns:
            (Project.Version): The project's latest version
        """
        versions = self.get_versions(loaders, game_versions, featured, type, auth)
        if len(versions) == 0:
            return None
        return versions[0]

    @property
    def gallery(self) -> list[Project.GalleryImage]:
        return _util.list_to_object(Project.GalleryImage, self.project_model.gallery)

    @property
    def description(self) -> str:
        return self.project_model.description

    @property
    def body(self) -> str:
        return self.project_model.body

    @property
    def is_client_side(self) -> bool:
        """Check if this project is client side.

        Returns:
            (bool): Whether this project is client side
        """
        return True if self.project_model.client_side == "required" else False

    @property
    def is_server_side(self) -> bool:
        """Check if this project is server side.

        Returns:
            (bool): Whether this project is server side
        """
        return True if self.project_model.server_side == "required" else False

    @property
    def downloads(self) -> int:
        return self.project_model.downloads

    @property
    def categories(self) -> list[str]:
        return self.project_model.categories

    @property
    def additional_categories(self) -> list[str] | None:
        return self.project_model.additional_categories

    @property
    def all_categories(self) -> list[str]:
        if self.additional_categories is None:
            return self.categories

        return self.categories + self.additional_categories

    @property
    def license(self) -> Project.License:
        return Project.License._from_json(self.project_model.license)

    def get_specific_version(self, semantic_version: str) -> Project.Version | None:
        """Get a specific version based on the semantic version.

        Args:
            semantic_version (str): The semantic version to search for

        Returns:
            (Project.Version): The version that was found using the semantic version
            (None): No version was found with that semantic version
        """
        versions = self.get_versions()
        if versions:
            for version in versions:
                if version.version_model.version_number == semantic_version:
                    return version
        return None

    def download(self, recursive: bool = False) -> int:
        """Download the project.

        Args:
            recursive (bool): Whether to download dependencies. Defaults to False
        """
        latest = self.get_latest_version()
        if latest is None:
            return 0
        files = latest.files
        for file in files:
            file_content = _requests.get(file.url, timeout=60).content
            open(file.name, "wb").write(file_content)
        if recursive:
            dependencies = latest.dependencies
            for dep in dependencies:
                files = dep.version.files
                for file in files:
                    file_content = _requests.get(file.url, timeout=60).content
                    open(file.name, "wb").write(file_content)
        return 1

    def get_versions(
        self,
        loaders: list[_literals.loader_literal] | None = None,
        game_versions: list[_literals.game_version_literal] | None = None,
        featured: bool | None = None,
        types: _literals.version_type_literal | None = None,
        auth: str | None = None,
    ) -> list[Project.Version]:
        """Get project versions based on filters.

        Args:
            loaders (list[str], optional): The types of loaders to filter for
            game_versions (list[str], optional): The game versions to filter for
            featured (bool, optional): Allows to filter for featured or non-featured versions only
            types (Literal["release", "beta", "alpha"], optional): The release type of version
            auth (str, optional): An optional authorization token to use when getting the project versions

        Raises:
            NotFoundError: The requested project wasn't found or no authorization to see this project
            InvalidRequestError: Invalid request

        Returns:
            (list[Project.Version]): The versions that were found
        """
        filters = {
            "loaders": loaders,
            "game_versions": game_versions,
            "featured": featured,
        }
        filters = _util.remove_null_values(filters)
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/version",
            params=_util.json_to_query_params(filters),
            headers={"authorization": self._get_auth(auth)},
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        versions = [
            self.Version(_models.VersionModel._from_json(version))
            for version in response
        ]
        if not types:
            return versions
        result = []
        for version in versions:
            if version.version_model.version_type in types:
                result.append(version)
        return result

    def get_oldest_version(
        self,
        loaders: list[_literals.loader_literal] | None = None,
        game_versions: list[_literals.game_version_literal] | None = None,
        featured: bool | None = None,
        type: _literals.version_type_literal | None = None,
        auth: str | None = None,
    ) -> Project.Version | None:
        """Get the oldest project version.

        Args:
            loaders (list[str], optional): The types of loaders to filter for
            game_versions (list[str], optional): The game versions to filter for
            featured (bool, optional): Allows to filter for featured or non-featured versions only
            type (Literal["release", "beta", "alpha"], optional): The type of version
            auth (str, optional): An optional authorization token to use when getting the project versions

        Returns:
            (Project.Version): The version that was found
        """
        versions = self.get_versions(loaders, game_versions, featured, type, auth)
        if len(versions) == 0:
            return None
        return versions[-1]

    @property
    def id(self) -> str:
        return self.project_model.id

    @property
    def issues_url(self) -> str | None:
        return self.project_model.issues_url

    @property
    def source_url(self) -> str | None:
        return self.project_model.source_url

    @property
    def wiki_url(self) -> str | None:
        return self.project_model.wiki_url

    @property
    def discord_url(self) -> str | None:
        return self.project_model.discord_url

    @property
    def slug(self) -> str:
        return self.project_model.slug

    @property
    def name(self) -> str:
        return self.project_model.title

    @staticmethod
    def get_version(id: str) -> Project.Version:
        """Get a version by ID.

        Args:
            id (str): The ID of the version

        Raises:
            NotFoundError: The requested version wasn't found or no authorization to see this version
            InvalidRequestError: Invalid request

        Returns:
            (Project.Version): The version that was found
        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/version/{id}", timeout=60
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested version wasn't found or no authorization to see this version"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return Project.Version(_models.VersionModel._from_json(response))

    def create_version(
        self, version_model: _models.VersionModel, auth: str | None = None
    ) -> int:
        """Create a new version on the project.

        Args:
            auth (str, optional): The authorization token to use when creating the version
            version_model (VersionModel): The model to use when creating the version

        Raises:
            NoAuthorizationError: No authorization to create this version
            InvalidRequestError: Invalid request

        Returns:
            (int): Whether creating the version was successful
        """
        version_model.project_id = self.id

        files = {}

        for file in version_model.file_parts:
            files[file] = open(file, "rb")

        raw_response = _requests.post(
            "https://api.modrinth.com/v2/version",
            headers={"authorization": self._get_auth(auth)},
            data={"data": _json.dumps(version_model._to_json())},
            files=files,
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to create this version"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def change_icon(self, file_path: str, auth: str | None = None) -> bool:
        """Change the project icon.

        Args:
            file_path (str): The file path of the image to use for the new project icon
            auth (str, optional): The authorization token to use when changing the project icon

        Raises:
            InvalidParamError: Invalid input for new icon
            InvalidRequestError: Invalid request

        Returns:
            (bool): Whether the project icon change was successful
        """
        raw_response = _requests.patch(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/icon",
            params={"ext": file_path.split(".")[-1]},
            headers={"authorization": self._get_auth(auth)},
            data=open(file_path, "rb"),
            timeout=60,
        )
        match raw_response.status_code:
            case 400:
                raise _exceptions.InvalidParamError("Invalid input for new icon")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def delete_icon(self, auth: str | None = None) -> bool:
        """Delete the project icon.

        Args:
            auth (str, optional): The authorization token to use when deleting the project icon

        Raises:
            InvalidParamError: Invalid input
            NoAuthorizationError: No authorization to edit this project
            InvalidRequestError: Invalid request

        Returns:
            (bool): Whether the project icon deletion was successful
        """
        raw_response = _requests.delete(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/icon",
            headers={"authorization": self._get_auth(auth)},
            timeout=60,
        )
        match raw_response.status_code:
            case 400:
                raise _exceptions.InvalidParamError("Invalid input")
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to edit this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def add_gallery_image(
        self, image: Project.GalleryImage, auth: str | None = None
    ) -> bool:
        """Add a gallery image to the project.

        Args:
            image (Project.GalleryImage): The gallery image to add
            auth (str, optional): The authorization token to use when adding the gallery image

        Raises:
            NoAuthorizationError: No authorization to create a gallery image
            NotFoundError: The requested project wasn't found or no authorization to see this project
            InvalidRequestError: Invalid request

        Returns:
            (bool): If the gallery image addition was successful
        """
        raw_response = _requests.post(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/gallery",
            headers={"authorization": self._get_auth(auth)},
            params=image._to_json(),
            data=open(image.file_path, "rb"),
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to create a gallery image"
                )
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def modify_gallery_image(
        self,
        url: str,
        featured: bool | None = None,
        title: str | None = None,
        description: str | None = None,
        ordering: int | None = None,
        auth: str | None = None,
    ) -> bool:
        """Modify a gallery image.

        Args:
            url (str): URL link of the image to modify
            featured (bool, optional): Whether the image is featured
            title (str, optional): New title of the image
            description (str, optional): New description of the image
            ordering (int, optional): New ordering of the image
            auth (str, optional): Authentication token when modifying the gallery image

        Raises:
            NoAuthorizationError: No authorization to edit this gallery image
            NotFoundError: The requested project wasn't found or no authorization to see this project
            InvalidRequestError: Invalid request

        Returns:
            (bool): Whether the gallery image modification was successful
        """
        modified_json = {
            "url": url,
            "featured": featured,
            "title": title,
            "description": description,
            "ordering": ordering,
        }
        modified_json = _util.remove_null_values(modified_json)
        raw_response = _requests.patch(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/gallery",
            params=modified_json,
            headers={"authorization": self._get_auth(auth)},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to edit this gallery image"
                )
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def delete_gallery_image(self, url: str, auth: str | None = None) -> bool:
        """Delete a gallery image.

        Args:
            url (str): URL link of the image to delete
            auth (str, optional): Authentication token to use when deleting the gallery image

        Raises:
            InvalidParamError: Invalid URL or project specified
            NoAuthorizationError: No authorization to delete this gallery image
            InvalidRequestError: Invalid request

        Returns:
            (bool): Whether the gallery image deletion was successful
        """
        if "-raw" in url:
            raise _exceptions.InvalidParamError(
                "Please use cdn.modrinth.com instead of cdn-raw.modrinth.com"
            )
        raw_response = _requests.delete(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/gallery",
            headers={"authorization": self._get_auth(auth)},
            params={"url": url},
            timeout=60,
        )
        match raw_response.status_code:
            case 400:
                raise _exceptions.InvalidParamError("Invalid URL or project specified")
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to delete this gallery image"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def modify(
        self,
        slug: str | None = None,
        title: str | None = None,
        description: str | None = None,
        categories: list[str] | None = None,
        client_side: str | None = None,
        server_side: str | None = None,
        body: str | None = None,
        additional_categories: list[str] | None = None,
        issues_url: str | None = None,
        source_url: str | None = None,
        wiki_url: str | None = None,
        discord_url: str | None = None,
        license_id: str | None = None,
        license_url: str | None = None,
        status: _literals.project_status_literal | None = None,
        requested_status: _literals.requested_project_status_literal | None = None,
        moderation_message: str | None = None,
        moderation_message_body: str | None = None,
        auth: str | None = None,
    ) -> bool:
        r"""Modify the project.

        Args:
            slug (str, optional): The slug of a project, used for vanity URLs. Regex: ^[\w!@$()`.+,"\-']{3,64}$
            title (str, optional): The title or name of the project
            description (str, optional): A short description of the project
            categories (list[str], optional): A list of categories that the project has
            client_side (str, optional): The client side support of the project
            server_side (str, optional): The server side support of the project
            body (str, optional): A long form description of the project
            additional_categories (list[str], optional): A list of categories which are searchable but non-primary
            issues_url (str, optional): An optional link to where to submit bugs or issues with the project
            source_url (str, optional): An optional link to the source code of the project
            wiki_url (str, optional): An optional link to the project's wiki page or other relevant information
            discord_url (str, optional): An optional invite link to the project's discord
            license_id (str, optional): The SPDX license ID of a project
            license_url (str, optional): The URL to this license
            status (Literal["approved", "archived", "rejected", "draft", "unlisted", "processing", "withheld", "scheduled", "private", "unknown"], optional): The status of the project
            requested_status (Literal["approved", "archived", "unlisted", "private", "draft"], optional): The requested status when submitting for review or scheduling the project for release
            moderation_message (str, optional): The title of the moderators' message for the project
            moderation_message_body (str, optional): The body of the moderators' message for the project
            auth (str, optional): Authentication token to use when modifying the project

        Raises:
            InvalidParamError: Please specify at least 1 optional argument
            NoAuthorizationError: No authorization to modify this project
            NotFoundError: The requested project wasn't found or no authorization to see this project
            InvalidRequestError: Invalid request

        Returns:
            (bool): Whether the project modification was successful
        """
        modified_json = {
            "slug": slug,
            "title": title,
            "description": description,
            "categories": categories,
            "client_side": client_side,
            "server_side": server_side,
            "body": body,
            "additional_categories": additional_categories,
            "issues_url": issues_url,
            "source_url": source_url,
            "wiki_url": wiki_url,
            "discord_url": discord_url,
            "license_id": license_id,
            "license_url": license_url,
            "status": status,
            "requested_status": requested_status,
            "moderation_message": moderation_message,
            "moderation_message_body": moderation_message_body,
        }
        modified_json = _util.remove_null_values(modified_json)
        if not modified_json:
            raise _exceptions.InvalidParamError(
                "Please specify at least 1 optional argument"
            )
        raw_response = _requests.patch(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}",
            data=_json.dumps(modified_json),
            headers={
                "Content-Type": "application/json",
                "authorization": self._get_auth(auth),
            },
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to edit this project"
                )
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    @property
    def followers(self) -> int:
        return self.project_model.followers

    def delete(self, auth: str | None = None) -> bool:
        """Delete the project.

        Args:
            auth (str, optional): Authentication token to use when deleting the project

        Raises:
            NotFoundError: The requested project wasn't found
            NoAuthorizationError: No authorization to delete this project
            InvalidRequestError: Invalid request

        Returns:
            (bool): Whether the project deletion was successful
        """
        raw_response = _requests.delete(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}",
            headers={"authorization": self._get_auth(auth)},
            timeout=60,
        )
        match raw_response.status_code:
            case 400:
                raise _exceptions.NotFoundError("The requested project was not found")
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to delete this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    @property
    def dependencies(self) -> list[Project]:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/project/{self.project_model.slug}/dependencies",
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            Project(_models.ProjectModel._from_json(dependency_json))
            for dependency_json in response.get("projects", ...)
        ]

    @staticmethod
    def search(
        query: str = "",
        facets: list[list[str]] | None = None,
        index: _literals.index_literal = "relevance",
        offset: int = 0,
        limit: int = 10,
        filters: list[str] | None = None,
    ) -> list[Project._SearchResult]:
        """Search for projects.

        Args:
            query (str, optional): The query to search for
            facets (list[list[str]], optional): The recommended way of filtering search results. [Learn more about using facets](https://docs.modrinth.com/docs/tutorials/api_search)
            index (Literal["relevance", "downloads", "follows", "newest", "updated"], optional): The sorting method used for sorting search results
            offset (int, optional): The offset into the search. Skip this number of results
            limit (int, optional): The number of results returned by the search
            filters (list[str], optional): A list of filters relating to the properties of a project. Use filters when there isn't an available facet for your needs. [More information](https://docs.meilisearch.com/reference/features/filtering.html)

        Raises:
            NotFoundError: The requested project wasn't found or no authorization to see this project
            InvalidRequestError: Invalid request

        Returns:
            (list[Project.SearchResult]): The project search results
        """
        params = {}
        if query != "":
            params.update({"query": query})
        if facets:
            params.update({"facets": _json.dumps(facets)})
        if index != "relevance":
            params.update({"index": index})
        if offset != 0:
            params.update({"offset": str(offset)})
        if limit != 10:
            params.update({"limit": str(limit)})
        if filters:
            params.update({"filters": _json.dumps(filters)})
        raw_response = _requests.get(
            "https://api.modrinth.com/v2/search", params=params, timeout=60
        )
        response: dict = raw_response.json()
        return [
            Project._SearchResult(_models._SearchResultModel._from_json(project))
            for project in response.get("hits", ...)
        ]

    @property
    def team_members(self) -> list[_teams._Team._TeamMember]:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/project/{self.project_model.id}/members",
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            _teams._Team._TeamMember._from_json(team_member) for team_member in response
        ]

    @property
    def team(self) -> _teams._Team:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/project/{self.project_model.id}/members",
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested project wasn't found or no authorization to see this project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return _teams._Team._from_json(response)

    def __repr__(self) -> str:
        return f"Project: {self.project_model.title}"

    class Version:
        """Versions contain download links to files with additional metadata.

        Attributes:
            model (VersionModel): The version model associated with the version

        """

        def __init__(self, version_model: _models.VersionModel) -> None:
            self.version_model = version_model

        @property
        def type(self) -> str:
            return self.version_model.version_type

        @property
        def dependencies(self) -> list[Project.Dependency]:
            return [
                Project.Dependency._from_json(dependency_json)  # type: ignore
                for dependency_json in self.version_model.dependencies
            ]

        @staticmethod
        def get(id: str) -> Project.Version:
            """Get a version by ID.

            Args:
                id (str): The ID of the version

            Raises:
                NotFoundError: The requested version wasn't found or no authorization to see this version
                InvalidRequestError: Invalid request

            Returns:
                (Project.Version): The version that was found
            """
            raw_response = _requests.get(
                f"https://api.modrinth.com/v2/version/{id}", timeout=60
            )
            match raw_response.status_code:
                case 404:
                    raise _exceptions.NotFoundError(
                        "The requested version wasn't found or no authorization to see this version"
                    )
            if not raw_response.ok:
                raise _exceptions.InvalidRequestError(raw_response.text)
            response: dict = raw_response.json()
            return Project.Version(_models.VersionModel._from_json(response))

        @staticmethod
        def get_from_hash(
            hash: str,
            algorithm: _literals.sha_algorithm_literal = "sha1",
            multiple: bool = False,
        ) -> Project.Version | list[Project.Version]:
            """Get a version by hash.

            Args:
                hash (str): The hash of the file, considering its byte content, and encoded in hexadecimal
                algorithm (Literal["sha512", "sha1"]): The algorithm of the hash
                multiple (bool): Whether to return multiple results when looking for this hash

            Raises:
                NotFoundError: The requested version file wasn't found or no authorization to see this version
                InvalidRequestError: Invalid request

            Returns:
                (Project.Version): The version that was found
            """
            raw_response = _requests.get(
                f"https://api.modrinth.com/v2/version_file/{hash}",
                params={"algorithm": algorithm, "multiple": str(multiple).lower()},
                timeout=60,
            )
            match raw_response.status_code:
                case 404:
                    raise _exceptions.NotFoundError(
                        "The requested version file wasn't found or no authorization to see this version"
                    )
            if not raw_response.ok:
                raise _exceptions.InvalidRequestError(raw_response.text)
            response: dict = raw_response.json()
            if isinstance(response, list):
                return [
                    Project.Version(_models.VersionModel._from_json(version))
                    for version in response
                ]
            return Project.Version(_models.VersionModel._from_json(response))

        @staticmethod
        def delete_file_from_hash(
            auth: str,
            hash: str,
            version_id: str,
            algorithm: _literals.sha_algorithm_literal = "sha1",
        ) -> bool:
            """Delete a file from its hash.

            Args:
                hash (str): The hash of the file, considering its byte content, and encoded in hexadecimal
                algorithm (Literal["sha512", "sha1"]): The algorithm of the hash
                version_id (bool): Version ID to delete the version from if multiple files of the same hash exist
                auth (str): The authorization token to use when deleting the file from its hash

            Raises:
                NotFoundError: The requested version wasn't found
                NoAuthorizationError: No authorization to delete this file
                InvalidRequestError: Invalid request

            Returns:
                (bool): If the file deletion was successful
            """
            raw_response = _requests.delete(
                f"https://api.modrinth.com/v2/version_file/{hash}",
                params={"algorithm": algorithm, "version_id": version_id},
                headers={"authorization": auth},
                timeout=60,
            )
            match raw_response.status_code:
                case 404:
                    raise _exceptions.NotFoundError(
                        "The requested version was not found"
                    )
                case 401:
                    raise _exceptions.NoAuthorizationError(
                        "No authorization to delete this file"
                    )
            if not raw_response.ok:
                raise _exceptions.InvalidRequestError(raw_response.text)
            return True

        @property
        def files(self) -> list[Project._File]:
            return [Project._File._from_json(file) for file in self.version_model.file_parts]  # type: ignore

        def download(self, recursive: bool = False) -> None:
            """Download the files associated with the version.

            Args:
                recursive (bool, optional): Whether to also download the files of the dependencies
            """
            for file in self.files:
                file_content = _requests.get(file.url, timeout=60).content
                open(file.name, "wb").write(file_content)
            if recursive:
                dependencies = self.dependencies
                for dep in dependencies:
                    files = dep.version.files
                    for file in files:
                        file_content = _requests.get(file.url, timeout=60).content
                        open(file.name, "wb").write(file_content)

        @property
        def project(self) -> Project:
            return Project.get(self.version_model.project_id)

        @property
        def primary_files(self) -> list[Project._File]:
            result = []
            for file in self.files:
                if file.primary:
                    result.append(file)
            return result

        @property
        def author(self) -> _users.User:
            user = _users.User.get(self.version_model.author_id)
            return user

        @property
        def is_featured(self) -> bool:
            """Check if the version is featured.

            Returns:
                (bool): Whether the version is featured
            """
            return self.version_model.featured

        @property
        def date_published(self) -> _datetime.datetime:
            return _util.format_time(self.version_model.date_published)

        @property
        def downloads(self) -> int:
            return self.version_model.downloads

        @property
        def name(self) -> str:
            return self.version_model.name

        @property
        def version_number(self) -> str:
            return self.version_model.version_number

        def __repr__(self) -> str:
            return f"Version: {self.version_model.name}"

    class GalleryImage:
        """
        Represents an image in a gallery.

        Attributes:
            file_path (str): The path to the image
            ext (str): Image extension
            featured (str): Whether an image is featured
            title (str): Title of the image
            description (str): Description of the image
            ordering (int): Ordering of the image

        """

        def __init__(
            self,
            file_path: str,
            featured: bool,
            title: str,
            description: str,
            ordering: int = 0,
        ) -> None:
            self.file_path = file_path
            self.ext = file_path.split(".")[-1]
            self.featured = str(featured).lower()
            self.title = title
            self.description = description
            self.ordering = ordering

        @staticmethod
        def _from_json(gallery_image_json: dict) -> Project.GalleryImage:
            return Project.GalleryImage(
                gallery_image_json.get("url", ...),
                gallery_image_json.get("featured", ...),
                gallery_image_json.get("title", ...),
                gallery_image_json.get("description", ...),
                gallery_image_json.get("ordering", ...),
            )

        def _to_json(self) -> dict:
            return _util.remove_null_values(self.__dict__)

    class _File:
        hashes: dict
        url: str
        name: str
        primary: str
        size: int
        file_type: str
        extension: str

        @property
        def is_resourcepack(self) -> bool:
            """
            Check if a file is a resourcepack.

            Returns:
                (bool): If the file is a resourcepack
            """
            if self.file_type is None:
                return False
            return True

        @staticmethod
        def _from_json(file_json: dict) -> Project._File:
            result = Project._File()
            result.hashes = file_json.get("hashes", ...)
            result.url = file_json.get("url", ...)
            result.name = file_json.get("filename", ...)
            result.primary = file_json.get("primary", ...)
            result.size = file_json.get("size", ...)
            result.file_type = file_json.get("file_type", ...)
            result.extension = result.name.split(".")[-1]
            return result

        def __repr__(self) -> str:
            return f"File: {self.name}"

    @dataclasses.dataclass
    class License:
        """
        Represents a license.

        Attributes:
            id (str): The SPDX license ID of a project
            name (str): The long name of a license
            url (str): The URL to this license

        """

        id: str
        name: str
        url: str | None = None

        @staticmethod
        def _from_json(license_json: dict) -> Project.License:
            result = Project.License(
                license_json["id"], license_json["name"], license_json["url"]
            )
            return result

        def _to_json(self) -> dict:
            return self.__dict__

        def __repr__(self) -> str:
            return f"License: {(self.name if self.name else self.id)}"

    @dataclasses.dataclass
    class Donation:
        """
        Represents a donation.

        Attributes:
            id (str): The ID of the donation platform
            platform (str): The donation platform this link is to
            url (str): The URL of the donation platform and user

        """

        id: str
        platform: str
        url: str

        @staticmethod
        def _from_json(donation_json: dict) -> Project.Donation:
            result = Project.Donation._from_json(donation_json)
            return result

        def __repr__(self) -> str:
            return f"Donation: {self.platform}"

    @dataclasses.dataclass
    class Dependency:
        dependency_type: _literals.dependency_type_literal
        version_id: str | None = None
        project_id: str | None = None
        file_name: str | None = None

        def _to_json(self) -> dict:
            return self.__dict__

        @staticmethod
        def _from_json(dependency_json: dict) -> Project.Dependency:
            result = Project.Dependency(
                dependency_json["dependency_type"],
                dependency_json["version_id"],
                dependency_json["project_id"],
                dependency_json["file_name"],
            )
            return result

        @property
        def version(self) -> Project.Version:
            id = self.project_id
            if self.version_id:
                id = self.version_id
                return Project.Version.get(id)  # type: ignore
            else:
                return Project.get(id).get_latest_version()

        @property
        def is_required(self) -> bool:
            """
            Check if the dependency is required.

            Returns:
                (bool): True if the dependency is required, False otherwise
            """
            return True if self.dependency_type == "required" else False

        @property
        def is_optional(self) -> bool:
            """
            Check if the dependency is optional.

            Returns:
                (bool): True if the dependency is optional, False otherwise
            """
            return True if self.dependency_type == "optional" else False

        @property
        def is_incompatible(self) -> bool:
            """
            Check if the dependency is incompatible.

            Returns:
                (bool): True if the dependency is incompatible, False otherwise
            """
            return True if self.dependency_type == "incompatible" else False

        def __repr__(self) -> str:
            return f"Dependency"

    @dataclasses.dataclass
    class _SearchResult:
        search_result_model: _models._SearchResultModel

        def __repr__(self) -> str:
            return f"Search Result: {self.search_result_model.title}"

is_client_side: bool property

Check if this project is client side.

Returns:

Type Description
bool

Whether this project is client side

is_server_side: bool property

Check if this project is server side.

Returns:

Type Description
bool

Whether this project is server side

Dependency dataclass

Source code in src/pyrinth/projects.py
@dataclasses.dataclass
class Dependency:
    dependency_type: _literals.dependency_type_literal
    version_id: str | None = None
    project_id: str | None = None
    file_name: str | None = None

    def _to_json(self) -> dict:
        return self.__dict__

    @staticmethod
    def _from_json(dependency_json: dict) -> Project.Dependency:
        result = Project.Dependency(
            dependency_json["dependency_type"],
            dependency_json["version_id"],
            dependency_json["project_id"],
            dependency_json["file_name"],
        )
        return result

    @property
    def version(self) -> Project.Version:
        id = self.project_id
        if self.version_id:
            id = self.version_id
            return Project.Version.get(id)  # type: ignore
        else:
            return Project.get(id).get_latest_version()

    @property
    def is_required(self) -> bool:
        """
        Check if the dependency is required.

        Returns:
            (bool): True if the dependency is required, False otherwise
        """
        return True if self.dependency_type == "required" else False

    @property
    def is_optional(self) -> bool:
        """
        Check if the dependency is optional.

        Returns:
            (bool): True if the dependency is optional, False otherwise
        """
        return True if self.dependency_type == "optional" else False

    @property
    def is_incompatible(self) -> bool:
        """
        Check if the dependency is incompatible.

        Returns:
            (bool): True if the dependency is incompatible, False otherwise
        """
        return True if self.dependency_type == "incompatible" else False

    def __repr__(self) -> str:
        return f"Dependency"

is_incompatible: bool property

Check if the dependency is incompatible.

Returns:

Type Description
bool

True if the dependency is incompatible, False otherwise

is_optional: bool property

Check if the dependency is optional.

Returns:

Type Description
bool

True if the dependency is optional, False otherwise

is_required: bool property

Check if the dependency is required.

Returns:

Type Description
bool

True if the dependency is required, False otherwise

Donation dataclass

Represents a donation.

Attributes:

Name Type Description
id str

The ID of the donation platform

platform str

The donation platform this link is to

url str

The URL of the donation platform and user

Source code in src/pyrinth/projects.py
@dataclasses.dataclass
class Donation:
    """
    Represents a donation.

    Attributes:
        id (str): The ID of the donation platform
        platform (str): The donation platform this link is to
        url (str): The URL of the donation platform and user

    """

    id: str
    platform: str
    url: str

    @staticmethod
    def _from_json(donation_json: dict) -> Project.Donation:
        result = Project.Donation._from_json(donation_json)
        return result

    def __repr__(self) -> str:
        return f"Donation: {self.platform}"

GalleryImage

Represents an image in a gallery.

Attributes:

Name Type Description
file_path str

The path to the image

ext str

Image extension

featured str

Whether an image is featured

title str

Title of the image

description str

Description of the image

ordering int

Ordering of the image

Source code in src/pyrinth/projects.py
class GalleryImage:
    """
    Represents an image in a gallery.

    Attributes:
        file_path (str): The path to the image
        ext (str): Image extension
        featured (str): Whether an image is featured
        title (str): Title of the image
        description (str): Description of the image
        ordering (int): Ordering of the image

    """

    def __init__(
        self,
        file_path: str,
        featured: bool,
        title: str,
        description: str,
        ordering: int = 0,
    ) -> None:
        self.file_path = file_path
        self.ext = file_path.split(".")[-1]
        self.featured = str(featured).lower()
        self.title = title
        self.description = description
        self.ordering = ordering

    @staticmethod
    def _from_json(gallery_image_json: dict) -> Project.GalleryImage:
        return Project.GalleryImage(
            gallery_image_json.get("url", ...),
            gallery_image_json.get("featured", ...),
            gallery_image_json.get("title", ...),
            gallery_image_json.get("description", ...),
            gallery_image_json.get("ordering", ...),
        )

    def _to_json(self) -> dict:
        return _util.remove_null_values(self.__dict__)

License dataclass

Represents a license.

Attributes:

Name Type Description
id str

The SPDX license ID of a project

name str

The long name of a license

url str

The URL to this license

Source code in src/pyrinth/projects.py
@dataclasses.dataclass
class License:
    """
    Represents a license.

    Attributes:
        id (str): The SPDX license ID of a project
        name (str): The long name of a license
        url (str): The URL to this license

    """

    id: str
    name: str
    url: str | None = None

    @staticmethod
    def _from_json(license_json: dict) -> Project.License:
        result = Project.License(
            license_json["id"], license_json["name"], license_json["url"]
        )
        return result

    def _to_json(self) -> dict:
        return self.__dict__

    def __repr__(self) -> str:
        return f"License: {(self.name if self.name else self.id)}"

Version

Versions contain download links to files with additional metadata.

Attributes:

Name Type Description
model VersionModel

The version model associated with the version

Source code in src/pyrinth/projects.py
class Version:
    """Versions contain download links to files with additional metadata.

    Attributes:
        model (VersionModel): The version model associated with the version

    """

    def __init__(self, version_model: _models.VersionModel) -> None:
        self.version_model = version_model

    @property
    def type(self) -> str:
        return self.version_model.version_type

    @property
    def dependencies(self) -> list[Project.Dependency]:
        return [
            Project.Dependency._from_json(dependency_json)  # type: ignore
            for dependency_json in self.version_model.dependencies
        ]

    @staticmethod
    def get(id: str) -> Project.Version:
        """Get a version by ID.

        Args:
            id (str): The ID of the version

        Raises:
            NotFoundError: The requested version wasn't found or no authorization to see this version
            InvalidRequestError: Invalid request

        Returns:
            (Project.Version): The version that was found
        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/version/{id}", timeout=60
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested version wasn't found or no authorization to see this version"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return Project.Version(_models.VersionModel._from_json(response))

    @staticmethod
    def get_from_hash(
        hash: str,
        algorithm: _literals.sha_algorithm_literal = "sha1",
        multiple: bool = False,
    ) -> Project.Version | list[Project.Version]:
        """Get a version by hash.

        Args:
            hash (str): The hash of the file, considering its byte content, and encoded in hexadecimal
            algorithm (Literal["sha512", "sha1"]): The algorithm of the hash
            multiple (bool): Whether to return multiple results when looking for this hash

        Raises:
            NotFoundError: The requested version file wasn't found or no authorization to see this version
            InvalidRequestError: Invalid request

        Returns:
            (Project.Version): The version that was found
        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/version_file/{hash}",
            params={"algorithm": algorithm, "multiple": str(multiple).lower()},
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested version file wasn't found or no authorization to see this version"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        if isinstance(response, list):
            return [
                Project.Version(_models.VersionModel._from_json(version))
                for version in response
            ]
        return Project.Version(_models.VersionModel._from_json(response))

    @staticmethod
    def delete_file_from_hash(
        auth: str,
        hash: str,
        version_id: str,
        algorithm: _literals.sha_algorithm_literal = "sha1",
    ) -> bool:
        """Delete a file from its hash.

        Args:
            hash (str): The hash of the file, considering its byte content, and encoded in hexadecimal
            algorithm (Literal["sha512", "sha1"]): The algorithm of the hash
            version_id (bool): Version ID to delete the version from if multiple files of the same hash exist
            auth (str): The authorization token to use when deleting the file from its hash

        Raises:
            NotFoundError: The requested version wasn't found
            NoAuthorizationError: No authorization to delete this file
            InvalidRequestError: Invalid request

        Returns:
            (bool): If the file deletion was successful
        """
        raw_response = _requests.delete(
            f"https://api.modrinth.com/v2/version_file/{hash}",
            params={"algorithm": algorithm, "version_id": version_id},
            headers={"authorization": auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError(
                    "The requested version was not found"
                )
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to delete this file"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    @property
    def files(self) -> list[Project._File]:
        return [Project._File._from_json(file) for file in self.version_model.file_parts]  # type: ignore

    def download(self, recursive: bool = False) -> None:
        """Download the files associated with the version.

        Args:
            recursive (bool, optional): Whether to also download the files of the dependencies
        """
        for file in self.files:
            file_content = _requests.get(file.url, timeout=60).content
            open(file.name, "wb").write(file_content)
        if recursive:
            dependencies = self.dependencies
            for dep in dependencies:
                files = dep.version.files
                for file in files:
                    file_content = _requests.get(file.url, timeout=60).content
                    open(file.name, "wb").write(file_content)

    @property
    def project(self) -> Project:
        return Project.get(self.version_model.project_id)

    @property
    def primary_files(self) -> list[Project._File]:
        result = []
        for file in self.files:
            if file.primary:
                result.append(file)
        return result

    @property
    def author(self) -> _users.User:
        user = _users.User.get(self.version_model.author_id)
        return user

    @property
    def is_featured(self) -> bool:
        """Check if the version is featured.

        Returns:
            (bool): Whether the version is featured
        """
        return self.version_model.featured

    @property
    def date_published(self) -> _datetime.datetime:
        return _util.format_time(self.version_model.date_published)

    @property
    def downloads(self) -> int:
        return self.version_model.downloads

    @property
    def name(self) -> str:
        return self.version_model.name

    @property
    def version_number(self) -> str:
        return self.version_model.version_number

    def __repr__(self) -> str:
        return f"Version: {self.version_model.name}"

Check if the version is featured.

Returns:

Type Description
bool

Whether the version is featured

delete_file_from_hash(auth, hash, version_id, algorithm='sha1') staticmethod

Delete a file from its hash.

Parameters:

Name Type Description Default
hash str

The hash of the file, considering its byte content, and encoded in hexadecimal

required
algorithm Literal['sha512', 'sha1']

The algorithm of the hash

'sha1'
version_id bool

Version ID to delete the version from if multiple files of the same hash exist

required
auth str

The authorization token to use when deleting the file from its hash

required

Raises:

Type Description
NotFoundError

The requested version wasn't found

NoAuthorizationError

No authorization to delete this file

InvalidRequestError

Invalid request

Returns:

Type Description
bool

If the file deletion was successful

Source code in src/pyrinth/projects.py
@staticmethod
def delete_file_from_hash(
    auth: str,
    hash: str,
    version_id: str,
    algorithm: _literals.sha_algorithm_literal = "sha1",
) -> bool:
    """Delete a file from its hash.

    Args:
        hash (str): The hash of the file, considering its byte content, and encoded in hexadecimal
        algorithm (Literal["sha512", "sha1"]): The algorithm of the hash
        version_id (bool): Version ID to delete the version from if multiple files of the same hash exist
        auth (str): The authorization token to use when deleting the file from its hash

    Raises:
        NotFoundError: The requested version wasn't found
        NoAuthorizationError: No authorization to delete this file
        InvalidRequestError: Invalid request

    Returns:
        (bool): If the file deletion was successful
    """
    raw_response = _requests.delete(
        f"https://api.modrinth.com/v2/version_file/{hash}",
        params={"algorithm": algorithm, "version_id": version_id},
        headers={"authorization": auth},
        timeout=60,
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError(
                "The requested version was not found"
            )
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to delete this file"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

download(recursive=False)

Download the files associated with the version.

Parameters:

Name Type Description Default
recursive bool

Whether to also download the files of the dependencies

False
Source code in src/pyrinth/projects.py
def download(self, recursive: bool = False) -> None:
    """Download the files associated with the version.

    Args:
        recursive (bool, optional): Whether to also download the files of the dependencies
    """
    for file in self.files:
        file_content = _requests.get(file.url, timeout=60).content
        open(file.name, "wb").write(file_content)
    if recursive:
        dependencies = self.dependencies
        for dep in dependencies:
            files = dep.version.files
            for file in files:
                file_content = _requests.get(file.url, timeout=60).content
                open(file.name, "wb").write(file_content)

get(id) staticmethod

Get a version by ID.

Parameters:

Name Type Description Default
id str

The ID of the version

required

Raises:

Type Description
NotFoundError

The requested version wasn't found or no authorization to see this version

InvalidRequestError

Invalid request

Returns:

Type Description
Project.Version

The version that was found

Source code in src/pyrinth/projects.py
@staticmethod
def get(id: str) -> Project.Version:
    """Get a version by ID.

    Args:
        id (str): The ID of the version

    Raises:
        NotFoundError: The requested version wasn't found or no authorization to see this version
        InvalidRequestError: Invalid request

    Returns:
        (Project.Version): The version that was found
    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/version/{id}", timeout=60
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError(
                "The requested version wasn't found or no authorization to see this version"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    return Project.Version(_models.VersionModel._from_json(response))

get_from_hash(hash, algorithm='sha1', multiple=False) staticmethod

Get a version by hash.

Parameters:

Name Type Description Default
hash str

The hash of the file, considering its byte content, and encoded in hexadecimal

required
algorithm Literal['sha512', 'sha1']

The algorithm of the hash

'sha1'
multiple bool

Whether to return multiple results when looking for this hash

False

Raises:

Type Description
NotFoundError

The requested version file wasn't found or no authorization to see this version

InvalidRequestError

Invalid request

Returns:

Type Description
Project.Version

The version that was found

Source code in src/pyrinth/projects.py
@staticmethod
def get_from_hash(
    hash: str,
    algorithm: _literals.sha_algorithm_literal = "sha1",
    multiple: bool = False,
) -> Project.Version | list[Project.Version]:
    """Get a version by hash.

    Args:
        hash (str): The hash of the file, considering its byte content, and encoded in hexadecimal
        algorithm (Literal["sha512", "sha1"]): The algorithm of the hash
        multiple (bool): Whether to return multiple results when looking for this hash

    Raises:
        NotFoundError: The requested version file wasn't found or no authorization to see this version
        InvalidRequestError: Invalid request

    Returns:
        (Project.Version): The version that was found
    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/version_file/{hash}",
        params={"algorithm": algorithm, "multiple": str(multiple).lower()},
        timeout=60,
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError(
                "The requested version file wasn't found or no authorization to see this version"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    if isinstance(response, list):
        return [
            Project.Version(_models.VersionModel._from_json(version))
            for version in response
        ]
    return Project.Version(_models.VersionModel._from_json(response))

Add a gallery image to the project.

Parameters:

Name Type Description Default
image Project.GalleryImage

The gallery image to add

required
auth str

The authorization token to use when adding the gallery image

None

Raises:

Type Description
NoAuthorizationError

No authorization to create a gallery image

NotFoundError

The requested project wasn't found or no authorization to see this project

InvalidRequestError

Invalid request

Returns:

Type Description
bool

If the gallery image addition was successful

Source code in src/pyrinth/projects.py
def add_gallery_image(
    self, image: Project.GalleryImage, auth: str | None = None
) -> bool:
    """Add a gallery image to the project.

    Args:
        image (Project.GalleryImage): The gallery image to add
        auth (str, optional): The authorization token to use when adding the gallery image

    Raises:
        NoAuthorizationError: No authorization to create a gallery image
        NotFoundError: The requested project wasn't found or no authorization to see this project
        InvalidRequestError: Invalid request

    Returns:
        (bool): If the gallery image addition was successful
    """
    raw_response = _requests.post(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}/gallery",
        headers={"authorization": self._get_auth(auth)},
        params=image._to_json(),
        data=open(image.file_path, "rb"),
        timeout=60,
    )
    match raw_response.status_code:
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to create a gallery image"
            )
        case 404:
            raise _exceptions.NotFoundError(
                "The requested project wasn't found or no authorization to see this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

change_icon(file_path, auth=None)

Change the project icon.

Parameters:

Name Type Description Default
file_path str

The file path of the image to use for the new project icon

required
auth str

The authorization token to use when changing the project icon

None

Raises:

Type Description
InvalidParamError

Invalid input for new icon

InvalidRequestError

Invalid request

Returns:

Type Description
bool

Whether the project icon change was successful

Source code in src/pyrinth/projects.py
def change_icon(self, file_path: str, auth: str | None = None) -> bool:
    """Change the project icon.

    Args:
        file_path (str): The file path of the image to use for the new project icon
        auth (str, optional): The authorization token to use when changing the project icon

    Raises:
        InvalidParamError: Invalid input for new icon
        InvalidRequestError: Invalid request

    Returns:
        (bool): Whether the project icon change was successful
    """
    raw_response = _requests.patch(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}/icon",
        params={"ext": file_path.split(".")[-1]},
        headers={"authorization": self._get_auth(auth)},
        data=open(file_path, "rb"),
        timeout=60,
    )
    match raw_response.status_code:
        case 400:
            raise _exceptions.InvalidParamError("Invalid input for new icon")
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

create_version(version_model, auth=None)

Create a new version on the project.

Parameters:

Name Type Description Default
auth str

The authorization token to use when creating the version

None
version_model VersionModel

The model to use when creating the version

required

Raises:

Type Description
NoAuthorizationError

No authorization to create this version

InvalidRequestError

Invalid request

Returns:

Type Description
int

Whether creating the version was successful

Source code in src/pyrinth/projects.py
def create_version(
    self, version_model: _models.VersionModel, auth: str | None = None
) -> int:
    """Create a new version on the project.

    Args:
        auth (str, optional): The authorization token to use when creating the version
        version_model (VersionModel): The model to use when creating the version

    Raises:
        NoAuthorizationError: No authorization to create this version
        InvalidRequestError: Invalid request

    Returns:
        (int): Whether creating the version was successful
    """
    version_model.project_id = self.id

    files = {}

    for file in version_model.file_parts:
        files[file] = open(file, "rb")

    raw_response = _requests.post(
        "https://api.modrinth.com/v2/version",
        headers={"authorization": self._get_auth(auth)},
        data={"data": _json.dumps(version_model._to_json())},
        files=files,
        timeout=60,
    )
    match raw_response.status_code:
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to create this version"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

delete(auth=None)

Delete the project.

Parameters:

Name Type Description Default
auth str

Authentication token to use when deleting the project

None

Raises:

Type Description
NotFoundError

The requested project wasn't found

NoAuthorizationError

No authorization to delete this project

InvalidRequestError

Invalid request

Returns:

Type Description
bool

Whether the project deletion was successful

Source code in src/pyrinth/projects.py
def delete(self, auth: str | None = None) -> bool:
    """Delete the project.

    Args:
        auth (str, optional): Authentication token to use when deleting the project

    Raises:
        NotFoundError: The requested project wasn't found
        NoAuthorizationError: No authorization to delete this project
        InvalidRequestError: Invalid request

    Returns:
        (bool): Whether the project deletion was successful
    """
    raw_response = _requests.delete(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}",
        headers={"authorization": self._get_auth(auth)},
        timeout=60,
    )
    match raw_response.status_code:
        case 400:
            raise _exceptions.NotFoundError("The requested project was not found")
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to delete this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

Delete a gallery image.

Parameters:

Name Type Description Default
url str

URL link of the image to delete

required
auth str

Authentication token to use when deleting the gallery image

None

Raises:

Type Description
InvalidParamError

Invalid URL or project specified

NoAuthorizationError

No authorization to delete this gallery image

InvalidRequestError

Invalid request

Returns:

Type Description
bool

Whether the gallery image deletion was successful

Source code in src/pyrinth/projects.py
def delete_gallery_image(self, url: str, auth: str | None = None) -> bool:
    """Delete a gallery image.

    Args:
        url (str): URL link of the image to delete
        auth (str, optional): Authentication token to use when deleting the gallery image

    Raises:
        InvalidParamError: Invalid URL or project specified
        NoAuthorizationError: No authorization to delete this gallery image
        InvalidRequestError: Invalid request

    Returns:
        (bool): Whether the gallery image deletion was successful
    """
    if "-raw" in url:
        raise _exceptions.InvalidParamError(
            "Please use cdn.modrinth.com instead of cdn-raw.modrinth.com"
        )
    raw_response = _requests.delete(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}/gallery",
        headers={"authorization": self._get_auth(auth)},
        params={"url": url},
        timeout=60,
    )
    match raw_response.status_code:
        case 400:
            raise _exceptions.InvalidParamError("Invalid URL or project specified")
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to delete this gallery image"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

delete_icon(auth=None)

Delete the project icon.

Parameters:

Name Type Description Default
auth str

The authorization token to use when deleting the project icon

None

Raises:

Type Description
InvalidParamError

Invalid input

NoAuthorizationError

No authorization to edit this project

InvalidRequestError

Invalid request

Returns:

Type Description
bool

Whether the project icon deletion was successful

Source code in src/pyrinth/projects.py
def delete_icon(self, auth: str | None = None) -> bool:
    """Delete the project icon.

    Args:
        auth (str, optional): The authorization token to use when deleting the project icon

    Raises:
        InvalidParamError: Invalid input
        NoAuthorizationError: No authorization to edit this project
        InvalidRequestError: Invalid request

    Returns:
        (bool): Whether the project icon deletion was successful
    """
    raw_response = _requests.delete(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}/icon",
        headers={"authorization": self._get_auth(auth)},
        timeout=60,
    )
    match raw_response.status_code:
        case 400:
            raise _exceptions.InvalidParamError("Invalid input")
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to edit this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

download(recursive=False)

Download the project.

Parameters:

Name Type Description Default
recursive bool

Whether to download dependencies. Defaults to False

False
Source code in src/pyrinth/projects.py
def download(self, recursive: bool = False) -> int:
    """Download the project.

    Args:
        recursive (bool): Whether to download dependencies. Defaults to False
    """
    latest = self.get_latest_version()
    if latest is None:
        return 0
    files = latest.files
    for file in files:
        file_content = _requests.get(file.url, timeout=60).content
        open(file.name, "wb").write(file_content)
    if recursive:
        dependencies = latest.dependencies
        for dep in dependencies:
            files = dep.version.files
            for file in files:
                file_content = _requests.get(file.url, timeout=60).content
                open(file.name, "wb").write(file_content)
    return 1

get(id, authorization='') staticmethod

Get a project by ID or slug.

Parameters:

Name Type Description Default
id str

The ID or slug of the project

required
authorization str

An optional authorization token when getting the project

''

Raises:

Type Description
NotFoundError

The requested project wasn't found or no authorization to see this project

InvalidRequestError

Invalid request

Returns:

Type Description
Project

The project that was found

Source code in src/pyrinth/projects.py
@staticmethod
def get(id: str, authorization: str = "") -> Project:
    """Get a project by ID or slug.

    Args:
        id (str): The ID or slug of the project
        authorization (str, optional): An optional authorization token when getting the project

    Raises:
        NotFoundError: The requested project wasn't found or no authorization to see this project
        InvalidRequestError: Invalid request

    Returns:
        (Project): The project that was found
    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/project/{id}",
        headers={"authorization": authorization},
        timeout=60,
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError(
                "The requested project wasn't found or no authorization to see this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    response.update({"authorization": authorization})
    return Project(_models.ProjectModel._from_json(response))

get_latest_version(loaders=None, game_versions=None, featured=None, type=None, auth=None)

Get the projects latest version.

Parameters:

Name Type Description Default
loaders list[str]

The loaders filter. Defaults to None

None
game_versions list[str]

The game versions filter. Defaults to None

None
featured bool

The is featured filter. Defaults to None

None
type Literal['release', 'beta', 'alpha']

The types filter. Defaults to None

None
auth str

The authorization token. Defaults to None

None

Returns:

Type Description
Project.Version

The project's latest version

Source code in src/pyrinth/projects.py
def get_latest_version(
    self,
    loaders: list[_literals.loader_literal] | None = None,
    game_versions: list[_literals.game_version_literal] | None = None,
    featured: bool | None = None,
    type: _literals.version_type_literal | None = None,
    auth: str | None = None,
) -> Project.Version | None:
    """Get the projects latest version.

    Args:
        loaders (list[str], optional): The loaders filter. Defaults to None
        game_versions (list[str], optional): The game versions filter. Defaults to None
        featured (bool, optional): The is featured filter. Defaults to None
        type (Literal["release", "beta", "alpha"], optional): The types filter. Defaults to None
        auth (str, optional): The authorization token. Defaults to None

    Returns:
        (Project.Version): The project's latest version
    """
    versions = self.get_versions(loaders, game_versions, featured, type, auth)
    if len(versions) == 0:
        return None
    return versions[0]

get_multiple(ids) staticmethod

Get multiple projects.

Parameters:

Name Type Description Default
ids list[str]

The IDs of the projects

required

Raises:

Type Description
InvalidRequestError

Invalid request

Returns:

Type Description
list[Project]

The projects that were found

Source code in src/pyrinth/projects.py
@staticmethod
def get_multiple(ids: list[str]) -> list[Project]:
    """Get multiple projects.

    Args:
        ids (list[str]): The IDs of the projects

    Raises:
        InvalidRequestError: Invalid request

    Returns:
        (list[Project]): The projects that were found
    """
    raw_response = _requests.get(
        "https://api.modrinth.com/v2/projects",
        params={"ids": _json.dumps(ids)},
        timeout=60,
    )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    return [
        Project(_models.ProjectModel._from_json(project_json))
        for project_json in response
    ]

get_oldest_version(loaders=None, game_versions=None, featured=None, type=None, auth=None)

Get the oldest project version.

Parameters:

Name Type Description Default
loaders list[str]

The types of loaders to filter for

None
game_versions list[str]

The game versions to filter for

None
featured bool

Allows to filter for featured or non-featured versions only

None
type Literal['release', 'beta', 'alpha']

The type of version

None
auth str

An optional authorization token to use when getting the project versions

None

Returns:

Type Description
Project.Version

The version that was found

Source code in src/pyrinth/projects.py
def get_oldest_version(
    self,
    loaders: list[_literals.loader_literal] | None = None,
    game_versions: list[_literals.game_version_literal] | None = None,
    featured: bool | None = None,
    type: _literals.version_type_literal | None = None,
    auth: str | None = None,
) -> Project.Version | None:
    """Get the oldest project version.

    Args:
        loaders (list[str], optional): The types of loaders to filter for
        game_versions (list[str], optional): The game versions to filter for
        featured (bool, optional): Allows to filter for featured or non-featured versions only
        type (Literal["release", "beta", "alpha"], optional): The type of version
        auth (str, optional): An optional authorization token to use when getting the project versions

    Returns:
        (Project.Version): The version that was found
    """
    versions = self.get_versions(loaders, game_versions, featured, type, auth)
    if len(versions) == 0:
        return None
    return versions[-1]

get_specific_version(semantic_version)

Get a specific version based on the semantic version.

Parameters:

Name Type Description Default
semantic_version str

The semantic version to search for

required

Returns:

Type Description
Project.Version

The version that was found using the semantic version

None

No version was found with that semantic version

Source code in src/pyrinth/projects.py
def get_specific_version(self, semantic_version: str) -> Project.Version | None:
    """Get a specific version based on the semantic version.

    Args:
        semantic_version (str): The semantic version to search for

    Returns:
        (Project.Version): The version that was found using the semantic version
        (None): No version was found with that semantic version
    """
    versions = self.get_versions()
    if versions:
        for version in versions:
            if version.version_model.version_number == semantic_version:
                return version
    return None

get_version(id) staticmethod

Get a version by ID.

Parameters:

Name Type Description Default
id str

The ID of the version

required

Raises:

Type Description
NotFoundError

The requested version wasn't found or no authorization to see this version

InvalidRequestError

Invalid request

Returns:

Type Description
Project.Version

The version that was found

Source code in src/pyrinth/projects.py
@staticmethod
def get_version(id: str) -> Project.Version:
    """Get a version by ID.

    Args:
        id (str): The ID of the version

    Raises:
        NotFoundError: The requested version wasn't found or no authorization to see this version
        InvalidRequestError: Invalid request

    Returns:
        (Project.Version): The version that was found
    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/version/{id}", timeout=60
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError(
                "The requested version wasn't found or no authorization to see this version"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    return Project.Version(_models.VersionModel._from_json(response))

get_versions(loaders=None, game_versions=None, featured=None, types=None, auth=None)

Get project versions based on filters.

Parameters:

Name Type Description Default
loaders list[str]

The types of loaders to filter for

None
game_versions list[str]

The game versions to filter for

None
featured bool

Allows to filter for featured or non-featured versions only

None
types Literal['release', 'beta', 'alpha']

The release type of version

None
auth str

An optional authorization token to use when getting the project versions

None

Raises:

Type Description
NotFoundError

The requested project wasn't found or no authorization to see this project

InvalidRequestError

Invalid request

Returns:

Type Description
list[Project.Version]

The versions that were found

Source code in src/pyrinth/projects.py
def get_versions(
    self,
    loaders: list[_literals.loader_literal] | None = None,
    game_versions: list[_literals.game_version_literal] | None = None,
    featured: bool | None = None,
    types: _literals.version_type_literal | None = None,
    auth: str | None = None,
) -> list[Project.Version]:
    """Get project versions based on filters.

    Args:
        loaders (list[str], optional): The types of loaders to filter for
        game_versions (list[str], optional): The game versions to filter for
        featured (bool, optional): Allows to filter for featured or non-featured versions only
        types (Literal["release", "beta", "alpha"], optional): The release type of version
        auth (str, optional): An optional authorization token to use when getting the project versions

    Raises:
        NotFoundError: The requested project wasn't found or no authorization to see this project
        InvalidRequestError: Invalid request

    Returns:
        (list[Project.Version]): The versions that were found
    """
    filters = {
        "loaders": loaders,
        "game_versions": game_versions,
        "featured": featured,
    }
    filters = _util.remove_null_values(filters)
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}/version",
        params=_util.json_to_query_params(filters),
        headers={"authorization": self._get_auth(auth)},
        timeout=60,
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError(
                "The requested project wasn't found or no authorization to see this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    versions = [
        self.Version(_models.VersionModel._from_json(version))
        for version in response
    ]
    if not types:
        return versions
    result = []
    for version in versions:
        if version.version_model.version_type in types:
            result.append(version)
    return result

modify(slug=None, title=None, description=None, categories=None, client_side=None, server_side=None, body=None, additional_categories=None, issues_url=None, source_url=None, wiki_url=None, discord_url=None, license_id=None, license_url=None, status=None, requested_status=None, moderation_message=None, moderation_message_body=None, auth=None)

Modify the project.

Parameters:

Name Type Description Default
slug str

The slug of a project, used for vanity URLs. Regex: ^[\w!@\(()`.+,"\-']{3,64}\)

None
title str

The title or name of the project

None
description str

A short description of the project

None
categories list[str]

A list of categories that the project has

None
client_side str

The client side support of the project

None
server_side str

The server side support of the project

None
body str

A long form description of the project

None
additional_categories list[str]

A list of categories which are searchable but non-primary

None
issues_url str

An optional link to where to submit bugs or issues with the project

None
source_url str

An optional link to the source code of the project

None
wiki_url str

An optional link to the project's wiki page or other relevant information

None
discord_url str

An optional invite link to the project's discord

None
license_id str

The SPDX license ID of a project

None
license_url str

The URL to this license

None
status Literal['approved', 'archived', 'rejected', 'draft', 'unlisted', 'processing', 'withheld', 'scheduled', 'private', 'unknown']

The status of the project

None
requested_status Literal['approved', 'archived', 'unlisted', 'private', 'draft']

The requested status when submitting for review or scheduling the project for release

None
moderation_message str

The title of the moderators' message for the project

None
moderation_message_body str

The body of the moderators' message for the project

None
auth str

Authentication token to use when modifying the project

None

Raises:

Type Description
InvalidParamError

Please specify at least 1 optional argument

NoAuthorizationError

No authorization to modify this project

NotFoundError

The requested project wasn't found or no authorization to see this project

InvalidRequestError

Invalid request

Returns:

Type Description
bool

Whether the project modification was successful

Source code in src/pyrinth/projects.py
def modify(
    self,
    slug: str | None = None,
    title: str | None = None,
    description: str | None = None,
    categories: list[str] | None = None,
    client_side: str | None = None,
    server_side: str | None = None,
    body: str | None = None,
    additional_categories: list[str] | None = None,
    issues_url: str | None = None,
    source_url: str | None = None,
    wiki_url: str | None = None,
    discord_url: str | None = None,
    license_id: str | None = None,
    license_url: str | None = None,
    status: _literals.project_status_literal | None = None,
    requested_status: _literals.requested_project_status_literal | None = None,
    moderation_message: str | None = None,
    moderation_message_body: str | None = None,
    auth: str | None = None,
) -> bool:
    r"""Modify the project.

    Args:
        slug (str, optional): The slug of a project, used for vanity URLs. Regex: ^[\w!@$()`.+,"\-']{3,64}$
        title (str, optional): The title or name of the project
        description (str, optional): A short description of the project
        categories (list[str], optional): A list of categories that the project has
        client_side (str, optional): The client side support of the project
        server_side (str, optional): The server side support of the project
        body (str, optional): A long form description of the project
        additional_categories (list[str], optional): A list of categories which are searchable but non-primary
        issues_url (str, optional): An optional link to where to submit bugs or issues with the project
        source_url (str, optional): An optional link to the source code of the project
        wiki_url (str, optional): An optional link to the project's wiki page or other relevant information
        discord_url (str, optional): An optional invite link to the project's discord
        license_id (str, optional): The SPDX license ID of a project
        license_url (str, optional): The URL to this license
        status (Literal["approved", "archived", "rejected", "draft", "unlisted", "processing", "withheld", "scheduled", "private", "unknown"], optional): The status of the project
        requested_status (Literal["approved", "archived", "unlisted", "private", "draft"], optional): The requested status when submitting for review or scheduling the project for release
        moderation_message (str, optional): The title of the moderators' message for the project
        moderation_message_body (str, optional): The body of the moderators' message for the project
        auth (str, optional): Authentication token to use when modifying the project

    Raises:
        InvalidParamError: Please specify at least 1 optional argument
        NoAuthorizationError: No authorization to modify this project
        NotFoundError: The requested project wasn't found or no authorization to see this project
        InvalidRequestError: Invalid request

    Returns:
        (bool): Whether the project modification was successful
    """
    modified_json = {
        "slug": slug,
        "title": title,
        "description": description,
        "categories": categories,
        "client_side": client_side,
        "server_side": server_side,
        "body": body,
        "additional_categories": additional_categories,
        "issues_url": issues_url,
        "source_url": source_url,
        "wiki_url": wiki_url,
        "discord_url": discord_url,
        "license_id": license_id,
        "license_url": license_url,
        "status": status,
        "requested_status": requested_status,
        "moderation_message": moderation_message,
        "moderation_message_body": moderation_message_body,
    }
    modified_json = _util.remove_null_values(modified_json)
    if not modified_json:
        raise _exceptions.InvalidParamError(
            "Please specify at least 1 optional argument"
        )
    raw_response = _requests.patch(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}",
        data=_json.dumps(modified_json),
        headers={
            "Content-Type": "application/json",
            "authorization": self._get_auth(auth),
        },
        timeout=60,
    )
    match raw_response.status_code:
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to edit this project"
            )
        case 404:
            raise _exceptions.NotFoundError(
                "The requested project wasn't found or no authorization to see this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

Modify a gallery image.

Parameters:

Name Type Description Default
url str

URL link of the image to modify

required
featured bool

Whether the image is featured

None
title str

New title of the image

None
description str

New description of the image

None
ordering int

New ordering of the image

None
auth str

Authentication token when modifying the gallery image

None

Raises:

Type Description
NoAuthorizationError

No authorization to edit this gallery image

NotFoundError

The requested project wasn't found or no authorization to see this project

InvalidRequestError

Invalid request

Returns:

Type Description
bool

Whether the gallery image modification was successful

Source code in src/pyrinth/projects.py
def modify_gallery_image(
    self,
    url: str,
    featured: bool | None = None,
    title: str | None = None,
    description: str | None = None,
    ordering: int | None = None,
    auth: str | None = None,
) -> bool:
    """Modify a gallery image.

    Args:
        url (str): URL link of the image to modify
        featured (bool, optional): Whether the image is featured
        title (str, optional): New title of the image
        description (str, optional): New description of the image
        ordering (int, optional): New ordering of the image
        auth (str, optional): Authentication token when modifying the gallery image

    Raises:
        NoAuthorizationError: No authorization to edit this gallery image
        NotFoundError: The requested project wasn't found or no authorization to see this project
        InvalidRequestError: Invalid request

    Returns:
        (bool): Whether the gallery image modification was successful
    """
    modified_json = {
        "url": url,
        "featured": featured,
        "title": title,
        "description": description,
        "ordering": ordering,
    }
    modified_json = _util.remove_null_values(modified_json)
    raw_response = _requests.patch(
        f"https://api.modrinth.com/v2/project/{self.project_model.slug}/gallery",
        params=modified_json,
        headers={"authorization": self._get_auth(auth)},
        timeout=60,
    )
    match raw_response.status_code:
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to edit this gallery image"
            )
        case 404:
            raise _exceptions.NotFoundError(
                "The requested project wasn't found or no authorization to see this project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

search(query='', facets=None, index='relevance', offset=0, limit=10, filters=None) staticmethod

Search for projects.

Parameters:

Name Type Description Default
query str

The query to search for

''
facets list[list[str]]

The recommended way of filtering search results. Learn more about using facets

None
index Literal['relevance', 'downloads', 'follows', 'newest', 'updated']

The sorting method used for sorting search results

'relevance'
offset int

The offset into the search. Skip this number of results

0
limit int

The number of results returned by the search

10
filters list[str]

A list of filters relating to the properties of a project. Use filters when there isn't an available facet for your needs. More information

None

Raises:

Type Description
NotFoundError

The requested project wasn't found or no authorization to see this project

InvalidRequestError

Invalid request

Returns:

Type Description
list[Project.SearchResult]

The project search results

Source code in src/pyrinth/projects.py
@staticmethod
def search(
    query: str = "",
    facets: list[list[str]] | None = None,
    index: _literals.index_literal = "relevance",
    offset: int = 0,
    limit: int = 10,
    filters: list[str] | None = None,
) -> list[Project._SearchResult]:
    """Search for projects.

    Args:
        query (str, optional): The query to search for
        facets (list[list[str]], optional): The recommended way of filtering search results. [Learn more about using facets](https://docs.modrinth.com/docs/tutorials/api_search)
        index (Literal["relevance", "downloads", "follows", "newest", "updated"], optional): The sorting method used for sorting search results
        offset (int, optional): The offset into the search. Skip this number of results
        limit (int, optional): The number of results returned by the search
        filters (list[str], optional): A list of filters relating to the properties of a project. Use filters when there isn't an available facet for your needs. [More information](https://docs.meilisearch.com/reference/features/filtering.html)

    Raises:
        NotFoundError: The requested project wasn't found or no authorization to see this project
        InvalidRequestError: Invalid request

    Returns:
        (list[Project.SearchResult]): The project search results
    """
    params = {}
    if query != "":
        params.update({"query": query})
    if facets:
        params.update({"facets": _json.dumps(facets)})
    if index != "relevance":
        params.update({"index": index})
    if offset != 0:
        params.update({"offset": str(offset)})
    if limit != 10:
        params.update({"limit": str(limit)})
    if filters:
        params.update({"filters": _json.dumps(filters)})
    raw_response = _requests.get(
        "https://api.modrinth.com/v2/search", params=params, timeout=60
    )
    response: dict = raw_response.json()
    return [
        Project._SearchResult(_models._SearchResultModel._from_json(project))
        for project in response.get("hits", ...)
    ]



Used for users.

User

Source code in src/pyrinth/users.py
class User:
    def __init__(self, user_model: _models._UserModel) -> None:
        self.user_model = user_model

    def __repr__(self) -> str:
        return f"User: {(self.user_model.name if self.user_model.name else self.user_model.username)}"

    @property
    def auth(self) -> str:
        return self.user_model.auth

    @staticmethod
    def _from_json(user_json: dict) -> User:
        return User(_models._UserModel._from_json(user_json))

    @property
    def payout_history(self) -> _PayoutHistory:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/user/{self.user_model.username}/payouts",
            headers={"authorization": self.user_model.auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to get this user's payout history"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return User._PayoutHistory(
            response["all_time"], response["last_month"], response["payouts"]
        )

    def withdraw_balance(self, amount: int) -> _typing.Literal[True]:
        raw_response = _requests.post(
            f"https://api.modrinth.com/v2/user/{self.user_model.id}/payouts",
            headers={
                "content-type": "application/json",
                "authorization": self.user_model.auth,
            },
            json={"amount": amount},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to withdraw this user's balance"
                )
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def change_avatar(self, file_path) -> _typing.Literal[True]:
        raw_response = _requests.patch(
            f"https://api.modrinth.com/v2/user/{self.user_model.id}/icon",
            headers={"authorization": self.user_model.auth},
            params={"ext": file_path.split(".")[-1]},
            data=open(file_path, "rb"),
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.InvalidParamError("Invalid format for new icon")
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    @staticmethod
    def get(id: str, auth=None) -> User:
        """Get a user.

        Args:
            id (str): The user's ID to find
            auth (str, optional): The authorization token to use when creating the user. Defaults to None

        Raises:
            NotFoundError: The user was not found
            InvalidRequestError: An invalid API call was sent

        Returns:
            (User): The user that was found
        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/user/{id}", timeout=60
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        response.update({"authorization": auth})
        return User(_models._UserModel._from_json(response))

    @property
    def date_created(self) -> _datetime.datetime:
        return _util.format_time(self.user_model.created)

    @property
    def followed_projects(self) -> list[_projects.Project]:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/user/{self.user_model.username}/follows",
            headers={"authorization": self.user_model.auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to get this user's followed projects"
                )
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            _projects.Project(_models.ProjectModel._from_json(project_json))
            for project_json in response
        ]

    @property
    def notifications(self) -> list[_Notification]:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/user/{self.user_model.username}/notifications",
            headers={"authorization": self.user_model.auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to get this user's notifications"
                )
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            User._Notification._from_json(notification) for notification in response
        ]

    def create_project(
        self, project_model: _models.ProjectModel, icon: str | None = None
    ) -> int:
        """
        Create a project.

        Args:
            project_model (ProjectModel): The model of the project to create
            icon (str): The path of the icon to use for the newly created project

        Returns:
            (int): If the project creation was successful
        """
        files: dict = {"data": project_model._to_bytes()}
        if icon:
            files.update({"icon": open(icon, "rb")})
        raw_response = _requests.post(
            "https://api.modrinth.com/v2/project",
            files=files,
            headers={"authorization": self.user_model.auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to create a project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    @property
    def projects(self) -> list[_projects.Project]:
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/user/{self.user_model.id}/projects",
            timeout=60,
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [
            _projects.Project(_models.ProjectModel._from_json(project_json))
            for project_json in response
        ]

    def follow_project(self, id: str) -> int:
        """
        Follow a project.

        Args:
            id (str): The ID of the project to follow

        Returns:
            (int): If the project follow was successful
        """
        raw_response = _requests.post(
            f"https://api.modrinth.com/v2/project/{id}/follow",
            headers={"authorization": self.user_model.auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 400:
                raise _exceptions.NotFoundError(
                    "The requested project was not found or you are already following the specified project"
                )
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to follow a project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    def unfollow_project(self, id: str) -> int:
        """
        Unfollow a project.

        Args:
            id (str): The ID of the project to unfollow

        Returns:
            (int): If the project unfollow was successful
        """
        raw_response = _requests.delete(
            f"https://api.modrinth.com/v2/project/{id}/follow",
            headers={"authorization": self.user_model.auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 400:
                raise _exceptions.NotFoundError(
                    "The requested project was not found or you are not following the specified project"
                )
            case 401:
                raise _exceptions.NoAuthorizationError(
                    "No authorization to unfollow a project"
                )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return True

    @staticmethod
    def get_from_auth(auth: str) -> User:
        """
        Get a user from authorization token.

        Returns:
            (User): The user that was found using the authorization token
        """
        raw_response = _requests.get(
            "https://api.modrinth.com/v2/user",
            headers={"authorization": auth},
            timeout=60,
        )
        match raw_response.status_code:
            case 401:
                raise _exceptions.InvalidParamError("Invalid authorization token")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        response.update({"authorization": auth})
        return User._from_json(response)

    @staticmethod
    def from_id(id: str) -> User:
        """
        Get a user from ID.

        Returns
            (User): The user that was found using the ID

        """
        raw_response = _requests.get(
            f"https://api.modrinth.com/v2/user/{id}", timeout=60
        )
        match raw_response.status_code:
            case 404:
                raise _exceptions.NotFoundError("The requested user was not found")
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        return User._from_json(raw_response.json())

    @staticmethod
    def from_ids(ids: list[str]) -> list[User]:
        """
        Get a users from IDs.

        Returns:
            (User): The users that were found using the IDs

        """
        raw_response = _requests.get(
            "https://api.modrinth.com/v2/users",
            params={"ids": _json.dumps(ids)},
            timeout=60,
        )
        if not raw_response.ok:
            raise _exceptions.InvalidRequestError(raw_response.text)
        response: dict = raw_response.json()
        return [User.get(user.get("username")) for user in response]

    class _Notification:
        """Used for the user's notifications."""

        id: str
        user_id: str
        type: str
        title: str
        text: str
        link: str
        read: str
        created: str
        actions: str
        project_title: str

        def __repr__(self) -> str:
            return f"Notification: {self.text}"

        @staticmethod
        def _from_json(notification_json: dict) -> User._Notification:
            result = User._Notification()
            result.id = notification_json.get("id", ...)
            result.user_id = notification_json.get("user_id", ...)
            result.type = notification_json.get("type", ...)
            result.title = notification_json.get("title", ...)
            result.text = notification_json.get("text", ...)
            result.link = notification_json.get("link", ...)
            result.read = notification_json.get("read", ...)
            result.created = notification_json.get("created", ...)
            result.actions = notification_json.get("actions", ...)
            result.project_title = result.title.split("**")[1]
            return result

    @dataclasses.dataclass
    class _PayoutHistory:
        all_time: float
        last_month: float
        payouts: list

        def __repr__(self) -> str:
            return f"PayoutHistory: {self.all_time}"

create_project(project_model, icon=None)

Create a project.

Parameters:

Name Type Description Default
project_model ProjectModel

The model of the project to create

required
icon str

The path of the icon to use for the newly created project

None

Returns:

Type Description
int

If the project creation was successful

Source code in src/pyrinth/users.py
def create_project(
    self, project_model: _models.ProjectModel, icon: str | None = None
) -> int:
    """
    Create a project.

    Args:
        project_model (ProjectModel): The model of the project to create
        icon (str): The path of the icon to use for the newly created project

    Returns:
        (int): If the project creation was successful
    """
    files: dict = {"data": project_model._to_bytes()}
    if icon:
        files.update({"icon": open(icon, "rb")})
    raw_response = _requests.post(
        "https://api.modrinth.com/v2/project",
        files=files,
        headers={"authorization": self.user_model.auth},
        timeout=60,
    )
    match raw_response.status_code:
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to create a project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

follow_project(id)

Follow a project.

Parameters:

Name Type Description Default
id str

The ID of the project to follow

required

Returns:

Type Description
int

If the project follow was successful

Source code in src/pyrinth/users.py
def follow_project(self, id: str) -> int:
    """
    Follow a project.

    Args:
        id (str): The ID of the project to follow

    Returns:
        (int): If the project follow was successful
    """
    raw_response = _requests.post(
        f"https://api.modrinth.com/v2/project/{id}/follow",
        headers={"authorization": self.user_model.auth},
        timeout=60,
    )
    match raw_response.status_code:
        case 400:
            raise _exceptions.NotFoundError(
                "The requested project was not found or you are already following the specified project"
            )
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to follow a project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True

from_id(id) staticmethod

Get a user from ID.

Returns (User): The user that was found using the ID

Source code in src/pyrinth/users.py
@staticmethod
def from_id(id: str) -> User:
    """
    Get a user from ID.

    Returns
        (User): The user that was found using the ID

    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/user/{id}", timeout=60
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError("The requested user was not found")
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return User._from_json(raw_response.json())

from_ids(ids) staticmethod

Get a users from IDs.

Returns:

Type Description
User

The users that were found using the IDs

Source code in src/pyrinth/users.py
@staticmethod
def from_ids(ids: list[str]) -> list[User]:
    """
    Get a users from IDs.

    Returns:
        (User): The users that were found using the IDs

    """
    raw_response = _requests.get(
        "https://api.modrinth.com/v2/users",
        params={"ids": _json.dumps(ids)},
        timeout=60,
    )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    return [User.get(user.get("username")) for user in response]

get(id, auth=None) staticmethod

Get a user.

Parameters:

Name Type Description Default
id str

The user's ID to find

required
auth str

The authorization token to use when creating the user. Defaults to None

None

Raises:

Type Description
NotFoundError

The user was not found

InvalidRequestError

An invalid API call was sent

Returns:

Type Description
User

The user that was found

Source code in src/pyrinth/users.py
@staticmethod
def get(id: str, auth=None) -> User:
    """Get a user.

    Args:
        id (str): The user's ID to find
        auth (str, optional): The authorization token to use when creating the user. Defaults to None

    Raises:
        NotFoundError: The user was not found
        InvalidRequestError: An invalid API call was sent

    Returns:
        (User): The user that was found
    """
    raw_response = _requests.get(
        f"https://api.modrinth.com/v2/user/{id}", timeout=60
    )
    match raw_response.status_code:
        case 404:
            raise _exceptions.NotFoundError("The requested user was not found")
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    response.update({"authorization": auth})
    return User(_models._UserModel._from_json(response))

get_from_auth(auth) staticmethod

Get a user from authorization token.

Returns:

Type Description
User

The user that was found using the authorization token

Source code in src/pyrinth/users.py
@staticmethod
def get_from_auth(auth: str) -> User:
    """
    Get a user from authorization token.

    Returns:
        (User): The user that was found using the authorization token
    """
    raw_response = _requests.get(
        "https://api.modrinth.com/v2/user",
        headers={"authorization": auth},
        timeout=60,
    )
    match raw_response.status_code:
        case 401:
            raise _exceptions.InvalidParamError("Invalid authorization token")
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    response: dict = raw_response.json()
    response.update({"authorization": auth})
    return User._from_json(response)

unfollow_project(id)

Unfollow a project.

Parameters:

Name Type Description Default
id str

The ID of the project to unfollow

required

Returns:

Type Description
int

If the project unfollow was successful

Source code in src/pyrinth/users.py
def unfollow_project(self, id: str) -> int:
    """
    Unfollow a project.

    Args:
        id (str): The ID of the project to unfollow

    Returns:
        (int): If the project unfollow was successful
    """
    raw_response = _requests.delete(
        f"https://api.modrinth.com/v2/project/{id}/follow",
        headers={"authorization": self.user_model.auth},
        timeout=60,
    )
    match raw_response.status_code:
        case 400:
            raise _exceptions.NotFoundError(
                "The requested project was not found or you are not following the specified project"
            )
        case 401:
            raise _exceptions.NoAuthorizationError(
                "No authorization to unfollow a project"
            )
    if not raw_response.ok:
        raise _exceptions.InvalidRequestError(raw_response.text)
    return True