Skip to main content

An easy to use Python wrapper for the Pterodactyl Panel API.

Project description

pydactyl

Latest build Latest docs Coverage Latest version

An easy to use Python wrapper for the Pterodactyl Panel API.

State of the project

This wrapper is mostly complete for Pterodactyl 0.7. It will be updated to work with the 1.0 release, and it's likely that 0.7 support will be dropped at that time. Older versions that support 0.7 will remain available.

If you encounter problems, find APIs that haven't been implemented, or have a feature request please file a Github issue.

Installing

To install with pip:

pip install py-dactyl

Getting Started

Pterodactyl has two different types of API keys: Client (also known as Account) and Application. Any user can generate an Account API key to control their own servers. The Account API key for an Administrator user will be able to access any server's Client API. The Client API does not contain any destructive functions, so it is relatively safe to experiment with.

Application API keys can only be generated my administrators. These keys can be used to create, modify, and delete servers, among other things. They have access to any server on the panel and can be destructive, so use with care.

Client API

The Client API or Account API is accessed by users of the Pterodactyl panel. Below are examples of how you might get information about y our servers.

from pydactyl import PterodactylClient

# Create a client to connect to the panel and authenticate with your API key.
client = PterodactylClient('https://panel.mydomain.com', 'MySuperSecretApiKey')

# Get a list of all servers the user has access to
my_servers = client.client.list_servers()
# Get the unique identifier for the first server.
srv_id = my_servers[0]['identifier']

# Check the utilization of the server
srv_utilization = client.client.get_server_utilization(srv_id)
print(srv_utilization)

# Turn the server on.
client.client.send_power_action(srv_id, 'start')

Application API

The Application API is the administrative API of the Ptoerdactyl panel. Below are examples of how you might use this API.

from pydactyl import PterdoactylClient

# Create a client to connect to the panel and authenticate with your API key.
client = PterodactylClient('https://panel.mydomain.com', 'MySuperSecretApiKey')

# Create a server.  Customize the Nest and Egg IDs to match the IDs in your panel.
# This server is created with a limit of 8000 MB of memory, no access to swap, unlimited disk space, in location_id 1.
client.servers.create_server(name='My Paper Server', user_id=1, nest_id=1, 
                             egg_id=3, memory_limit=8000, swap_limit=0, 
                             disk_limit=0, location_ids=[1])
<Response [201]>

A 201 response indicates success, however if there is a problem with the request Pydactyl will raise an exception with additional details. When updating the location_ids field to an invalid location it displays an error:

client.servers.create_server(name='My Paper Server', user_id=1, nest_id=1, 
                            egg_id=3, memory_limit=8000, swap_limit=0, 
                            disk_limit=0, location_ids=[199])
Traceback (most recent call last):
 File "<input>", line 6, in <module>
 File "D:\code\pydactyl\pydactyl\api\servers.py", line 268, in create_server
   mode='POST', data=data, json=False)
 File "D:\code\pydactyl\pydactyl\api\base.py", line 98, in _api_request
   'code'], errors['detail'])
pydactyl.exceptions.PterodactylApiError: Bad API Request(400) - NoViableNodeException - No nodes satisfying the requirements specified for automatic deployment could be found.

You can use the User class to add, modify, and delete panel users.

# Create a new user
result = client.user.create_user('test_user', 'test@gmail.com', 'Test', 'Name')
# Get the ID of the created user
user_id = result['attributes']['id']
# Get the user info, also returned by create_user()
client.user.get_user_info(user_id)
{'object': 'user', 'attributes': {'id': 14, 'external_id': None, ....
# Delete the user
client.user.delete_user(user_id=14)

Paginated Responses

Pydactyl API responses return a PaginatedResponse object that can be iterated over to automatically fetch additional pages as required. It is currently only used by get_node_allocations(), however in time all Pydactyl methods will return this response.

# Create a list of all ports
allocs = client.nodes.list_node_allocations(node_id)
ports = []
for page in allocs:
    for item in page.data:
        ports.append(item['attributes']['port'])
len(ports)
151

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

py-dactyl-0.1.9.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

py_dactyl-0.1.9-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file py-dactyl-0.1.9.tar.gz.

File metadata

  • Download URL: py-dactyl-0.1.9.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.0

File hashes

Hashes for py-dactyl-0.1.9.tar.gz
Algorithm Hash digest
SHA256 2b27ded602c7bbbdfe062c91e25ac83d03c9616319a6b0a2c38375c2a4c37860
MD5 4cad1f8faccc06d8f60d3ff4a4077e06
BLAKE2b-256 ea9ba45071376197c9ed589c5c8eb05a95bfbdcf4295016b5df782889a1d75e8

See more details on using hashes here.

File details

Details for the file py_dactyl-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: py_dactyl-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.0

File hashes

Hashes for py_dactyl-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fbd10f30f653c000b26bd12d63ca34b6b847a1a71886e40ae4944778589dc872
MD5 af8782ee18a854ce46781d2ff9cd5667
BLAKE2b-256 75c854a22f487e1938c2fba762b5f07bc5774d1b18d190b0ac62803890f5ccb7

See more details on using hashes here.

Supported by

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