https://github.com/sensson/python-directadmin
A Python interface to the DirectAdmin API
https://github.com/sensson/python-directadmin
directadmin python
Last synced: 10 months ago
JSON representation
A Python interface to the DirectAdmin API
- Host: GitHub
- URL: https://github.com/sensson/python-directadmin
- Owner: sensson
- License: mit
- Created: 2019-02-16T08:06:33.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2021-08-17T10:31:16.000Z (over 4 years ago)
- Last Synced: 2024-10-31T15:23:59.693Z (over 1 year ago)
- Topics: directadmin, python
- Language: Python
- Size: 11.7 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# python-directadmin
This is a Python interface to the DirectAdmin API.
# Usage
```
from directadmin.api import API
api = API(
username='username',
password='secure',
server='https://1.2.3.4:2222',
)
resellers = api.cmd_api_show_resellers()
print(resellers)
```
# API
`API()` handles all connections, calls and responses. It accepts the following
parameters:
* `username`: the username that you use to login to DirectAdmin;
* `password`: the password belonging to the username;
* `server`: the server you're connecting to, including http(s) and the port;
* `debug`: a boolean to turn on debugging mode;
* `json`: a boolean to enable JSON output in the DirectAdmin API.
Although it supports the new JSON output DirectAdmin uses in its evolution
skin, this hasn't been added for all endpoints yet. JSON output is disabled
by default.
## Supported methods
The [API documentation](https://www.directadmin.com/api.html) has a list of all
available endpoints in DirectAdmin. All endpoints DirectAdmin provides are
supported, including future ones.
In the DirectAdmin documentation you will find endpoints such as:
* CMD_API_ACCOUNT_USER
* CMD_API_SHOW_USER_DOMAINS
And others.
These translate directly to methods of the API object. For example:
* CMD_API_ACCOUNT_USER is accessed via `api.cmd_api_account_user()`;
* CMD_API_SHOW_USER_DOMAINS is accessed via `api.cmd_api_show_user_domains()`.
Every method accepts the keywords as documented by DirectAdmin. To create a new
user you would use:
```
api.cmd_api_account_user(
action='create',
add='Submit',
username='test',
...
)
```
## Impersonation
You can use `become()` to impersonate another user as an admin or reseller. For
example:
```
api = API(..)
api.become('username').cmd_api_databases(..)
```
`become()` will return a new instance of `API()`.
# Error handling
* `ResponseException` is raised when the API returns an unexpected response;
* `UnauthorizedException` is raised when your username or password is wrong.
Set `debug` to `True` when initializing the API object to get more information.
# Tests
Sorry, this code doesn't come with tests yet.