Package: ampapi
ampapi-pyAn API that allows you to communicate with AMP installations from within Python.Documentation for available API calls can be found by appending /API to the URL of any existing AMP installation.Support:Ping@thepotatoking3452in the#developmentchannel of theAMP DiscordMy owndevelopment DiscordInstallationpipinstallampapiorpipinstall'ampapi @ git+https://github.com/p0t4t0sandwich/ampapi-py.git'You also need the following packages installed:pipinstallrequestsaiohttpjsonNotesI've redone the return types, most should work, but if you find any that don't, please let me know.ExamplesCommonAPI Examplefromampapi.modules.CommonAPIimportCommonAPIdefmain():# If you know the module that the instance is using, specify it instead of CommonAPIAPI=CommonAPI("http://localhost:8080/","admin","myfancypassword123")API.Login()# API call parameters are simply in the same order as shown in the documentation.API.Core.SendConsoleMessage("say Hello Everyone, this message was sent from the Python API!")currentStatus=API.Core.GetStatus()CPUUsagePercent=currentStatus.Metrics["CPU Usage"].Percentprint(f"Current CPU usage is:{CPUUsagePercent}%")main()Async CommonAPI Exampleimportasynciofromampapi.modules.CommonAPIimportCommonAPIasyncdefmain():# If you know the module that the instance is using, specify it instead of CommonAPIAPI=CommonAPI("http://localhost:8080/","admin","myfancypassword123")awaitAPI.LoginAsync()# API call parameters are simply in the same order as shown in the documentation.awaitAPI.Core.SendConsoleMessageAsync("say Hello Everyone, this message was sent from the Python API!")currentStatus=awaitAPI.Core.GetStatusAsync()CPUUsagePercent=currentStatus.Metrics["CPU Usage"].Percentprint(f"Current CPU usage is:{CPUUsagePercent}%")asyncio.run(main())Example using the ADS to manage an instancefromampapi.modules.ADSimportADSAPI=ADS("http://localhost:8080/","admin","myfancypassword123")API.Login()# Get the available instancestargets=API.ADSModule.GetInstances()# In this example, my Hub server is on the second target# If you're running a standalone setup, you can just use targets[1]target=targets[1]hub_instance_id=""# Get the available instancesinstances=target.AvailableInstancesforinstanceininstances:# Find the instance named "Hub"ifinstance.InstanceName=="Hub":hub_instance_id=instance.InstanceIDbreak# Use the instance ID to get the API for the instanceHub=API.InstanceLogin(hub_instance_id,"Minecraft")# Get the current CPU usagecurrentStatus=Hub.Core.GetStatus()CPUUsagePercent=currentStatus.Metrics["CPU Usage"].Percent# Send a message to the consoleHub.Core.SendConsoleMessage(f"say Current CPU usage is{CPUUsagePercent}%")CommonAPI Example, handling the sessionId and rememberMeToken manually (not recommended)fromampapi.modules.CommonAPIimportCommonAPItry:API=CommonAPI("http://localhost:8080/")# The third parameter is either used for 2FA logins, or if no password is specified to use a remembered token from a previous login, or a service login token.loginResult=API.Core.Login("admin","myfancypassword123","",False)ifloginResult.success:print("Login successful")API.sessionId=loginResult.sessionIDAPI.Core.sessionId=loginResult.sessionID# API call parameters are simply in the same order as shown in the documentation.API.Core.SendConsoleMessage("say Hello Everyone, this message was sent from the Python API!")currentStatus=API.Core.GetStatus()CPUUsagePercent=currentStatus.Metrics["CPU Usage"].Percentprint(f"Current CPU usage is:{CPUUsagePercent}%")else:print("Login failed")print(loginResult)exceptExceptionaserr:# In reality, you'd handle this exception betterraiseException(err)