cc-ampapi 4.6.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 (50) hide show
  1. {cc_ampapi-4.6.0/cc_ampapi.egg-info → cc_ampapi-5.0.1}/PKG-INFO +117 -76
  2. cc_ampapi-5.0.1/README.md +266 -0
  3. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/ampapi/__init__.py +13 -14
  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-4.6.0 → cc_ampapi-5.0.1/cc_ampapi.egg-info}/PKG-INFO +117 -76
  24. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/SOURCES.txt +7 -4
  25. {cc_ampapi-4.6.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-4.6.0/README.md +0 -224
  28. cc_ampapi-4.6.0/ampapi/adsmodule.py +0 -2060
  29. cc_ampapi-4.6.0/ampapi/analytics.py +0 -70
  30. cc_ampapi-4.6.0/ampapi/backoff.py +0 -101
  31. cc_ampapi-4.6.0/ampapi/base.py +0 -838
  32. cc_ampapi-4.6.0/ampapi/bridge.py +0 -69
  33. cc_ampapi-4.6.0/ampapi/controller.py +0 -292
  34. cc_ampapi-4.6.0/ampapi/core.py +0 -2412
  35. cc_ampapi-4.6.0/ampapi/emailsender.py +0 -35
  36. cc_ampapi-4.6.0/ampapi/enums_.py +0 -188
  37. cc_ampapi-4.6.0/ampapi/filebackup.py +0 -240
  38. cc_ampapi-4.6.0/ampapi/filemanager.py +0 -573
  39. cc_ampapi-4.6.0/ampapi/instance.py +0 -558
  40. cc_ampapi-4.6.0/ampapi/minecraft.py +0 -625
  41. cc_ampapi-4.6.0/ampapi/modules.py +0 -3106
  42. cc_ampapi-4.6.0/ampapi/types_.py +0 -264
  43. cc_ampapi-4.6.0/ampapi/util.py +0 -655
  44. cc_ampapi-4.6.0/pyproject.toml +0 -98
  45. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/LICENSE +0 -0
  46. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/LICENSE-dpy +0 -0
  47. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/MANIFEST.in +0 -0
  48. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/dependency_links.txt +0 -0
  49. {cc_ampapi-4.6.0 → cc_ampapi-5.0.1}/cc_ampapi.egg-info/top_level.txt +0 -0
  50. {cc_ampapi-4.6.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: 4.6.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,35 +684,34 @@ 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
711
 
713
712
  ---
714
713
 
715
- CubeCoders AMP API wrapper in Python.
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.
716
715
 
717
716
  <div align="left">
718
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>
@@ -720,17 +719,34 @@ CubeCoders AMP API wrapper in Python.
720
719
 
721
720
  <!-- ![Number of GitHub stars](https://img.shields.io/github/stars/d60/twikit) -->
722
721
 
723
- ![Version](https://img.shields.io/pypi/v/cubecoders-amp-api-wrapper?label=PyPI)
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]
724
739
 
725
740
  ### Key Features
726
741
 
727
742
  ---
728
743
 
729
- - Pythonic API wrapper using `async` and `await`.
730
- - Data is in dataclasses for easier management and interaction.
744
+ - Pythonic API wrapper using `async` and `await` via `aiohttp`.
745
+ - Data is automatically deserialized into typed dataclasses for easier management and interaction.
731
746
  - Optional parameter per function or global to disable formatting of data.
732
- - Parent classes `ADSInstance` and `AMPInstance` to group endpoints together and make handling of multiple Instances easier.
733
- - This will also limit Instance specific API endpoints (eg. Minecraft) to that Instance type only.
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+.
734
750
 
735
751
  ### Docs
736
752
 
@@ -740,9 +756,13 @@ CubeCoders AMP API wrapper in Python.
740
756
 
741
757
  ---
742
758
 
743
- _Python 3.10 or higher is required_
759
+ _Python 3.12 or higher is required_
744
760
 
745
- To install run the below command to install the required pip packages from [Requirements](./requirements.txt)
761
+ To install run the below command via your preferred terminal or IDE.
762
+
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"`.
746
766
 
747
767
  ### PyPi
748
768
 
@@ -762,22 +782,35 @@ pip install cc-ampapi
762
782
 
763
783
  In your IDE Python file. -> `import ampapi`.
764
784
 
765
- 1. First you need to fill out the APIParams class with the required fields (url, user and password).
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.
766
787
  2. Pass the APIParams class into the Bridge class parameter api_params.
767
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.
768
- 3. You can then use the Parent class `ADSInstance()` or the smaller class `AMPInstance()` or any of the API classes as a stand alone.
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.
769
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:`.
770
793
 
771
794
  ### Quick Example -
772
795
 
773
796
  ```py
774
- from ampapi import *
775
- from ampapi.dataclass import AnalyticsFilter, AnalyticsSummary, APIParams, Players
776
- from ampapi.enums import *
777
- from ampapi.instance import AMPControllerInstance, AMPInstance, AMPMinecraftInstance
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
+ )
778
811
 
779
812
  # You can pull these values from an `.ini` or a `.env` file,
780
- # then populate the NamedTuple APIparams from `types -> APIParams`
813
+ # then populate the dataclass APIParams from `modules -> APIParams`
781
814
  _params = APIParams(url="http://192.168.13.130:8080",
782
815
  user="amp_username",
783
816
  password="amp_password")
@@ -789,28 +822,28 @@ async def Sample_API() -> None:
789
822
  Example API Function to call Endpoints.
790
823
  """
791
824
  _bridge = Bridge(api_params=_params)
792
- ADS: AMPControllerInstance = AMPControllerInstance()
825
+ ADS: Controller = Controller()
793
826
  # By default all API calls will be formatted into Dataclasses if possible.
794
827
  # You can toggle format_data off with ANY of the API classes that inherit Base().
795
828
  ADS.format_data = False
796
829
 
797
- # This would populate the ADS class property .instances and .available_instances
830
+ # This would populate the ADS class property .instances
798
831
  await ADS.get_instances(format_data=True)
799
832
  # We convert the ADS.instances attribute to a list for easier iteration.
800
833
  # The data is a set to prevent duplicates.
801
834
  ADSinstances = list(ADS.instances)
802
- arkinstance: Union[AMPInstance, None] = None
803
- mcinstance: Union[AMPInstance, AMPMinecraftInstance, None] = None
835
+ arkinstance: Union[Instance, None] = None
836
+ mcinstance: Union[Instance, MinecraftInstance, None] = None
804
837
  # We can break out all our instances into their own attributes.
805
838
  for instance in ADSinstances:
806
839
  # Pre populated from the dataclass and has the API endpoints too!
807
- if isinstance(instance, (AMPADSInstance, AMPInstance, AMPMinecraftInstance)):
808
- if instance.friendly_name == "ArkInstance":
809
- arkinstance = instance
810
- elif instance.friendly_name == "Minecraft_PVP":
811
- mcinstance = instance
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
812
845
 
813
- if arkinstance is None or mcinstance is None or not isinstance(mcinstance, AMPMinecraftInstance):
846
+ if arkinstance is None or mcinstance is None or not isinstance(mcinstance, MinecraftInstance):
814
847
  return
815
848
  # This turns back on data formatting Globally.
816
849
  arkinstance.format_data = True
@@ -819,7 +852,8 @@ async def Sample_API() -> None:
819
852
  await arkinstance.take_backup(name="ARK1_backup", description="This is an ARK backup", sticky=True)
820
853
 
821
854
  # Then you can call instance type specific API endpoints.
822
- await mcinstance.mc_add_to_whitelist(user_or_uuid="k8_thekat")
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")
823
857
 
824
858
  # You can also check attributes and other fields of the instance for easy logic.
825
859
  if mcinstance.instance_name == "Test_Server":
@@ -827,8 +861,8 @@ async def Sample_API() -> None:
827
861
  ...
828
862
 
829
863
  # The State of the Instance.
830
- # Can be checked via `AMPInstance.Running`.
831
- # To keep this updated simply check.
864
+ # Can be checked via `Instance.running`.
865
+ # This is cached, call `ADS.get_instances()` again to refresh it.
832
866
  if mcinstance.running is True:
833
867
  print(f"{mcinstance.friendly_name} is Running Nyao~")
834
868
 
@@ -840,26 +874,30 @@ async def Sample_API() -> None:
840
874
  await mcinstance.restart_instance()
841
875
  await mcinstance.stop_instance()
842
876
 
843
- # The State of the Application. eg. Running, Offline, Restarting, etc. See `types.py -> State_enum
844
- # This is NOT updated constantly. See about using `get_status()` to keep it current.
845
- if mcinstance.app_state == AMPInstanceState.stopped:
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:
846
880
  await mcinstance.start_application()
847
881
 
848
882
  # You can also stop and update the application via
849
883
  await mcinstance.stop_application()
850
884
  await mcinstance.update_application()
851
885
 
852
- # To get more current Instance State check out.
853
- mcinstance.status.state
854
- mcinstance.app_state
855
- # To keep the `AMPInstance.State` property current; simply call the function below.
856
- await mcinstance.get_status()
857
- # You can also check Metrics of an Instance easily.
858
- mcinstance.status.metrics
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)
859
893
 
860
894
  # Want to kick a random person? Here ya go~
861
- players: Players = await mcinstance.get_user_list()
862
- await mcinstance.mc_kick_user_by_id(user_id=players.sorted[0].uuid)
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()
863
901
 
864
902
 
865
903
 
@@ -867,25 +905,37 @@ async def Sample_Analytics_API():
867
905
  """
868
906
  Example Method to use Instance Analytics.
869
907
  """
870
- ADS: AMPControllerInstance = AMPControllerInstance()
908
+ ADS: Controller = Controller()
871
909
  await ADS.get_instances()
872
- # The index value to get to an MC Instance will be different for you; this is just an example.
873
- # You can check an Instances Type via the `.Module` attribute of any ADS/Instance class.
874
- 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
875
919
  # Example analytics call without a filter.
876
- Analytics: Analytics_Summary = await mcinstance.get_analytics_summary()
877
- # Then with that class you can access lots of Information, such as Top Players, Stats and SessionTime.
878
- Analytics.topPlayers # This is a list of this Instances Top Players.
879
- 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..
880
925
  # _____________________________________________
881
- # 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.
882
- 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.
883
928
  # These results will be filtered to only users within the US.
884
- 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)
885
931
 
886
- user_filter: Analytics_Filter = Analytics_Filter(Username="k8_thekat") # The IGN/Username of the user connected to the Server.
887
- # These results will be filtered to only users with that match the parameter Username. (eg. k8_thekat).
888
- 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)
936
+
937
+ # When you are done, close the session the Bridge made for us.
938
+ await ADS.clean_up()
889
939
 
890
940
 
891
941
  ```
@@ -915,20 +965,11 @@ await arkinstance.get_role_data(format_data=True)
915
965
 
916
966
  # Contributing to the Project
917
967
 
918
- #### Git Commit message format
919
-
920
- ```
921
- # file_name.py
922
- - Change 1
923
- - Change 2
924
- -- Change 2 sub-change 1
925
-
926
- $ This commit message will be omitted because of `$`
927
- - Everything below it will be ignored too as long as it has a `-`
928
- ```
929
-
930
- #### AMP Version Bump
931
-
932
- If the AMP version has changed, please generate new API spec sheets and upload them with any function changes.
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~
933
971
 
934
- - Run `await APIUtil.amp_api_update(instance=instance_here)`
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
@@ -1,51 +1,50 @@
1
- # ruff: noqa
2
- """
3
- Copyright (C) 2021-2022 Katelynn Cadwallader.
1
+ # ruff: noqa: I001, N815, F821, UP037 # star imports keep their load order and version_info is deleted after use
2
+ """Copyright (C) 2021-2026 Katelynn Cadwallader.
4
3
 
5
- This file is part of Gatekeeper, the AMP API.
4
+ This file is part of AMPAPI_Python.
6
5
 
7
- AMP API is free software; you can redistribute it and/or modify
6
+ AMPAPI_Python is free software; you can redistribute it and/or modify
8
7
  it under the terms of the GNU General Public License as published by
9
8
  the Free Software Foundation; either version 3, or (at your option)
10
9
  any later version.
11
10
 
12
- AMP API is distributed in the hope that it will be useful, but WITHOUT
11
+ AMPAPI_Python is distributed in the hope that it will be useful, but WITHOUT
13
12
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
13
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15
14
  License for more details.
16
15
 
17
16
  You should have received a copy of the GNU General Public License
18
- along with AMP API; see the file COPYING. If not, write to the Free
17
+ along with AMPAPI_Python; see the file COPYING. If not, write to the Free
19
18
  Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20
19
  02110-1301, USA.
21
20
  """
22
21
 
23
22
  from __future__ import annotations
24
23
 
25
- __title__ = "CubeCoders AMP API"
24
+ __title__ = "AMPAPI Python"
26
25
  __author__ = "k8thekat"
27
26
  __license__ = "GNU"
28
- __version__ = "4.6.0"
27
+ __version__ = "5.0.1"
29
28
  __credits__ = "AMP by CubeCoders and associates."
30
29
 
31
30
  from typing import Literal, NamedTuple
32
31
 
33
32
 
34
- from .util import *
35
33
  from .adsmodule import *
36
34
  from .analytics import *
37
35
  from .base import *
38
36
  from .bridge import *
39
- from .controller import *
40
37
  from .core import *
38
+ from .errors import *
41
39
  from .emailsender import *
42
40
  from .filebackup import *
43
41
  from .filemanager import *
42
+ from .generic import *
44
43
  from .instance import *
45
44
  from .minecraft import *
46
45
  from .modules import *
47
- from .enums_ import *
48
- from .backoff import *
46
+ from .steamcmd import *
47
+ from ._enums import *
49
48
 
50
49
 
51
50
  class VersionInfo(NamedTuple):
@@ -55,6 +54,6 @@ class VersionInfo(NamedTuple):
55
54
  releaseLevel: Literal["alpha", "beta", "pre-release", "release", "development"]
56
55
 
57
56
 
58
- version_info: VersionInfo = VersionInfo(Major=4, Minor=6, Revision=0, releaseLevel="development")
57
+ version_info: VersionInfo = VersionInfo(Major=5, Minor=0, Revision=1, releaseLevel="release")
59
58
 
60
59
  del NamedTuple, Literal, VersionInfo