cc-ampapi 1.3.0__tar.gz → 5.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {cc_ampapi-1.3.0/cc_ampapi.egg-info → cc_ampapi-5.0.1}/PKG-INFO +187 -84
  2. cc_ampapi-5.0.1/README.md +266 -0
  3. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/ampapi/__init__.py +15 -16
  4. cc_ampapi-5.0.1/ampapi/_enums.py +292 -0
  5. cc_ampapi-5.0.1/ampapi/_types.py +1747 -0
  6. cc_ampapi-5.0.1/ampapi/adsmodule.py +4011 -0
  7. cc_ampapi-5.0.1/ampapi/analytics.py +207 -0
  8. cc_ampapi-5.0.1/ampapi/base.py +2095 -0
  9. cc_ampapi-5.0.1/ampapi/bridge.py +322 -0
  10. cc_ampapi-5.0.1/ampapi/core.py +5262 -0
  11. cc_ampapi-5.0.1/ampapi/emailsender.py +86 -0
  12. cc_ampapi-5.0.1/ampapi/errors.py +107 -0
  13. cc_ampapi-5.0.1/ampapi/filebackup.py +600 -0
  14. cc_ampapi-5.0.1/ampapi/filemanager.py +1140 -0
  15. cc_ampapi-5.0.1/ampapi/generic.py +272 -0
  16. cc_ampapi-5.0.1/ampapi/instance.py +2151 -0
  17. cc_ampapi-5.0.1/ampapi/key_drift.py +353 -0
  18. cc_ampapi-5.0.1/ampapi/minecraft.py +1202 -0
  19. cc_ampapi-5.0.1/ampapi/modules.py +4798 -0
  20. cc_ampapi-5.0.1/ampapi/py.typed +0 -0
  21. cc_ampapi-5.0.1/ampapi/steamcmd.py +147 -0
  22. cc_ampapi-5.0.1/ampapi/util.py +1246 -0
  23. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1/cc_ampapi.egg-info}/PKG-INFO +187 -84
  24. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/SOURCES.txt +7 -5
  25. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/requires.txt +1 -1
  26. cc_ampapi-5.0.1/pyproject.toml +147 -0
  27. cc_ampapi-1.3.0/README.md +0 -162
  28. cc_ampapi-1.3.0/ampapi/adsmodule.py +0 -1822
  29. cc_ampapi-1.3.0/ampapi/analytics.py +0 -70
  30. cc_ampapi-1.3.0/ampapi/base.py +0 -755
  31. cc_ampapi-1.3.0/ampapi/bridge.py +0 -66
  32. cc_ampapi-1.3.0/ampapi/controller.py +0 -159
  33. cc_ampapi-1.3.0/ampapi/core.py +0 -2313
  34. cc_ampapi-1.3.0/ampapi/dataclass.py +0 -2800
  35. cc_ampapi-1.3.0/ampapi/emailsender.py +0 -35
  36. cc_ampapi-1.3.0/ampapi/enums.py +0 -186
  37. cc_ampapi-1.3.0/ampapi/filebackup.py +0 -221
  38. cc_ampapi-1.3.0/ampapi/filemanager.py +0 -555
  39. cc_ampapi-1.3.0/ampapi/instance.py +0 -362
  40. cc_ampapi-1.3.0/ampapi/minecraft.py +0 -602
  41. cc_ampapi-1.3.0/ampapi/modules.py +0 -216
  42. cc_ampapi-1.3.0/ampapi/types_.py +0 -264
  43. cc_ampapi-1.3.0/ampapi/util.py +0 -620
  44. cc_ampapi-1.3.0/pyproject.toml +0 -97
  45. cc_ampapi-1.3.0/requirements.txt +0 -3
  46. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/LICENSE +0 -0
  47. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/LICENSE-dpy +0 -0
  48. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/MANIFEST.in +0 -0
  49. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/dependency_links.txt +0 -0
  50. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/top_level.txt +0 -0
  51. {cc_ampapi-1.3.0 → cc_ampapi-5.0.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-ampapi
3
- Version: 1.3.0
3
+ Version: 5.0.1
4
4
  Summary: A Python wrapper for the AMP API by CubeCoders
5
5
  Author-email: k8thekat <Cadwalladerkatelynn+AMPAPI@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -684,61 +684,90 @@ License: GNU GENERAL PUBLIC LICENSE
684
684
  - docs/extensions/*, Copyright (c) 2015-present Rapptz. For licensing see ./LICENSE-dpy
685
685
 
686
686
  Project-URL: GitHub, https://github.com/k8thekat/AMPAPI_Python
687
- Project-URL: Changelog, https://github.com/k8thekat/AMPAPI_Python/blob/master/CHANGELOG.md
687
+ Project-URL: Changelog, https://github.com/k8thekat/AMPAPI_Python/blob/main/CHANGELOG.md
688
688
  Keywords: cubecoders,cube coders,amp,api
689
689
  Classifier: Development Status :: 5 - Production/Stable
690
690
  Classifier: Intended Audience :: Developers
691
691
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
692
692
  Classifier: Operating System :: OS Independent
693
- Classifier: Programming Language :: Python :: 3.10
694
- Classifier: Programming Language :: Python :: 3.11
695
693
  Classifier: Programming Language :: Python :: 3.12
694
+ Classifier: Programming Language :: Python :: 3.13
696
695
  Classifier: Framework :: AsyncIO
697
696
  Classifier: Topic :: Internet
698
697
  Classifier: Topic :: Software Development :: Libraries
699
698
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
700
699
  Classifier: Topic :: Utilities
701
700
  Classifier: Typing :: Typed
702
- Requires-Python: >=3.10.0
701
+ Requires-Python: >=3.12.0
703
702
  Description-Content-Type: text/markdown
704
703
  License-File: LICENSE
705
704
  License-File: LICENSE-dpy
706
705
  Requires-Dist: aiohttp>=3.7.4.post0
707
- Requires-Dist: dataclass_wizard>=0.22.2
708
706
  Requires-Dist: pyotp>=2.6.0
707
+ Requires-Dist: typing_extensions>=4.12.0
709
708
  Dynamic: license-file
710
709
 
711
710
  # AMP API Python
712
- ___
713
- CubeCoders AMP API wrapper in Python.
714
711
 
712
+ ---
713
+
714
+ An asynchronous Python wrapper for the CubeCoders AMP (Application Management Panel) API, enabling developers to programmatically manage game server Instances with a clean, Pythonic interface.
715
715
 
716
716
  <div align="left">
717
717
  <a href="https://discord.gg/BtNyU8DFtt"><img src='https://img.shields.io/discord/705500489248145459?color=blue&label=Discord&logo=Discord%20Server&logoColor=green' alt='Discord Server'></a>
718
718
  </div>
719
719
 
720
720
  <!-- ![Number of GitHub stars](https://img.shields.io/github/stars/d60/twikit) -->
721
- ![Version](https://img.shields.io/pypi/v/cubecoders-amp-api-wrapper?label=PyPI)
722
721
 
722
+ ![Version](https://img.shields.io/pypi/v/cc-ampapi?label=PyPI)
723
+
724
+ ### Table of Contents
725
+
726
+ ---
727
+
728
+ - [Key Features](#key-features)
729
+ - [Docs](#docs)
730
+ - [Installing](#installing)
731
+ - [PyPi](#pypi)
732
+ - [Basic Usage](#basic-usage)
733
+ - [Quick Example](#quick-example--)
734
+ - [Controlling data formatting](#controlling-data-formatting--)
735
+ - [Contributing to the Project](#contributing-to-the-project)
736
+ - [Issues]
737
+ - [Changelog]
738
+ - [Upgrading from 4.x]
723
739
 
724
740
  ### Key Features
725
- ___
726
741
 
727
- - Pythonic API wrapper using `async` and `await`.
728
- - Data is in dataclasses for easier management and interaction.
729
- - Optional parameter per function or global to disable formatting of data.
730
- - Parent classes `ADSInstance` and `AMPInstance` to group endpoints together and make handling of multiple Instances easier.
731
- - This will also limit Instance specific API endpoints (eg. Minecraft) to that Instance type only.
742
+ ---
743
+
744
+ - Pythonic API wrapper using `async` and `await` via `aiohttp`.
745
+ - Data is automatically deserialized into typed dataclasses for easier management and interaction.
746
+ - Optional parameter per function or global to disable formatting of data.
747
+ - Inheritance-based Instance model (`Controller`, `Instance`, `MinecraftInstance`, etc.) groups endpoints by Instance type, preventing invalid calls at the class level.
748
+ - TOTP/2FA authentication support for secure programmatic login via `pyotp`.
749
+ - Fully typed and verified with Pyright in strict mode, compatible with Python 3.12+.
750
+
751
+ ### Docs
752
+
753
+ - https://ampapi-python.readthedocs.io/en/latest/
732
754
 
733
755
  ### Installing
734
- ___
735
756
 
736
- *Python 3.10 or higher is required*
757
+ ---
758
+
759
+ _Python 3.12 or higher is required_
760
+
761
+ To install run the below command via your preferred terminal or IDE.
737
762
 
738
- To install run the below command to install the required pip packages from [Requirements](./requirements.txt)
763
+ > **5.0.0 breaks backwards compatibility with 4.x.** See [Upgrading from 4.x] for what changed, or pin `cc-ampapi<5` until you're ready~
764
+
765
+ > **cc-ampapi 5.x is for an AMP 2 panel.** For an AMP 3 panel, install the 6.x beta with `pip install --pre "cc-ampapi>=6"`.
766
+
767
+ ### PyPi
768
+
769
+ ---
739
770
 
740
- ### PyPi
741
- ___
742
771
  -> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/)
743
772
 
744
773
  ```bash
@@ -748,96 +777,179 @@ pip install cc-ampapi
748
777
  ```
749
778
 
750
779
  ### Basic Usage
751
- ___
752
- 1. First you need to fill out the APIParams class with the required fields (url, user and password).
780
+
781
+ ---
782
+
783
+ In your IDE Python file. -> `import ampapi`.
784
+
785
+ 1. First you need to fill out the APIParams class with the required fields (`url`, `user` and `password`).
786
+ - A user that signs in through an OIDC provider has no password, so set `auth_mode=AuthMode.oidc` instead. See the `Bridge` docs.
753
787
  2. Pass the APIParams class into the Bridge class parameter api_params.
754
- - You only need to make ONE bridge class; the rest of the API classes will get the same object and handle logging in for you.
755
- 3. You can then use the Parent class `ADSInstance()` or the smaller class `AMPInstance()` or any of the API classes as a stand alone.
756
- - See [Quick Example](./README.md#quick-example--) for a visual example.
788
+ - You only need to make ONE bridge class; the rest of the API classes will get the same object and handle logging in for you.
789
+ - To use your own `aiohttp.ClientSession`, pass it as `Bridge(api_params=..., session=...)`. You close it yourself.
790
+ 3. You can then use the Parent class `Controller()` or the smaller class `Instance()` or any of the API classes as a stand alone.
791
+ - See [Quick Example](https://github.com/k8thekat/AMPAPI_Python/blob/main/docs/samples/sample.py) for a visual example.
792
+ 4. When you are done, close the session with `await controller.clean_up()`, or use `async with Controller() as controller:`.
757
793
 
758
794
  ### Quick Example -
759
795
 
760
796
  ```py
797
+ from typing import Union
798
+
799
+ from ampapi import (
800
+ AnalyticsFilter,
801
+ AnalyticsSummary,
802
+ APIParams,
803
+ Bridge,
804
+ Controller,
805
+ Instance,
806
+ InstanceState,
807
+ MinecraftInstance,
808
+ Players,
809
+ Status,
810
+ )
811
+
761
812
  # You can pull these values from an `.ini` or a `.env` file,
762
- # then populate the NamedTuple APIparams from `types -> APIParams`
813
+ # then populate the dataclass APIParams from `modules -> APIParams`
763
814
  _params = APIParams(url="http://192.168.13.130:8080",
764
815
  user="amp_username",
765
816
  password="amp_password")
766
817
 
767
- _bridge = Bridge(api_params=_params)
768
818
 
769
- async def Sample_API():
819
+
820
+ async def Sample_API() -> None:
770
821
  """
771
- Example Method to call Instance Endpoints and create the ADS Instance class.
822
+ Example API Function to call Endpoints.
772
823
  """
773
-
774
- ADS: ADSInstance = ADSInstance()
775
- # This would populate the ADS class property .AvailableInstances
776
- await ADS.get_instances()
824
+ _bridge = Bridge(api_params=_params)
825
+ ADS: Controller = Controller()
826
+ # By default all API calls will be formatted into Dataclasses if possible.
827
+ # You can toggle format_data off with ANY of the API classes that inherit Base().
828
+ ADS.format_data = False
829
+
830
+ # This would populate the ADS class property .instances
831
+ await ADS.get_instances(format_data=True)
832
+ # We convert the ADS.instances attribute to a list for easier iteration.
833
+ # The data is a set to prevent duplicates.
834
+ ADSinstances = list(ADS.instances)
835
+ arkinstance: Union[Instance, None] = None
836
+ mcinstance: Union[Instance, MinecraftInstance, None] = None
777
837
  # We can break out all our instances into their own attributes.
778
- # Your instances wont line up like these examples; but you can check the InstanceName and Module to figure out the order of your Instances.
779
- arkinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[1]
780
- mcinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[2]
838
+ for instance in ADSinstances:
839
+ # Pre populated from the dataclass and has the API endpoints too!
840
+ # Every converted Instance is already an `Instance`, so there is nothing to check
841
+ if instance.friendly_name == "ArkInstance":
842
+ arkinstance = instance
843
+ elif instance.friendly_name == "Minecraft_PVP":
844
+ mcinstance = instance
845
+
846
+ if arkinstance is None or mcinstance is None or not isinstance(mcinstance, MinecraftInstance):
847
+ return
848
+ # This turns back on data formatting Globally.
849
+ arkinstance.format_data = True
781
850
 
782
- # Pre populated from the dataclass and has the API methods too!
783
851
  # You can take a backup really easily.
784
- await arkinstance.take_backup(title="ARK1_backup", description="This is an ARK backup", sticky=True)
852
+ await arkinstance.take_backup(name="ARK1_backup", description="This is an ARK backup", sticky=True)
785
853
 
786
- # Then you can call instance type specific API methods.
787
- await mcinstance.mc_add_to_whitelist(user_or_uuid="k8_thekat")
854
+ # Then you can call instance type specific API endpoints.
855
+ # AMP 2.6.5.0 removed the whitelist endpoints, so we send the server's own console command instead
856
+ await mcinstance.send_console_message(msg="whitelist add k8_thekat")
788
857
 
789
- # You can also check attributes and other fields of the instance.
790
- mcinstance.InstanceName
791
- mcinstance.InstanceID
858
+ # You can also check attributes and other fields of the instance for easy logic.
859
+ if mcinstance.instance_name == "Test_Server":
860
+ # do code here
861
+ ...
792
862
 
793
- # The State of the Instance. eg. Running, Offline, Restarting. See `types.py -> State_enum
794
- # This is NOT updated constantly. See about using `get_status()` to keep it current.
795
- if mcinstance.AppState == State_enum.Stopped:
863
+ # The State of the Instance.
864
+ # Can be checked via `Instance.running`.
865
+ # This is cached, call `ADS.get_instances()` again to refresh it.
866
+ if mcinstance.running is True:
867
+ print(f"{mcinstance.friendly_name} is Running Nyao~")
868
+
869
+ elif mcinstance.running is False:
870
+ print(f"{mcinstance.friendly_name} is not currently Running.")
796
871
  await mcinstance.start_instance()
797
872
 
798
- # You can also check Metrics of an Instance easily.
799
- mcinstance.Status.Metrics
873
+ # You can also restart and stop the Instance too.
874
+ await mcinstance.restart_instance()
875
+ await mcinstance.stop_instance()
876
+
877
+ # The State of the Application. eg. ready, stopped, restarting, etc. See `_enums.py -> InstanceState`
878
+ # This is NOT updated constantly. See about using `get_status()` to get it current.
879
+ if mcinstance.app_state == InstanceState.stopped:
880
+ await mcinstance.start_application()
881
+
882
+ # You can also stop and update the application via
883
+ await mcinstance.stop_application()
884
+ await mcinstance.update_application()
885
+
886
+ # To get the current Instance State call the function below, it returns a `Status` dataclass.
887
+ # A call gives the raw dict when `format_data` is off, so we ask for the dataclass and check we got it
888
+ status = await mcinstance.get_status(format_data=True)
889
+ if isinstance(status, Status):
890
+ print(status.state)
891
+ # You can also check Metrics of an Instance easily.
892
+ print(status.metrics)
800
893
 
801
894
  # Want to kick a random person? Here ya go~
802
- players: list[Players] = await mcinstance.get_user_list()
803
- await mcinstance.mc_kick_user_by_id(id=players[0].id)
895
+ players = await mcinstance.get_user_list(format_data=True)
896
+ if isinstance(players, Players) and len(players.sorted) > 0:
897
+ await mcinstance.mc_kick_user_by_id(user_id=players.sorted[0].uuid)
898
+
899
+ # When you are done, close the session the Bridge made for us.
900
+ await ADS.clean_up()
901
+
804
902
 
805
903
 
806
904
  async def Sample_Analytics_API():
807
905
  """
808
906
  Example Method to use Instance Analytics.
809
907
  """
810
- ADS: ADSInstance = ADSInstance()
908
+ ADS: Controller = Controller()
811
909
  await ADS.get_instances()
812
- # The index value to get to an MC Instance will be different for you; this is just an example.
813
- # You can check an Instances Type via the `.Module` attribute of any ADS/Instance class.
814
- mcinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[2]
910
+ # The instances are a set, so we pick the first Minecraft one out of it; this is just an example.
911
+ # You can check an Instances Type via the `.module` attribute of any Instance class.
912
+ mcinstance: Union[Instance, MinecraftInstance, None] = None
913
+ for instance in ADS.instances:
914
+ if isinstance(instance, MinecraftInstance):
915
+ mcinstance = instance
916
+ break
917
+ if mcinstance is None:
918
+ return
815
919
  # Example analytics call without a filter.
816
- Analytics: Analytics_Summary = await mcinstance.get_analytics_summary()
817
- # Then with that class you can access lots of Information, such as Top Players, Stats and SessionTime.
818
- Analytics.topPlayers # This is a list of this Instances Top Players.
819
- Analytics.stats # This is a list of different fields such as Unique Users, New Users, etc..
920
+ Analytics = await mcinstance.get_analytics_summary(format_data=True)
921
+ if isinstance(Analytics, AnalyticsSummary):
922
+ # Then with that class you can access lots of Information, such as Top Players, Stats and SessionTime.
923
+ print(Analytics.top_players) # This is a list of this Instances Top Players.
924
+ print(Analytics.stats) # This is a list of different fields such as Unique Users, New Users, etc..
820
925
  # _____________________________________________
821
- # Now you can also filter the results to look at a specific User or Country. Simply define the `Analytics_Filter` class and pass it into the method call.
822
- country_filter: Analytics_Filter = Analytics_Filter(Country="US") # The Country parameter supports `ISO 3166-1 Alpha-2 format` only.
926
+ # Now you can also filter the results to look at a specific User or Country. Simply define the `AnalyticsFilter` class and pass it into the method call.
927
+ country_filter: AnalyticsFilter = AnalyticsFilter(country="US") # The country parameter supports `ISO 3166-1 Alpha-2 format` only.
823
928
  # These results will be filtered to only users within the US.
824
- filtered_analytics: Analytics_Summary = await mcinstance.get_analytics_summary(filters=country_filter)
929
+ filtered_analytics = await mcinstance.get_analytics_summary(filters=country_filter, format_data=True)
930
+ print(filtered_analytics)
825
931
 
826
- user_filter: Analytics_Filter = Analytics_Filter(Username="k8_thekat") # The IGN/Username of the user connected to the Server.
827
- # These results will be filtered to only users with that match the parameter Username. (eg. k8_thekat).
828
- filtered_analytics2: Analytics_Summary = await mcinstance.get_analytics_summary(filters=user_filter)
932
+ user_filter: AnalyticsFilter = AnalyticsFilter(username="k8_thekat") # The IGN/Username of the user connected to the Server.
933
+ # These results will be filtered to only users with that match the parameter username. (eg. k8_thekat).
934
+ filtered_analytics2 = await mcinstance.get_analytics_summary(filters=user_filter, format_data=True)
935
+ print(filtered_analytics2)
829
936
 
830
-
831
- ```
937
+ # When you are done, close the session the Bridge made for us.
938
+ await ADS.clean_up()
832
939
 
833
940
 
941
+ ```
942
+
834
943
  ### Controlling data formatting -
944
+
835
945
  - All JSON data returned from the API endpoints is formatted into a Dataclass/Enum/etc if possible.
836
946
  - Data formatting can be controlled globally or locally by changing the `format_data` parameter of the method to `False`.
837
- - When turning off the data formatting, typically you will get a `dictionary` back.
947
+ - When turning off the data formatting, typically you will get a `dictionary` back.
838
948
 
839
949
  ### Example -
950
+
840
951
  ```py
952
+ # You must have your Bridge object made and the Instance class created to access `format_data`.
841
953
  # By default all API calls will be formatted into Dataclasses if possible.
842
954
  # You can toggle format_data off with ANY of the API classes that inherit Base().
843
955
  ADS.format_data = False
@@ -851,22 +963,13 @@ await arkinstance.get_role_data(format_data=True)
851
963
 
852
964
  ```
853
965
 
966
+ # Contributing to the Project
854
967
 
855
- ### Contributing to the project
856
-
857
- # Git Commit message format
858
-
859
- ```
860
- # file_name.py
861
- - Change 1
862
- - Change 2
863
- -- Change 2 sub-change 1
864
-
865
- $ This commit message will be omitted because of `$`
866
- - Everything below it will be ignored too as long as it has a `-`
867
- ```
868
-
869
- # AMP Version Bump
870
- If the AMP version has changed, please generate new API spec sheets and upload them with any function changes.
871
- - Run `await APIUtil.amp_api_update(instance=instance_here)`
968
+ See [CONTRIBUTING.md] for setup, the checks to run, the commit message format, and the dev tools.
969
+ Those tools cover calling endpoints that have no wrapper yet, capturing responses, checking captures for key drift
970
+ with `KeyDriftCheck`, and regenerating the spec sheets when AMP updates~
872
971
 
972
+ [Issues]: https://github.com/k8thekat/AMPAPI_Python/issues
973
+ [Changelog]: https://github.com/k8thekat/AMPAPI_Python/blob/main/CHANGELOG.md
974
+ [Upgrading from 4.x]: https://ampapi-python.readthedocs.io/en/latest/upgrading.html
975
+ [CONTRIBUTING.md]: https://github.com/k8thekat/AMPAPI_Python/blob/main/CONTRIBUTING.md
@@ -0,0 +1,266 @@
1
+ # AMP API Python
2
+
3
+ ---
4
+
5
+ An asynchronous Python wrapper for the CubeCoders AMP (Application Management Panel) API, enabling developers to programmatically manage game server Instances with a clean, Pythonic interface.
6
+
7
+ <div align="left">
8
+ <a href="https://discord.gg/BtNyU8DFtt"><img src='https://img.shields.io/discord/705500489248145459?color=blue&label=Discord&logo=Discord%20Server&logoColor=green' alt='Discord Server'></a>
9
+ </div>
10
+
11
+ <!-- ![Number of GitHub stars](https://img.shields.io/github/stars/d60/twikit) -->
12
+
13
+ ![Version](https://img.shields.io/pypi/v/cc-ampapi?label=PyPI)
14
+
15
+ ### Table of Contents
16
+
17
+ ---
18
+
19
+ - [Key Features](#key-features)
20
+ - [Docs](#docs)
21
+ - [Installing](#installing)
22
+ - [PyPi](#pypi)
23
+ - [Basic Usage](#basic-usage)
24
+ - [Quick Example](#quick-example--)
25
+ - [Controlling data formatting](#controlling-data-formatting--)
26
+ - [Contributing to the Project](#contributing-to-the-project)
27
+ - [Issues]
28
+ - [Changelog]
29
+ - [Upgrading from 4.x]
30
+
31
+ ### Key Features
32
+
33
+ ---
34
+
35
+ - Pythonic API wrapper using `async` and `await` via `aiohttp`.
36
+ - Data is automatically deserialized into typed dataclasses for easier management and interaction.
37
+ - Optional parameter per function or global to disable formatting of data.
38
+ - Inheritance-based Instance model (`Controller`, `Instance`, `MinecraftInstance`, etc.) groups endpoints by Instance type, preventing invalid calls at the class level.
39
+ - TOTP/2FA authentication support for secure programmatic login via `pyotp`.
40
+ - Fully typed and verified with Pyright in strict mode, compatible with Python 3.12+.
41
+
42
+ ### Docs
43
+
44
+ - https://ampapi-python.readthedocs.io/en/latest/
45
+
46
+ ### Installing
47
+
48
+ ---
49
+
50
+ _Python 3.12 or higher is required_
51
+
52
+ To install run the below command via your preferred terminal or IDE.
53
+
54
+ > **5.0.0 breaks backwards compatibility with 4.x.** See [Upgrading from 4.x] for what changed, or pin `cc-ampapi<5` until you're ready~
55
+
56
+ > **cc-ampapi 5.x is for an AMP 2 panel.** For an AMP 3 panel, install the 6.x beta with `pip install --pre "cc-ampapi>=6"`.
57
+
58
+ ### PyPi
59
+
60
+ ---
61
+
62
+ -> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/)
63
+
64
+ ```bash
65
+ # Linux/macOS/Windows
66
+ pip install cc-ampapi
67
+
68
+ ```
69
+
70
+ ### Basic Usage
71
+
72
+ ---
73
+
74
+ In your IDE Python file. -> `import ampapi`.
75
+
76
+ 1. First you need to fill out the APIParams class with the required fields (`url`, `user` and `password`).
77
+ - A user that signs in through an OIDC provider has no password, so set `auth_mode=AuthMode.oidc` instead. See the `Bridge` docs.
78
+ 2. Pass the APIParams class into the Bridge class parameter api_params.
79
+ - You only need to make ONE bridge class; the rest of the API classes will get the same object and handle logging in for you.
80
+ - To use your own `aiohttp.ClientSession`, pass it as `Bridge(api_params=..., session=...)`. You close it yourself.
81
+ 3. You can then use the Parent class `Controller()` or the smaller class `Instance()` or any of the API classes as a stand alone.
82
+ - See [Quick Example](https://github.com/k8thekat/AMPAPI_Python/blob/main/docs/samples/sample.py) for a visual example.
83
+ 4. When you are done, close the session with `await controller.clean_up()`, or use `async with Controller() as controller:`.
84
+
85
+ ### Quick Example -
86
+
87
+ ```py
88
+ from typing import Union
89
+
90
+ from ampapi import (
91
+ AnalyticsFilter,
92
+ AnalyticsSummary,
93
+ APIParams,
94
+ Bridge,
95
+ Controller,
96
+ Instance,
97
+ InstanceState,
98
+ MinecraftInstance,
99
+ Players,
100
+ Status,
101
+ )
102
+
103
+ # You can pull these values from an `.ini` or a `.env` file,
104
+ # then populate the dataclass APIParams from `modules -> APIParams`
105
+ _params = APIParams(url="http://192.168.13.130:8080",
106
+ user="amp_username",
107
+ password="amp_password")
108
+
109
+
110
+
111
+ async def Sample_API() -> None:
112
+ """
113
+ Example API Function to call Endpoints.
114
+ """
115
+ _bridge = Bridge(api_params=_params)
116
+ ADS: Controller = Controller()
117
+ # By default all API calls will be formatted into Dataclasses if possible.
118
+ # You can toggle format_data off with ANY of the API classes that inherit Base().
119
+ ADS.format_data = False
120
+
121
+ # This would populate the ADS class property .instances
122
+ await ADS.get_instances(format_data=True)
123
+ # We convert the ADS.instances attribute to a list for easier iteration.
124
+ # The data is a set to prevent duplicates.
125
+ ADSinstances = list(ADS.instances)
126
+ arkinstance: Union[Instance, None] = None
127
+ mcinstance: Union[Instance, MinecraftInstance, None] = None
128
+ # We can break out all our instances into their own attributes.
129
+ for instance in ADSinstances:
130
+ # Pre populated from the dataclass and has the API endpoints too!
131
+ # Every converted Instance is already an `Instance`, so there is nothing to check
132
+ if instance.friendly_name == "ArkInstance":
133
+ arkinstance = instance
134
+ elif instance.friendly_name == "Minecraft_PVP":
135
+ mcinstance = instance
136
+
137
+ if arkinstance is None or mcinstance is None or not isinstance(mcinstance, MinecraftInstance):
138
+ return
139
+ # This turns back on data formatting Globally.
140
+ arkinstance.format_data = True
141
+
142
+ # You can take a backup really easily.
143
+ await arkinstance.take_backup(name="ARK1_backup", description="This is an ARK backup", sticky=True)
144
+
145
+ # Then you can call instance type specific API endpoints.
146
+ # AMP 2.6.5.0 removed the whitelist endpoints, so we send the server's own console command instead
147
+ await mcinstance.send_console_message(msg="whitelist add k8_thekat")
148
+
149
+ # You can also check attributes and other fields of the instance for easy logic.
150
+ if mcinstance.instance_name == "Test_Server":
151
+ # do code here
152
+ ...
153
+
154
+ # The State of the Instance.
155
+ # Can be checked via `Instance.running`.
156
+ # This is cached, call `ADS.get_instances()` again to refresh it.
157
+ if mcinstance.running is True:
158
+ print(f"{mcinstance.friendly_name} is Running Nyao~")
159
+
160
+ elif mcinstance.running is False:
161
+ print(f"{mcinstance.friendly_name} is not currently Running.")
162
+ await mcinstance.start_instance()
163
+
164
+ # You can also restart and stop the Instance too.
165
+ await mcinstance.restart_instance()
166
+ await mcinstance.stop_instance()
167
+
168
+ # The State of the Application. eg. ready, stopped, restarting, etc. See `_enums.py -> InstanceState`
169
+ # This is NOT updated constantly. See about using `get_status()` to get it current.
170
+ if mcinstance.app_state == InstanceState.stopped:
171
+ await mcinstance.start_application()
172
+
173
+ # You can also stop and update the application via
174
+ await mcinstance.stop_application()
175
+ await mcinstance.update_application()
176
+
177
+ # To get the current Instance State call the function below, it returns a `Status` dataclass.
178
+ # A call gives the raw dict when `format_data` is off, so we ask for the dataclass and check we got it
179
+ status = await mcinstance.get_status(format_data=True)
180
+ if isinstance(status, Status):
181
+ print(status.state)
182
+ # You can also check Metrics of an Instance easily.
183
+ print(status.metrics)
184
+
185
+ # Want to kick a random person? Here ya go~
186
+ players = await mcinstance.get_user_list(format_data=True)
187
+ if isinstance(players, Players) and len(players.sorted) > 0:
188
+ await mcinstance.mc_kick_user_by_id(user_id=players.sorted[0].uuid)
189
+
190
+ # When you are done, close the session the Bridge made for us.
191
+ await ADS.clean_up()
192
+
193
+
194
+
195
+ async def Sample_Analytics_API():
196
+ """
197
+ Example Method to use Instance Analytics.
198
+ """
199
+ ADS: Controller = Controller()
200
+ await ADS.get_instances()
201
+ # The instances are a set, so we pick the first Minecraft one out of it; this is just an example.
202
+ # You can check an Instances Type via the `.module` attribute of any Instance class.
203
+ mcinstance: Union[Instance, MinecraftInstance, None] = None
204
+ for instance in ADS.instances:
205
+ if isinstance(instance, MinecraftInstance):
206
+ mcinstance = instance
207
+ break
208
+ if mcinstance is None:
209
+ return
210
+ # Example analytics call without a filter.
211
+ Analytics = await mcinstance.get_analytics_summary(format_data=True)
212
+ if isinstance(Analytics, AnalyticsSummary):
213
+ # Then with that class you can access lots of Information, such as Top Players, Stats and SessionTime.
214
+ print(Analytics.top_players) # This is a list of this Instances Top Players.
215
+ print(Analytics.stats) # This is a list of different fields such as Unique Users, New Users, etc..
216
+ # _____________________________________________
217
+ # Now you can also filter the results to look at a specific User or Country. Simply define the `AnalyticsFilter` class and pass it into the method call.
218
+ country_filter: AnalyticsFilter = AnalyticsFilter(country="US") # The country parameter supports `ISO 3166-1 Alpha-2 format` only.
219
+ # These results will be filtered to only users within the US.
220
+ filtered_analytics = await mcinstance.get_analytics_summary(filters=country_filter, format_data=True)
221
+ print(filtered_analytics)
222
+
223
+ user_filter: AnalyticsFilter = AnalyticsFilter(username="k8_thekat") # The IGN/Username of the user connected to the Server.
224
+ # These results will be filtered to only users with that match the parameter username. (eg. k8_thekat).
225
+ filtered_analytics2 = await mcinstance.get_analytics_summary(filters=user_filter, format_data=True)
226
+ print(filtered_analytics2)
227
+
228
+ # When you are done, close the session the Bridge made for us.
229
+ await ADS.clean_up()
230
+
231
+
232
+ ```
233
+
234
+ ### Controlling data formatting -
235
+
236
+ - All JSON data returned from the API endpoints is formatted into a Dataclass/Enum/etc if possible.
237
+ - Data formatting can be controlled globally or locally by changing the `format_data` parameter of the method to `False`.
238
+ - When turning off the data formatting, typically you will get a `dictionary` back.
239
+
240
+ ### Example -
241
+
242
+ ```py
243
+ # You must have your Bridge object made and the Instance class created to access `format_data`.
244
+ # By default all API calls will be formatted into Dataclasses if possible.
245
+ # You can toggle format_data off with ANY of the API classes that inherit Base().
246
+ ADS.format_data = False
247
+
248
+ # You can turn data formatting back on globally through any Instance object.
249
+ arkinstance.format_data = True
250
+
251
+ # You can turn off or on data formatting per function also.
252
+ await arkinstance.get_updates(format_data=False)
253
+ await arkinstance.get_role_data(format_data=True)
254
+
255
+ ```
256
+
257
+ # Contributing to the Project
258
+
259
+ See [CONTRIBUTING.md] for setup, the checks to run, the commit message format, and the dev tools.
260
+ Those tools cover calling endpoints that have no wrapper yet, capturing responses, checking captures for key drift
261
+ with `KeyDriftCheck`, and regenerating the spec sheets when AMP updates~
262
+
263
+ [Issues]: https://github.com/k8thekat/AMPAPI_Python/issues
264
+ [Changelog]: https://github.com/k8thekat/AMPAPI_Python/blob/main/CHANGELOG.md
265
+ [Upgrading from 4.x]: https://ampapi-python.readthedocs.io/en/latest/upgrading.html
266
+ [CONTRIBUTING.md]: https://github.com/k8thekat/AMPAPI_Python/blob/main/CONTRIBUTING.md