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.
Metadata
Release files for ampapi 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ampapi-1.1.5.tar.gz | 18.3 kB | Without provenance | Details for ampapi-1.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ampapi-1.1.5-py3-none-any.whl | Python 3 | none | any | Details for ampapi-1.1.5-py3-none-any.whl |
Total release size: 35.6 kB
Release files / ampapi-1.1.5.tar.gz
| Download URL | ampapi-1.1.5.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56e5b2b7ff8da0ccae154970f0741175bd7a5caeb4550f772906ff6e0cd7ae23
|
|
BLAKE2b-256 checksum How to use checksums |
042ed2a3d1c0daa453d74eeb8bab43717904170af3ce495488c810499ed503fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / ampapi-1.1.5-py3-none-any.whl
| Download URL | ampapi-1.1.5-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
283ac93c1024de6f19a5680daa5e78b047bd5f4da39e05c6d2eb055402a6029d
|
|
BLAKE2b-256 checksum How to use checksums |
f75c73dbb1d5705702cfca243945a98711555b5a31309dad157d3e1c4b84f205
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for ampapi 1.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.