Pybt is a Python SDK for the BT Panel API. It provides a comprehensive set of tools for managing and automating tasks on servers running the BaoTa Panel.
Project description
About
Pybt is a Python SDK for the BT Panel API. It provides a comprehensive set of tools for managing and automating tasks on servers running the BaoTa Panel.
Documentation
-
For detailed documentation, please visit our online documentation.
-
Official API Documentation: https://www.bt.cn/api-doc.pdf
Installation
pip install bt-python-sdk
or
git clone https://github.com/adamzhang1987/bt-python-sdk.git
python setup.py install
Configuration
The SDK uses environment variables for configuration. You can set these up in two ways:
-
Using a
.envfile (recommended):# Create a .env file in your project root BT_API_KEY="your-api-key" BT_PANEL_HOST="http://localhost:8888" DEBUG=False TIMEOUT=30 VERIFY_SSL=False
-
Setting environment variables directly:
export BT_API_KEY="your-api-key" export BT_PANEL_HOST="http://localhost:8888" export DEBUG=False export TIMEOUT=30 export VERIFY_SSL=False
Note: The
.envfile should be added to your.gitignoreto keep your API key secure.
Examples
- First, enable the API interface in
Panel Settings-API Interfaceand obtain yourAPI Key. - After enabling the API, only IPs in the whitelist can access the panel API interface.
- To call the panel API from your local machine, add "127.0.0.1" and your local IP to the whitelist.
For the
BT_PANEL_HOSTparameter, you only need to provide the panel's domain or IP with port, e.g.,http://192.168.1.168:8888.
# System status related APIs
>>> from pybt.api import System
>>> system_api = System() # Will automatically use environment variables
# Get system basic statistics
>>> system_api.get_system_total()
{'memTotal': 31700,
'memFree': 18403,
'memBuffers': 1020,
'memCached': 8444,
'memRealUsed': 3833,
'cpuNum': 12,
'cpuRealUsed': 4.9,
'time': '36 days',
'system': 'Ubuntu 20.04.3 LTS x86_64(Py3.7.9)',
'isuser': 0,
'isport': True,
'version': '7.7.0'}
# Get disk partition information
>>> system_api.get_disk_info()
[{'filesystem': '/dev/sda6',
'type': 'ext4',
'path': '/',
'size': ['1.1T', '23G', '1005G', '3%'],
'inodes': ['72089600', '360084', '71729516', '1%']}]
# Website management related APIs
>>> from pybt.api import Website, WebsiteBackup, Domain, Rewrite, Directory, PasswordAccess, TrafficLimit, DefaultDocument
>>> website_api = Website() # Will automatically use environment variables
# Get website list
>>> website_api.get_website_list()
{'where': '',
'page': "<div><span class='Pcurrent'>1</span><span class='Pcount'>Total: 1</span></div>",
'data': [{'id': 5,
'name': '10.10.11.181',
'path': '/www/wwwroot/webSiteDir',
'status': '1',
'ps': '10_10_11_181',
'addtime': '2021-06-12 22:57:32',
'edate': '0000-00-00',
'backup_count': 0,
'domain': 2,
'ssl': {'issuer': 'R3',
'notAfter': '2022-03-09',
'notBefore': '2021-12-09',
'dns': ['*.*.com'],
'subject': '*.*.com',
'endtime': 73},
'php_version': 'Static'}]}
# Get PHP version information
>>> website_api.get_php_versions()
[{'version': '00', 'name': 'Static'}, {'version': '56', 'name': 'PHP-56'}]
# Website backup management
>>> backup_api = WebsiteBackup()
>>> backup_api.get_backup_list(search=5) # Get backups for website ID 5
# Domain management
>>> domain_api = Domain()
>>> domain_api.get_domain_list(site_id=5) # Get domains for website ID 5
# Directory and configuration management
>>> dir_api = Directory()
>>> dir_api.get_root_path(id=5) # Get root path for website ID 5
# Password access control
>>> pwd_api = PasswordAccess()
>>> pwd_api.set_password_access(id=5, username="admin", password="secret")
# Traffic limit management
>>> traffic_api = TrafficLimit()
>>> traffic_api.set_traffic_limit(id=5, perserver=100, perip=10, limit_rate=1024)
# Default document management
>>> doc_api = DefaultDocument()
>>> doc_api.set_default_document(id=5, index="index.php,index.html")
Features
Click the triangle to expand and view module methods. For detailed module parameters, see the online documentation
System: System Status Related APIs
get_system_total Get system basic statisticsget_disk_info Get disk partition informationget_network Get real-time status information (CPU, memory, network, load)get_task_count Check for installation tasksupdate_panel Check panel updates
Website: Basic Website Management
get_website_list Get website listget_site_types Get website categoriesget_php_versions Get installed PHP version listcreate_website Create websitedelete_website Delete websitestop_website Stop websitestart_website Start websiteset_expiry_date Set website expiration dateset_website_remark Modify website remarks
WebsiteBackup: Website Backup Management
get_backup_list Get website backup listcreate_backup Create website backupdelete_backup Delete website backup
Domain: Domain Management
get_domain_list Get website domain listadd_domain Add website domaindelete_domain Delete website domain
Rewrite: Rewrite and Configuration Management
get_rewrite_list Get available rewrite rulesget_rewrite_content Get rewrite rule contentsave_rewrite_content Save rewrite rule content
Directory: Website Directory and Runtime Configuration
get_root_path Get website root directoryget_directory_config Get directory configurationtoggle_cross_site Toggle cross-site protectiontoggle_access_log Toggle access logset_root_path Set website root directoryset_run_path Set website run directory
PasswordAccess: Password Access Control
set_password_access Set password access for websiteclose_password_access Close password access for website
TrafficLimit: Traffic Limit Management
get_traffic_limit Get traffic limit configurationset_traffic_limit Set traffic limit configurationclose_traffic_limit Close traffic limit
DefaultDocument: Default Document Management
get_default_document Get default document configurationset_default_document Set default document configuration
Testing
Before running unit tests, create a .env file in the project root with the following content:
BT_API_KEY="your-api-key"
BT_PANEL_HOST="http://localhost:8888"
DEBUG=False
TIMEOUT=30
VERIFY_SSL=False
Then run:
# Run unit tests only
pytest
# Run both unit and integration tests
pytest --run-integration
# Run only integration tests
pytest -m integration --run-integration
Good luck! :star:
Powered by bt APIs.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bt_python_sdk-1.0.1.tar.gz.
File metadata
- Download URL: bt_python_sdk-1.0.1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05ecdb569dfd74b303c7defc457a7653298b742faa983c4ddc38d8af84e2b44e
|
|
| MD5 |
0b3c94980ca5d68294542e7cb9010c16
|
|
| BLAKE2b-256 |
530142f6f7705c9ca74b22bf4db80b3f6daa6a14f99da77f23ae0f550ad97ca7
|
Provenance
The following attestation bundles were made for bt_python_sdk-1.0.1.tar.gz:
Publisher:
python-publish.yml on adamzhang1987/bt-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bt_python_sdk-1.0.1.tar.gz -
Subject digest:
05ecdb569dfd74b303c7defc457a7653298b742faa983c4ddc38d8af84e2b44e - Sigstore transparency entry: 212316284
- Sigstore integration time:
-
Permalink:
adamzhang1987/bt-python-sdk@8541c33cf9193dc1f2d2d355c1fe9584c26de8c2 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/adamzhang1987
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8541c33cf9193dc1f2d2d355c1fe9584c26de8c2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bt_python_sdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: bt_python_sdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
334e3f642ff14cbeb0a5c24ca11bceb92011f00c64b85beb5814a534ff5bcf26
|
|
| MD5 |
79ea196bfb3b6943fddf91cba608d8cd
|
|
| BLAKE2b-256 |
6b84ca6cec1d29f2920214ea69062ec2cc63fb91aaf226eb3817cd3b6cc86e0b
|
Provenance
The following attestation bundles were made for bt_python_sdk-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on adamzhang1987/bt-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bt_python_sdk-1.0.1-py3-none-any.whl -
Subject digest:
334e3f642ff14cbeb0a5c24ca11bceb92011f00c64b85beb5814a534ff5bcf26 - Sigstore transparency entry: 212316286
- Sigstore integration time:
-
Permalink:
adamzhang1987/bt-python-sdk@8541c33cf9193dc1f2d2d355c1fe9584c26de8c2 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/adamzhang1987
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8541c33cf9193dc1f2d2d355c1fe9584c26de8c2 -
Trigger Event:
release
-
Statement type: