Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Make easy requests to Parallels Plesk Panel API

Project description

Easy requests to Parallels Plesk Panel API RPC.


Instead of building complex structures of XML, you can write all the requests in dict types. Pypleskapi converts dict type packets into XML structures, and so as the other way around, you just need to know how to write the corresponding dict structure.

>>> from pleskapi import StructDict
>>> from pleskapi import send_packet

>>> packet = StructDict('')
>>> packet['webspace']['get']['filter'] = {'name' : 'domain.tld'}
>>> packet['webspace']['get']['dataset']['gen_info']

>>> print packet.dict()
{'packet': {'webspace': {'get': {'filter': {'name': 'domain.tld'}, 'dataset': {'gen_info': {}}}}, '@version': ''}}

>>> print packet.xml(True)
<?xml version="1.0" encoding="UTF-8"?>
<packet version="">

>>> r = send_packet(packet.dict())
>>> r.response()
{'version': '', 'result': {'status': 'ok', 'filter-id': 'domain.tld', 'id': '36'}}

StructDict builds chain’s of dict without expliciting, common dict’s are build this way:

>>> d = dict() or {}
>>> d['webspace'] = {}
{'webspace': {}}

You need to create a new dict for every key:

>>> d['webspace'] = {}
>>> d['webspace']['get'] = {}
{'webspace': {'get': {}}}
>>> d['webspace']['get']['filter'] = { 'name' : 'domain.tld' }
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'get'

With StructDict you can build chain’s of dict:

>>> from pleskapi import StructDict
""" refer to  packet header body - <packet version="">...</packet> """
>>> sd = StructDict('')
>>> sd['webspace']['get']['filter']
>>> sd
{'webspace': {'get': {'filter': {}}}}
>>> print sd.xml()
<?xml version="1.0" encoding="UTF-8"?><packet version=""><webspace><get><filter/></get></webspace></packet>

Reference: Plesk API. The conversion is based in Hay’s project.


The following command will install pleskapi into your Python modules library:

$ python install

This command will generally need to be run with an administrative level account.


$ pip install pypleskapi


If you want to build ordered dict’s, you MUST have python2.7+ or OrderedDict.


Before starting this topic, I recommend the reading of API RPC Manual <> for better understanding how it works. For building dict structures that will become valid requests to Plesk API RPC, you need to understand how a dict represents an XML structure. The conversion follow the example bellow:

XML                              JSON
<e/>                             "e": null
<e>text</e>                      "e": "text"
<e name="value" />               "e": { "@name": "value" }
<e name="value">text</e>         "e": { "@name": "value", "#text": "text" }
<e> <a>text</a ><b>text</b> </e> "e": { "a": "text", "b": "text" }
<e> <a>text</a> <a>text</a> </e> "e": { "a": ["text", "text"] }
<e> text <a>text</a> </e>        "e": { "#text": "text", "a": "text" }

Reference: Converting Between XML and JSON.

An easy way of understanding it’s using the converter functions, you can convert from an XML structure to a python dict type

>>> from pleskapi import converter as conv
>>> xmlstr = '<?xml version="1.0" encoding="UTF-8"?><packet version=""><webspace><get><filter/></get></webspace></packet>'
>>> conv.xml2dict(xmlstr)
{'packet': {'webspace': {'get': {'filter': None}}, '@version': ''}}

Ordering Dict’s

Plesk RPC API needs that the XML structure follow a specific order, more info: API RPC Manual - API RPC > API RPC Packets > How to Create Packets.

A python dict type is unordered, so you need to use an OrderedDict type for ordering only the necessary keys. Let’s consider the XML string bellow:

<?xml version="1.0" encoding="UTF-8"?>
<packet version="">

ip_address node must be the first, netmask the second and so on. Building this structure without using OrderedDict, outputs to:

>>> from pleskapi import StructDict as sd

>>> sd['ip']['add'] = {}
>>> sd['ip']['add']['ip_address'] = ''
>>> sd['ip']['add']['netmask'] = ''
>>> sd['ip']['add']['type'] = 'shared'
>>> sd['ip']['add']['interface'] = 'eth0'
>>> sd.dict()
{'ip': {'add': {'interface': 'eth0', 'type': 'shared', 'netmask': '', 'ip_address': ''}}}

The keys in ‘add’ are unordered, so the XML structure will be:

<?xml version="1.0" encoding="UTF-8"?>
<packet version="">

This packet will return an error because the nodes are not ordered as it should. Ordering then are an easy task, just need to use the proper type:

>>> from pleskapi import StructDict as sd
>>> from pleskapi import odict

>>> sd['ip']['add'] = odict()
>>> sd['ip']['add']['ip_address'] = ''
>>> sd['ip']['add']['netmask'] = ''
>>> sd['ip']['add']['type'] = 'shared'
>>> sd['ip']['add']['interface'] = 'eth0'
>>> sd.dict()
{'ip': {'add': OrderedDict([('ip_address', ''), ('netmask', ''), ('type', 'shared'), ('interface', 'eth0')])}}

More examples


0.1.2 (2013-03-10)

  • Fixed on PyPi again: missing
  • Added PleskApiError class on package pleskapi
  • Updated docs and added LICENSE file

0.1.1 (2013-03-10)

  • Fixing on PyPi

0.1 (2013-03-10)

  • Birth

Project details

Download files

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

Files for python-pleskapi, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size python-pleskapi-0.1.2.tar.gz (7.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page