Skip to main content

CPanel API Client for Python

Downloads Downloads Downloads

Supports cPanel API 2 and UAPI.

Install

$ pip install cpanel-api

Examples

Basic usage:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import sys

from pprint import pprint

from cpanel_api import CPanelApi

logging.basicConfig(level=logging.WARNING, stream=sys.stderr)

hostname = 'HOSTNAME_OR_IPADRESS'
username = 'USERNAME'
password = 'PASSWORD'

client = CPanelApi(hostname, username, password)

# Alternatively, to authenticate using a UAPI or cPanel API 2 token, use:
# client = CPanelApi(hostname, username, '<TOKEN>', auth_type = 'utoken')

# {'warnings': None, 'errors': None, 'data': {'port': '1243'}, 'metadata': {}, 'status': 1, 'messages': None}
r = client.uapi.SSH.get_port()
print('SSH port:', r.data.port)
# get all public ssh keys
# {'cpanelresult': {'postevent': {'result': 1}, 'apiversion': 2, 'data': [...], 'func': 'listkeys', 'event': {'result': 1}, 'module': 'SSH', 'preevent': {'result': 1}}}
r = client.cpanel2.SSH.listkeys()
pprint(r.cpanelresult.data)
# retrieve key
r = client.cpanel2.SSH.fetchkey(name='id_rsa')
# {"name": "id_rsa", "key": "ssh-rsa XXX"}
print(r.cpanelresult.data[0].key)
r = client.cpanel2.SSH.importkey(name='new_rsa.pub', key='*data*')
pprint(r)
# ...
r = client.cpanel2.DomainLookup.getdocroot(domain='site.info')
print(r.cpanelresult.data[0].reldocroot)  # public_html

Function call syntax:

client.api_version.ModuleName.function_name({'param': 'value'})
client.api_version.ModuleName.function_name(param='value')
client.api_version.ModuleName.function_name({'param': 'value'}, param='value')
client.api_cal('api_version', 'ModuleName', 'function_name', {'param': 'value'}, param='value')

Where api_version is cpanel2 or uapi.

Metadata

Release files for cpanel-api 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpanel-api 0.3.0
File Size Uploaded
cpanel-api-0.3.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cpanel-api 0.3.0
File Interpreter ABI Platform
cpanel_api-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / cpanel-api-0.3.0.tar.gz

Download URL cpanel-api-0.3.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d8a1df858ffbdfa7dbc50dc2a0ac629269bcc4d8e0c9d9031fe478577def9786
BLAKE2b-256 checksum
How to use checksums
085da05dbcc614db75c09d3e076f24cf0f954a3a9d326617fa617eee0c76ac93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.8.2 Linux/5.4.0-1047-azure

Release files / cpanel_api-0.3.0-py3-none-any.whl

Download URL cpanel_api-0.3.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d2deed5cd79f8d93991e180fcc00494906e11db8453a5f6b6dfdf60ec5c2ff6
BLAKE2b-256 checksum
How to use checksums
c586460969b1f4157ae8a0870bf348b61f2c1e3c1735cd2a1207c0ba3af56c42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.8.2 Linux/5.4.0-1047-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page