Skip to main content

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

Project description

pydactyl

lint-and-test Latest docs Coverage Latest version Discord

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

State of the project

Support for Pterodactyl 1.x endpoints is mostly completed, however some endpoints are still missing. Future versions will not attempt to remain backwards compatible with versions of Pterodactyl before 1.0, however old versions of pydactyl that do support 0.7 will remain available.

The 1.0 release is mostly stable and will not see significant changes until the Pterodactyl 2.0 release. Pull Requests will still be accepted and new endpoints will continue to be added.

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

Documentation

Generated documentation can be found at https://pydactyl.readthedocs.io/ .

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.

Application API keys can only be generated by 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.

Exploring the API

In addition to the documentation you can explore the interface in an interactive Python interpreter using built-ins like dir() and the __doc__ attribute as shown below.

from pydactyl import PterodactylClient
api = PterodactylClient('debug', 'anything')

[i for i in dir(api.client.servers) if not i.startswith('_')]
# ['account', 'backups', 'databases', 'files', 'get_server', 'get_server_utilization', 'list_permissions', 'list_servers', 'network', 'schedules', 'send_console_command', 'send_power_action', 'servers', 'settings', 'startup', 'users']
[i for i in dir(api.client.servers.settings) if not i.startswith('_')]
# ['reinstall_server', 'rename_server']
print(api.client.servers.settings.rename_server.__doc__)
#Renames the server.
#        Args:
#            server_id(str): Server identifier (abbreviated UUID)
#            name(str): New name for the server

Client API

The Client API or Account API is accessed by users of the Pterodactyl panel. Below is the layout of the Client API namespace.

api.client.account
api.client.servers
api.client.servers.backups
api.client.servers.databases
api.client.servers.files
api.client.servers.network
api.client.servers.schedules
api.client.servers.settings
api.client.servers.startup
api.client.servers.users

A full list of methods available can be found in the documentation.

Below are examples of how you might get information about your servers.

from pydactyl import PterodactylClient

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

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

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

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

Application API

The Application API is the administrative API of the Pterodactyl panel. Below is the layout of the Application API namespace.

api.locations
api.nests
api.nodes
api.servers
api.user

Below are examples of how you might use this API.

from pydactyl import PterodactylClient

# Create a client to connect to the panel and authenticate with your API key.
api = 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.
api.servers.create_server(name='My Paper Server', user_id=1, nest_id=1,
                          egg_id=3, memory_limit=8000, swap_limit=0,
                          backup_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:

api.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 = api.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()
api.user.get_user_info(user_id)
{'object': 'user', 'attributes': {'id': 14, 'external_id': None, ....
# Delete the user
api.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 = api.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-1.1.5.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

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

py_dactyl-1.1.5-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for py-dactyl-1.1.5.tar.gz
Algorithm Hash digest
SHA256 84172c0131f5f7841d548b030548878945bf5a6be8f4a34bd3d8e33097f4cfe6
MD5 f6d76e8a2e6ee19ff37fbb0deaec77aa
BLAKE2b-256 76484ff22ce91d00d3c24133ebe79f366fd2c7a368b405dc18e66f5373bf9f0a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for py_dactyl-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c781a5afeba1568aa82831f3f81c6af581bb947ad6072175c2777c2a54480880
MD5 d92679358a37a5fe855ba7468548cb3c
BLAKE2b-256 2ebd553131754515423c572c003e757525cfab1997c9f6936d11a1d872b1113c

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