cc-ampapi 1.0.7__tar.gz → 1.1.0__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.
- {cc_ampapi-1.0.7/cc_ampapi.egg-info → cc_ampapi-1.1.0}/PKG-INFO +165 -2
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/README.md +6 -5
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/__init__.py +2 -2
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/core.py +6 -6
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/dataclass.py +52 -7
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0/cc_ampapi.egg-info}/PKG-INFO +165 -2
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/pyproject.toml +2 -2
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/LICENSE +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/LICENSE-dpy +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/MANIFEST.in +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/adsmodule.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/analytics.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/base.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/bridge.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/controller.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/emailsender.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/enums.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/filebackup.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/filemanager.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/instance.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/minecraft.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/modules.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/types_.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/ampapi/util.py +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/cc_ampapi.egg-info/SOURCES.txt +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/cc_ampapi.egg-info/dependency_links.txt +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/cc_ampapi.egg-info/top_level.txt +0 -0
- {cc_ampapi-1.0.7 → cc_ampapi-1.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: cc-ampapi
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
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
|
|
@@ -703,3 +703,166 @@ Requires-Python: >=3.10.0
|
|
|
703
703
|
Description-Content-Type: text/markdown
|
|
704
704
|
License-File: LICENSE
|
|
705
705
|
License-File: LICENSE-dpy
|
|
706
|
+
|
|
707
|
+
# AMP API Python
|
|
708
|
+
___
|
|
709
|
+
CubeCoders AMP API wrapper in Python.
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
<div align="left">
|
|
713
|
+
<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>
|
|
714
|
+
</div>
|
|
715
|
+
|
|
716
|
+
<!--  -->
|
|
717
|
+

|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
### Key Features
|
|
721
|
+
___
|
|
722
|
+
|
|
723
|
+
- Pythonic API wrapper using `async` and `await`.
|
|
724
|
+
- Data is in dataclasses for easier management and interaction.
|
|
725
|
+
- Optional parameter per function or global to disable formatting of data.
|
|
726
|
+
- Parent classes `ADSInstance` and `AMPInstance` to group endpoints together and make handling of multiple Instances easier.
|
|
727
|
+
- This will also limit Instance specific API endpoints (eg. Minecraft) to that Instance type only.
|
|
728
|
+
|
|
729
|
+
### Installing
|
|
730
|
+
___
|
|
731
|
+
|
|
732
|
+
*Python 3.10 or higher is required*
|
|
733
|
+
|
|
734
|
+
To install run the below command to install the required pip packages from [Requirements](./requirements.txt)
|
|
735
|
+
|
|
736
|
+
### PyPi
|
|
737
|
+
___
|
|
738
|
+
-> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/)
|
|
739
|
+
|
|
740
|
+
```bash
|
|
741
|
+
# Linux/macOS/Windows
|
|
742
|
+
pip install cc-ampapi
|
|
743
|
+
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
### Basic Usage
|
|
747
|
+
___
|
|
748
|
+
1. First you need to fill out the APIParams class with the required fields (url, user and password).
|
|
749
|
+
2. Pass the APIParams class into the Bridge class parameter api_params.
|
|
750
|
+
- 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.
|
|
751
|
+
3. You can then use the Parent class `ADSInstance()` or the smaller class `AMPInstance()` or any of the API classes as a stand alone.
|
|
752
|
+
- See [Quick Example](./README.md#quick-example--) for a visual example.
|
|
753
|
+
|
|
754
|
+
### Quick Example -
|
|
755
|
+
|
|
756
|
+
```py
|
|
757
|
+
# You can pull these values from an `.ini` or a `.env` file,
|
|
758
|
+
# then populate the NamedTuple APIparams from `types -> APIParams`
|
|
759
|
+
_params = APIParams(url="http://192.168.13.130:8080",
|
|
760
|
+
user="amp_username",
|
|
761
|
+
password="amp_password")
|
|
762
|
+
|
|
763
|
+
_bridge = Bridge(api_params=_params)
|
|
764
|
+
|
|
765
|
+
async def Sample_API():
|
|
766
|
+
"""
|
|
767
|
+
Example Method to call Instance Endpoints and create the ADS Instance class.
|
|
768
|
+
"""
|
|
769
|
+
|
|
770
|
+
ADS: ADSInstance = ADSInstance()
|
|
771
|
+
# This would populate the ADS class property .AvailableInstances
|
|
772
|
+
await ADS.get_instances()
|
|
773
|
+
# We can break out all our instances into their own attributes.
|
|
774
|
+
# Your instances wont line up like these examples; but you can check the InstanceName and Module to figure out the order of your Instances.
|
|
775
|
+
arkinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[1]
|
|
776
|
+
mcinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[2]
|
|
777
|
+
|
|
778
|
+
# Pre populated from the dataclass and has the API methods too!
|
|
779
|
+
# You can take a backup really easily.
|
|
780
|
+
await arkinstance.take_backup(title="ARK1_backup", description="This is an ARK backup", sticky=True)
|
|
781
|
+
|
|
782
|
+
# Then you can call instance type specific API methods.
|
|
783
|
+
await mcinstance.mc_add_to_whitelist(user_or_uuid="k8_thekat")
|
|
784
|
+
|
|
785
|
+
# You can also check attributes and other fields of the instance.
|
|
786
|
+
mcinstance.InstanceName
|
|
787
|
+
mcinstance.InstanceID
|
|
788
|
+
|
|
789
|
+
# The State of the Instance. eg. Running, Offline, Restarting. See `types.py -> State_enum
|
|
790
|
+
# This is NOT updated constantly. See about using `get_status()` to keep it current.
|
|
791
|
+
if mcinstance.AppState == State_enum.Stopped:
|
|
792
|
+
await mcinstance.start_instance()
|
|
793
|
+
|
|
794
|
+
# You can also check Metrics of an Instance easily.
|
|
795
|
+
mcinstance.Status.Metrics
|
|
796
|
+
|
|
797
|
+
# Want to kick a random person? Here ya go~
|
|
798
|
+
players: list[Players] = await mcinstance.get_user_list()
|
|
799
|
+
await mcinstance.mc_kick_user_by_id(id=players[0].id)
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
async def Sample_Analytics_API():
|
|
803
|
+
"""
|
|
804
|
+
Example Method to use Instance Analytics.
|
|
805
|
+
"""
|
|
806
|
+
ADS: ADSInstance = ADSInstance()
|
|
807
|
+
await ADS.get_instances()
|
|
808
|
+
# The index value to get to an MC Instance will be different for you; this is just an example.
|
|
809
|
+
# You can check an Instances Type via the `.Module` attribute of any ADS/Instance class.
|
|
810
|
+
mcinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[2]
|
|
811
|
+
# Example analytics call without a filter.
|
|
812
|
+
Analytics: Analytics_Summary = await mcinstance.get_analytics_summary()
|
|
813
|
+
# Then with that class you can access lots of Information, such as Top Players, Stats and SessionTime.
|
|
814
|
+
Analytics.topPlayers # This is a list of this Instances Top Players.
|
|
815
|
+
Analytics.stats # This is a list of different fields such as Unique Users, New Users, etc..
|
|
816
|
+
# _____________________________________________
|
|
817
|
+
# 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.
|
|
818
|
+
country_filter: Analytics_Filter = Analytics_Filter(Country="US") # The Country parameter supports `ISO 3166-1 Alpha-2 format` only.
|
|
819
|
+
# These results will be filtered to only users within the US.
|
|
820
|
+
filtered_analytics: Analytics_Summary = await mcinstance.get_analytics_summary(filters=country_filter)
|
|
821
|
+
|
|
822
|
+
user_filter: Analytics_Filter = Analytics_Filter(Username="k8_thekat") # The IGN/Username of the user connected to the Server.
|
|
823
|
+
# These results will be filtered to only users with that match the parameter Username. (eg. k8_thekat).
|
|
824
|
+
filtered_analytics2: Analytics_Summary = await mcinstance.get_analytics_summary(filters=user_filter)
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
### Controlling data formatting -
|
|
831
|
+
- All JSON data returned from the API endpoints is formatted into a Dataclass/Enum/etc if possible.
|
|
832
|
+
- Data formatting can be controlled globally or locally by changing the `format_data` parameter of the method to `False`.
|
|
833
|
+
- When turning off the data formatting, typically you will get a `dictionary` back.
|
|
834
|
+
|
|
835
|
+
### Example -
|
|
836
|
+
```py
|
|
837
|
+
# By default all API calls will be formatted into Dataclasses if possible.
|
|
838
|
+
# You can toggle format_data off with ANY of the API classes that inherit Base().
|
|
839
|
+
ADS.format_data = False
|
|
840
|
+
|
|
841
|
+
# You can turn data formatting back on globally through any Instance object.
|
|
842
|
+
arkinstance.format_data = True
|
|
843
|
+
|
|
844
|
+
# You can turn off or on data formatting per function also.
|
|
845
|
+
await arkinstance.get_updates(format_data=False)
|
|
846
|
+
await arkinstance.get_role_data(format_data=True)
|
|
847
|
+
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
### Contributing to the project
|
|
852
|
+
|
|
853
|
+
# Git Commit message format
|
|
854
|
+
|
|
855
|
+
```
|
|
856
|
+
# file_name.py
|
|
857
|
+
- Change 1
|
|
858
|
+
- Change 2
|
|
859
|
+
-- Change 2 sub-change 1
|
|
860
|
+
|
|
861
|
+
$ This commit message will be omitted because of `$`
|
|
862
|
+
- Everything below it will be ignored too as long as it has a `-`
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
# AMP Version Bump
|
|
866
|
+
If the AMP version has changed, please generate new API spec sheets and upload them with any function changes.
|
|
867
|
+
- Run `await APIUtil.amp_api_update(instance=instance_here)`
|
|
868
|
+
|
|
@@ -28,14 +28,15 @@ ___
|
|
|
28
28
|
To install run the below command to install the required pip packages from [Requirements](./requirements.txt)
|
|
29
29
|
|
|
30
30
|
### PyPi
|
|
31
|
-
|
|
31
|
+
___
|
|
32
|
+
-> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/)
|
|
33
|
+
|
|
32
34
|
```bash
|
|
33
|
-
# Linux/macOS
|
|
34
|
-
pip install
|
|
35
|
+
# Linux/macOS/Windows
|
|
36
|
+
pip install cc-ampapi
|
|
35
37
|
|
|
36
|
-
# Windows
|
|
37
|
-
pip install cubecoders-amp-api-wrapper
|
|
38
38
|
```
|
|
39
|
+
|
|
39
40
|
### Basic Usage
|
|
40
41
|
___
|
|
41
42
|
1. First you need to fill out the APIParams class with the required fields (url, user and password).
|
|
@@ -25,7 +25,7 @@ from __future__ import annotations
|
|
|
25
25
|
__title__ = "CubeCoders AMP API"
|
|
26
26
|
__author__ = "k8thekat"
|
|
27
27
|
__license__ = "GNU"
|
|
28
|
-
__version__ = "1.0
|
|
28
|
+
__version__ = "1.1.0"
|
|
29
29
|
__credits__ = "AMP by CubeCoders and associates."
|
|
30
30
|
|
|
31
31
|
from typing import Literal, NamedTuple
|
|
@@ -55,6 +55,6 @@ class VersionInfo(NamedTuple):
|
|
|
55
55
|
releaseLevel: Literal["alpha", "beta", "pre-release", "release", "development"]
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
version_info: VersionInfo = VersionInfo(Major=1, Minor=
|
|
58
|
+
version_info: VersionInfo = VersionInfo(Major=1, Minor=1, Revision=0, releaseLevel="release")
|
|
59
59
|
|
|
60
60
|
del NamedTuple, Literal, VersionInfo
|
|
@@ -1456,8 +1456,8 @@ class Core(Base):
|
|
|
1456
1456
|
|
|
1457
1457
|
Returns
|
|
1458
1458
|
--------
|
|
1459
|
-
:class:`
|
|
1460
|
-
On success returns a :class:`
|
|
1459
|
+
:class:`UserApplicationData`
|
|
1460
|
+
On success returns a :class:`UserApplicationData` class.
|
|
1461
1461
|
"""
|
|
1462
1462
|
|
|
1463
1463
|
await self._connect()
|
|
@@ -1467,8 +1467,8 @@ class Core(Base):
|
|
|
1467
1467
|
)
|
|
1468
1468
|
return result
|
|
1469
1469
|
|
|
1470
|
-
async def get_user_list(self, format_data: Union[bool, None] = None) ->
|
|
1471
|
-
"""|coro|
|
|
1470
|
+
async def get_user_list(self, format_data: Union[bool, None] = None) -> Players:
|
|
1471
|
+
"""|coro|Players
|
|
1472
1472
|
|
|
1473
1473
|
Returns the list of the connected users to the Application.
|
|
1474
1474
|
|
|
@@ -1479,8 +1479,8 @@ class Core(Base):
|
|
|
1479
1479
|
|
|
1480
1480
|
Returns
|
|
1481
1481
|
--------
|
|
1482
|
-
|
|
1483
|
-
On success returns a
|
|
1482
|
+
:class:`Players`
|
|
1483
|
+
On success returns a :class:`Players` dataclasses.
|
|
1484
1484
|
"""
|
|
1485
1485
|
|
|
1486
1486
|
await self._connect()
|
|
@@ -5,8 +5,9 @@ import logging
|
|
|
5
5
|
from dataclasses import dataclass, field, fields
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
from logging import Logger
|
|
8
|
+
from operator import attrgetter
|
|
8
9
|
from pprint import pformat
|
|
9
|
-
from typing import TYPE_CHECKING, Any, ClassVar, Union
|
|
10
|
+
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, Union
|
|
10
11
|
|
|
11
12
|
from dataclass_wizard.errors import MissingFields
|
|
12
13
|
from typing_extensions import Self
|
|
@@ -1794,10 +1795,9 @@ class PlatformInfo:
|
|
|
1794
1795
|
installed_glibc_version: str = field(default="") # "AMPVersionInfo"
|
|
1795
1796
|
|
|
1796
1797
|
|
|
1797
|
-
|
|
1798
|
-
class Players:
|
|
1798
|
+
class Player(NamedTuple):
|
|
1799
1799
|
"""
|
|
1800
|
-
Represents
|
|
1800
|
+
Represents a single player connected to a server.
|
|
1801
1801
|
|
|
1802
1802
|
Attributes
|
|
1803
1803
|
-----------
|
|
@@ -1805,16 +1805,61 @@ class Players:
|
|
|
1805
1805
|
The UUID of the player.
|
|
1806
1806
|
name: :class:`str`
|
|
1807
1807
|
The name of the player.
|
|
1808
|
-
|
|
1809
1808
|
"""
|
|
1810
1809
|
|
|
1811
1810
|
uuid: str = ""
|
|
1812
1811
|
name: str = ""
|
|
1813
1812
|
|
|
1813
|
+
def __eq__(self, other: object) -> bool:
|
|
1814
|
+
return isinstance(other, self.__class__) and self.name == other.name
|
|
1815
|
+
|
|
1816
|
+
def __lt__(self, other: object) -> bool:
|
|
1817
|
+
return isinstance(other, self.__class__) and self.name < other.name
|
|
1818
|
+
|
|
1819
|
+
|
|
1820
|
+
@dataclass(init=False)
|
|
1821
|
+
class Players:
|
|
1822
|
+
"""
|
|
1823
|
+
Represents the JSON response data from :meth:`~Core.get_user_list`.
|
|
1824
|
+
|
|
1825
|
+
|
|
1826
|
+
.. note::
|
|
1827
|
+
The print out of this dataclass can be long depending on the number of players connected due to separation by newline.
|
|
1828
|
+
|
|
1829
|
+
|
|
1830
|
+
Attributes
|
|
1831
|
+
-----------
|
|
1832
|
+
sorted: list[:class:`Player`]
|
|
1833
|
+
A sorted list of :class:`Player` objects by name.
|
|
1834
|
+
|
|
1835
|
+
"""
|
|
1836
|
+
|
|
1837
|
+
# {'781a2971-c14b-42c2-8742-d1e2b029d00a': 'k8_thekat', '50686fad-4027-4bdb-a4a5-2533f8a1e51f': 'WolfDevilAngel'}
|
|
1838
|
+
sorted: list[Player]
|
|
1839
|
+
|
|
1814
1840
|
def __init__(self, data: dict[str, str]) -> None:
|
|
1815
1841
|
for uuid, name in data.items():
|
|
1816
|
-
|
|
1817
|
-
|
|
1842
|
+
self.sorted.append(Player(uuid=uuid, name=name))
|
|
1843
|
+
self.sorted.sort(key=attrgetter("name"))
|
|
1844
|
+
|
|
1845
|
+
def __repr__(self) -> str:
|
|
1846
|
+
return "\n".join([p.name for p in self.sorted])
|
|
1847
|
+
|
|
1848
|
+
def get_player(self, name_or_uuid: str) -> list[Player]:
|
|
1849
|
+
"""
|
|
1850
|
+
Search for a player by their name or UUID.
|
|
1851
|
+
|
|
1852
|
+
Parameters
|
|
1853
|
+
-----------
|
|
1854
|
+
name_or_uuid: :class:`str`
|
|
1855
|
+
The players name or UUID.
|
|
1856
|
+
|
|
1857
|
+
Returns
|
|
1858
|
+
--------
|
|
1859
|
+
:class:`list[Player]`
|
|
1860
|
+
A list of :class:`Player` objects matching the search string.
|
|
1861
|
+
"""
|
|
1862
|
+
return [p for p in self.sorted if name_or_uuid in (p.name, p.uuid)]
|
|
1818
1863
|
|
|
1819
1864
|
|
|
1820
1865
|
@dataclass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: cc-ampapi
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
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
|
|
@@ -703,3 +703,166 @@ Requires-Python: >=3.10.0
|
|
|
703
703
|
Description-Content-Type: text/markdown
|
|
704
704
|
License-File: LICENSE
|
|
705
705
|
License-File: LICENSE-dpy
|
|
706
|
+
|
|
707
|
+
# AMP API Python
|
|
708
|
+
___
|
|
709
|
+
CubeCoders AMP API wrapper in Python.
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
<div align="left">
|
|
713
|
+
<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>
|
|
714
|
+
</div>
|
|
715
|
+
|
|
716
|
+
<!--  -->
|
|
717
|
+

|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
### Key Features
|
|
721
|
+
___
|
|
722
|
+
|
|
723
|
+
- Pythonic API wrapper using `async` and `await`.
|
|
724
|
+
- Data is in dataclasses for easier management and interaction.
|
|
725
|
+
- Optional parameter per function or global to disable formatting of data.
|
|
726
|
+
- Parent classes `ADSInstance` and `AMPInstance` to group endpoints together and make handling of multiple Instances easier.
|
|
727
|
+
- This will also limit Instance specific API endpoints (eg. Minecraft) to that Instance type only.
|
|
728
|
+
|
|
729
|
+
### Installing
|
|
730
|
+
___
|
|
731
|
+
|
|
732
|
+
*Python 3.10 or higher is required*
|
|
733
|
+
|
|
734
|
+
To install run the below command to install the required pip packages from [Requirements](./requirements.txt)
|
|
735
|
+
|
|
736
|
+
### PyPi
|
|
737
|
+
___
|
|
738
|
+
-> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/)
|
|
739
|
+
|
|
740
|
+
```bash
|
|
741
|
+
# Linux/macOS/Windows
|
|
742
|
+
pip install cc-ampapi
|
|
743
|
+
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
### Basic Usage
|
|
747
|
+
___
|
|
748
|
+
1. First you need to fill out the APIParams class with the required fields (url, user and password).
|
|
749
|
+
2. Pass the APIParams class into the Bridge class parameter api_params.
|
|
750
|
+
- 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.
|
|
751
|
+
3. You can then use the Parent class `ADSInstance()` or the smaller class `AMPInstance()` or any of the API classes as a stand alone.
|
|
752
|
+
- See [Quick Example](./README.md#quick-example--) for a visual example.
|
|
753
|
+
|
|
754
|
+
### Quick Example -
|
|
755
|
+
|
|
756
|
+
```py
|
|
757
|
+
# You can pull these values from an `.ini` or a `.env` file,
|
|
758
|
+
# then populate the NamedTuple APIparams from `types -> APIParams`
|
|
759
|
+
_params = APIParams(url="http://192.168.13.130:8080",
|
|
760
|
+
user="amp_username",
|
|
761
|
+
password="amp_password")
|
|
762
|
+
|
|
763
|
+
_bridge = Bridge(api_params=_params)
|
|
764
|
+
|
|
765
|
+
async def Sample_API():
|
|
766
|
+
"""
|
|
767
|
+
Example Method to call Instance Endpoints and create the ADS Instance class.
|
|
768
|
+
"""
|
|
769
|
+
|
|
770
|
+
ADS: ADSInstance = ADSInstance()
|
|
771
|
+
# This would populate the ADS class property .AvailableInstances
|
|
772
|
+
await ADS.get_instances()
|
|
773
|
+
# We can break out all our instances into their own attributes.
|
|
774
|
+
# Your instances wont line up like these examples; but you can check the InstanceName and Module to figure out the order of your Instances.
|
|
775
|
+
arkinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[1]
|
|
776
|
+
mcinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[2]
|
|
777
|
+
|
|
778
|
+
# Pre populated from the dataclass and has the API methods too!
|
|
779
|
+
# You can take a backup really easily.
|
|
780
|
+
await arkinstance.take_backup(title="ARK1_backup", description="This is an ARK backup", sticky=True)
|
|
781
|
+
|
|
782
|
+
# Then you can call instance type specific API methods.
|
|
783
|
+
await mcinstance.mc_add_to_whitelist(user_or_uuid="k8_thekat")
|
|
784
|
+
|
|
785
|
+
# You can also check attributes and other fields of the instance.
|
|
786
|
+
mcinstance.InstanceName
|
|
787
|
+
mcinstance.InstanceID
|
|
788
|
+
|
|
789
|
+
# The State of the Instance. eg. Running, Offline, Restarting. See `types.py -> State_enum
|
|
790
|
+
# This is NOT updated constantly. See about using `get_status()` to keep it current.
|
|
791
|
+
if mcinstance.AppState == State_enum.Stopped:
|
|
792
|
+
await mcinstance.start_instance()
|
|
793
|
+
|
|
794
|
+
# You can also check Metrics of an Instance easily.
|
|
795
|
+
mcinstance.Status.Metrics
|
|
796
|
+
|
|
797
|
+
# Want to kick a random person? Here ya go~
|
|
798
|
+
players: list[Players] = await mcinstance.get_user_list()
|
|
799
|
+
await mcinstance.mc_kick_user_by_id(id=players[0].id)
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
async def Sample_Analytics_API():
|
|
803
|
+
"""
|
|
804
|
+
Example Method to use Instance Analytics.
|
|
805
|
+
"""
|
|
806
|
+
ADS: ADSInstance = ADSInstance()
|
|
807
|
+
await ADS.get_instances()
|
|
808
|
+
# The index value to get to an MC Instance will be different for you; this is just an example.
|
|
809
|
+
# You can check an Instances Type via the `.Module` attribute of any ADS/Instance class.
|
|
810
|
+
mcinstance: AMPInstance | AMPMinecraftInstance = ADS.AvailableInstances[2]
|
|
811
|
+
# Example analytics call without a filter.
|
|
812
|
+
Analytics: Analytics_Summary = await mcinstance.get_analytics_summary()
|
|
813
|
+
# Then with that class you can access lots of Information, such as Top Players, Stats and SessionTime.
|
|
814
|
+
Analytics.topPlayers # This is a list of this Instances Top Players.
|
|
815
|
+
Analytics.stats # This is a list of different fields such as Unique Users, New Users, etc..
|
|
816
|
+
# _____________________________________________
|
|
817
|
+
# 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.
|
|
818
|
+
country_filter: Analytics_Filter = Analytics_Filter(Country="US") # The Country parameter supports `ISO 3166-1 Alpha-2 format` only.
|
|
819
|
+
# These results will be filtered to only users within the US.
|
|
820
|
+
filtered_analytics: Analytics_Summary = await mcinstance.get_analytics_summary(filters=country_filter)
|
|
821
|
+
|
|
822
|
+
user_filter: Analytics_Filter = Analytics_Filter(Username="k8_thekat") # The IGN/Username of the user connected to the Server.
|
|
823
|
+
# These results will be filtered to only users with that match the parameter Username. (eg. k8_thekat).
|
|
824
|
+
filtered_analytics2: Analytics_Summary = await mcinstance.get_analytics_summary(filters=user_filter)
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
### Controlling data formatting -
|
|
831
|
+
- All JSON data returned from the API endpoints is formatted into a Dataclass/Enum/etc if possible.
|
|
832
|
+
- Data formatting can be controlled globally or locally by changing the `format_data` parameter of the method to `False`.
|
|
833
|
+
- When turning off the data formatting, typically you will get a `dictionary` back.
|
|
834
|
+
|
|
835
|
+
### Example -
|
|
836
|
+
```py
|
|
837
|
+
# By default all API calls will be formatted into Dataclasses if possible.
|
|
838
|
+
# You can toggle format_data off with ANY of the API classes that inherit Base().
|
|
839
|
+
ADS.format_data = False
|
|
840
|
+
|
|
841
|
+
# You can turn data formatting back on globally through any Instance object.
|
|
842
|
+
arkinstance.format_data = True
|
|
843
|
+
|
|
844
|
+
# You can turn off or on data formatting per function also.
|
|
845
|
+
await arkinstance.get_updates(format_data=False)
|
|
846
|
+
await arkinstance.get_role_data(format_data=True)
|
|
847
|
+
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
### Contributing to the project
|
|
852
|
+
|
|
853
|
+
# Git Commit message format
|
|
854
|
+
|
|
855
|
+
```
|
|
856
|
+
# file_name.py
|
|
857
|
+
- Change 1
|
|
858
|
+
- Change 2
|
|
859
|
+
-- Change 2 sub-change 1
|
|
860
|
+
|
|
861
|
+
$ This commit message will be omitted because of `$`
|
|
862
|
+
- Everything below it will be ignored too as long as it has a `-`
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
# AMP Version Bump
|
|
866
|
+
If the AMP version has changed, please generate new API spec sheets and upload them with any function changes.
|
|
867
|
+
- Run `await APIUtil.amp_api_update(instance=instance_here)`
|
|
868
|
+
|
|
@@ -3,12 +3,12 @@ requires = ["setuptools>=61.0"]
|
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
|
-
name = "cc-ampapi"
|
|
6
|
+
name = "cc-ampapi"
|
|
7
7
|
dynamic = ["version"]
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "k8thekat", email = "Cadwalladerkatelynn+AMPAPI@gmail.com" },
|
|
10
10
|
]
|
|
11
|
-
readme = { file = "README.
|
|
11
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
12
12
|
description = "A Python wrapper for the AMP API by CubeCoders"
|
|
13
13
|
requires-python = ">=3.10.0"
|
|
14
14
|
license = { file = "LICENSE" }
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|