Skip to main content

A Python implemenation of the Cubecoders AMP API.

Project description

ampapi-python

This API 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.

Installation

pip install ampapi

or

pip install 'ampapi @ git+https://github.com/p0t4t0sandwich/ampapi-python.git'

You also need the following packages installed:

pip install requests aiohttp json

Async Example

import asyncio
from ampapi.ampapi import AMPAPI

async def start() -> None:
    API = AMPAPI("http://localhost:8080/")

    try:
        # 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 = await API.Core_LoginAsync("admin", "myfancypassword123", "", False)

        if "success" in loginResult.keys() and loginResult["success"]:
            print("Login successful")
            API.sessionId = loginResult["sessionID"]

            # API call parameters are simply in the same order as shown in the documentation.
            await API.Core_SendConsoleMessageAsync("say Hello Everyone, this message was sent from the Python API!")
            currentStatus = await API.Core_GetStatusAsync()
            CPUUsagePercent = currentStatus["Metrics"]["CPU Usage"]["Percent"]
            print(f"Current CPU usage is: {CPUUsagePercent}%")

        else:
            print("Login failed")
            print(loginResult)

    except Exception as err:
        print(err)

asyncio.run(start())

Non-Async Example

from ampapi.ampapi import AMPAPI

def start() -> None:
    API = AMPAPI("http://localhost:8080/")

    try:
        # 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)

        if "success" in loginResult.keys() and loginResult["success"]:
            print("Login successful")
            API.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"]["Percent"]
            print(f"Current CPU usage is: {CPUUsagePercent}%")

        else:
            print("Login failed")
            print(loginResult)

    except Exception as err:
        print(err)

start()

Notes on generating implementations

ampapi-python is generated using a script that parses the API spec. The ampapai_gen.py script under /utils can be used to generate future versions of the API. It requires the requests and json packages to be installed.

To generate a new version, set the AMP_URL, AMP_USERNAME, and AMP_PASSWORD environment variables and run the script.

Notes on missing methods

The generation script only uses the base ADS APISpec of an AMP Network Licence (my current licence). This means any Enterprise methods, methods added by plugins, or module-specific methods are not included. If you find yourself needing these methods frequently, please use the insance's API endpoint with the ampapai_gen.py script under /utils, then submit a pull request with the generated code. If you need a method that is not included, you can use the AMPAPI.APICall method to run the method directly.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ampapi-1.1.3.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ampapi-1.1.3-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file ampapi-1.1.3.tar.gz.

File metadata

  • Download URL: ampapi-1.1.3.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ampapi-1.1.3.tar.gz
Algorithm Hash digest
SHA256 b1c513ee619361ffdce1a58e0e948b77dfa656add4ca8df6f1852c9ec4552dc7
MD5 ccb64b35b0cafadd90028655873bebb5
BLAKE2b-256 0d888af0662821e207db9395172a7e5015e75a44f6f91808c2a2e683169817e7

See more details on using hashes here.

File details

Details for the file ampapi-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: ampapi-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ampapi-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4708f56da70360332e3f6c7a547e9824db18e9f1f7aed81f8115f40d79a8fe6c
MD5 3fc4ea3c1c2d8420a98961047ad3d5f8
BLAKE2b-256 e99089a367e6fa6cfec5acf78cdc6956e69d6c4b44afade5267b7b5df31a2dc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page