bsm-api-client 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bsm_api_client-1.0.0/LICENSE +21 -0
- bsm_api_client-1.0.0/PKG-INFO +127 -0
- bsm_api_client-1.0.0/README.md +102 -0
- bsm_api_client-1.0.0/pyproject.toml +40 -0
- bsm_api_client-1.0.0/setup.cfg +4 -0
- bsm_api_client-1.0.0/src/bsm_api_client/__init__.py +40 -0
- bsm_api_client-1.0.0/src/bsm_api_client/api_client.py +33 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client/__init__.py +1 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client/_content_methods.py +321 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client/_manager_methods.py +146 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client/_scheduler_methods.py +252 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client/_server_action_methods.py +352 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client/_server_info_methods.py +356 -0
- bsm_api_client-1.0.0/src/bsm_api_client/client_base.py +471 -0
- bsm_api_client-1.0.0/src/bsm_api_client/exceptions.py +102 -0
- bsm_api_client-1.0.0/src/bsm_api_client.egg-info/PKG-INFO +127 -0
- bsm_api_client-1.0.0/src/bsm_api_client.egg-info/SOURCES.txt +18 -0
- bsm_api_client-1.0.0/src/bsm_api_client.egg-info/dependency_links.txt +1 -0
- bsm_api_client-1.0.0/src/bsm_api_client.egg-info/requires.txt +1 -0
- bsm_api_client-1.0.0/src/bsm_api_client.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Danny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bsm-api-client
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python client library for the Bedrock Server Manager API
|
|
5
|
+
Author-email: DMedina559 <dmedina559-github@outlook.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/DMedina559/bsm-api-client
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/DMedina559/bsm-api-client/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/DMedina559/bsm-api-client/blob/main/docs/CHANGELOG.md
|
|
9
|
+
Keywords: minecraft,bedrock,server,manager,api,client,asyncio,aiohttp,bsm
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Framework :: AsyncIO
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: aiohttp<4.0.0,>=3.8.0
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
<div style="text-align: center;">
|
|
27
|
+
<img src="https://raw.githubusercontent.com/dmedina559/bedrock-server-manager/main/bedrock_server_manager/web/static/image/icon/favicon.svg" alt="BSM Logo" width="150">
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
# bsm-api-client
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/bsm-api-client/)
|
|
33
|
+
[](https://pypi.org/project/bsm-api-client/)
|
|
34
|
+
[](https://github.com/dmedina559/bsm-api-client/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
## Introduction
|
|
37
|
+
|
|
38
|
+
`bsm-api-client` is an asynchronous Python client library for interacting with the Bedrock Server Manager API. It provides a convenient way to manage Minecraft Bedrock Dedicated Servers through the manager's HTTP API.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
* Fully asynchronous using `asyncio` and `aiohttp`.
|
|
43
|
+
* Context manager support for session management.
|
|
44
|
+
* Handles authentication (JWT) automatically, including token refresh attempts.
|
|
45
|
+
* Provides methods for most BSM API endpoints:
|
|
46
|
+
* Manager Information & Global Actions
|
|
47
|
+
* Server Listing, Status & Configuration
|
|
48
|
+
* Server Actions (Start, Stop, Command, Update, etc.)
|
|
49
|
+
* Content Management (Backups, Worlds, Addons)
|
|
50
|
+
* OS-specific Task Scheduling (Cron for Linux, Task Scheduler for Windows)
|
|
51
|
+
* Custom exceptions for specific API errors, providing context like status codes and API messages.
|
|
52
|
+
* Supports connecting via HTTP or HTTPS.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
Install the library using pip:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install bsm-api-client
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
Here's a basic example of how to initialize the client and fetch server information:
|
|
65
|
+
|
|
66
|
+
For a complete list of endpoints and examples, see [API_DOCS.md](https://github.com/DMedina559/bsm-api-client/blob/main/docs/API_DOCS.md)
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import asyncio
|
|
70
|
+
from bsm_api_client import BedrockServerManagerApi, APIError, CannotConnectError
|
|
71
|
+
|
|
72
|
+
async def main():
|
|
73
|
+
client = BedrockServerManagerApi(
|
|
74
|
+
host="host", # e.g., "127.0.0.1" or "bsm.example.internal"
|
|
75
|
+
username="username", # Username for BSM login
|
|
76
|
+
password="password", # Password for BSM login
|
|
77
|
+
port=11325, # Optional: Not required for example if using domain such as bsm.example.internal
|
|
78
|
+
use_ssl=False # Set to True if your manager uses HTTPS
|
|
79
|
+
verify_ssl=True # Set to False if using HTTPS with a self-signed cert
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
async with client: # Handles session and token management
|
|
84
|
+
# Get manager info (no auth needed for this specific call, but client handles it)
|
|
85
|
+
manager_info = await client.async_get_info()
|
|
86
|
+
print(f"Manager OS: {manager_info.get('data', {}).get('os_type')}, Version: {manager_info.get('data', {}).get('app_version')}")
|
|
87
|
+
|
|
88
|
+
# Get list of all servers
|
|
89
|
+
servers = await client.async_get_servers_details()
|
|
90
|
+
if servers:
|
|
91
|
+
print("\nManaged Servers:")
|
|
92
|
+
for server in servers:
|
|
93
|
+
print(f" - Name: {server['name']}, Status: {server['status']}, Version: {server['version']}")
|
|
94
|
+
else:
|
|
95
|
+
print("No servers found.")
|
|
96
|
+
|
|
97
|
+
# Example: Start a specific server (replace 'MyServer' with an actual server name)
|
|
98
|
+
# server_name_to_start = "MyServer"
|
|
99
|
+
# if any(s['name'] == server_name_to_start for s in servers):
|
|
100
|
+
# print(f"\nAttempting to start server: {server_name_to_start}")
|
|
101
|
+
# start_response = await client.async_start_server(server_name_to_start)
|
|
102
|
+
# print(f"Start response: {start_response.get('message')}")
|
|
103
|
+
# else:
|
|
104
|
+
# print(f"\nServer '{server_name_to_start}' not found, cannot start.")
|
|
105
|
+
|
|
106
|
+
except AuthError as e:
|
|
107
|
+
print(f"Authentication Error: {e}")
|
|
108
|
+
except ServerNotFoundError as e:
|
|
109
|
+
print(f"Server Not Found Error: {e}")
|
|
110
|
+
except APIError as e:
|
|
111
|
+
print(f"An API Error occurred: {e}")
|
|
112
|
+
print(f" Status Code: {e.status_code}")
|
|
113
|
+
print(f" API Message: {e.api_message}")
|
|
114
|
+
print(f" API Errors: {e.api_errors}")
|
|
115
|
+
except CannotConnectError as e:
|
|
116
|
+
print(f"Connection Error: {e}")
|
|
117
|
+
except ValueError as e:
|
|
118
|
+
print(f"Input Error: {e}")
|
|
119
|
+
finally:
|
|
120
|
+
# The `async with client:` block handles closing the session.
|
|
121
|
+
# If not using context manager, you would call:
|
|
122
|
+
# await client.close()
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
asyncio.run(main())
|
|
127
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<div style="text-align: center;">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/dmedina559/bedrock-server-manager/main/bedrock_server_manager/web/static/image/icon/favicon.svg" alt="BSM Logo" width="150">
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# bsm-api-client
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/bsm-api-client/)
|
|
8
|
+
[](https://pypi.org/project/bsm-api-client/)
|
|
9
|
+
[](https://github.com/dmedina559/bsm-api-client/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
## Introduction
|
|
12
|
+
|
|
13
|
+
`bsm-api-client` is an asynchronous Python client library for interacting with the Bedrock Server Manager API. It provides a convenient way to manage Minecraft Bedrock Dedicated Servers through the manager's HTTP API.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
* Fully asynchronous using `asyncio` and `aiohttp`.
|
|
18
|
+
* Context manager support for session management.
|
|
19
|
+
* Handles authentication (JWT) automatically, including token refresh attempts.
|
|
20
|
+
* Provides methods for most BSM API endpoints:
|
|
21
|
+
* Manager Information & Global Actions
|
|
22
|
+
* Server Listing, Status & Configuration
|
|
23
|
+
* Server Actions (Start, Stop, Command, Update, etc.)
|
|
24
|
+
* Content Management (Backups, Worlds, Addons)
|
|
25
|
+
* OS-specific Task Scheduling (Cron for Linux, Task Scheduler for Windows)
|
|
26
|
+
* Custom exceptions for specific API errors, providing context like status codes and API messages.
|
|
27
|
+
* Supports connecting via HTTP or HTTPS.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Install the library using pip:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install bsm-api-client
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
Here's a basic example of how to initialize the client and fetch server information:
|
|
40
|
+
|
|
41
|
+
For a complete list of endpoints and examples, see [API_DOCS.md](https://github.com/DMedina559/bsm-api-client/blob/main/docs/API_DOCS.md)
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import asyncio
|
|
45
|
+
from bsm_api_client import BedrockServerManagerApi, APIError, CannotConnectError
|
|
46
|
+
|
|
47
|
+
async def main():
|
|
48
|
+
client = BedrockServerManagerApi(
|
|
49
|
+
host="host", # e.g., "127.0.0.1" or "bsm.example.internal"
|
|
50
|
+
username="username", # Username for BSM login
|
|
51
|
+
password="password", # Password for BSM login
|
|
52
|
+
port=11325, # Optional: Not required for example if using domain such as bsm.example.internal
|
|
53
|
+
use_ssl=False # Set to True if your manager uses HTTPS
|
|
54
|
+
verify_ssl=True # Set to False if using HTTPS with a self-signed cert
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
async with client: # Handles session and token management
|
|
59
|
+
# Get manager info (no auth needed for this specific call, but client handles it)
|
|
60
|
+
manager_info = await client.async_get_info()
|
|
61
|
+
print(f"Manager OS: {manager_info.get('data', {}).get('os_type')}, Version: {manager_info.get('data', {}).get('app_version')}")
|
|
62
|
+
|
|
63
|
+
# Get list of all servers
|
|
64
|
+
servers = await client.async_get_servers_details()
|
|
65
|
+
if servers:
|
|
66
|
+
print("\nManaged Servers:")
|
|
67
|
+
for server in servers:
|
|
68
|
+
print(f" - Name: {server['name']}, Status: {server['status']}, Version: {server['version']}")
|
|
69
|
+
else:
|
|
70
|
+
print("No servers found.")
|
|
71
|
+
|
|
72
|
+
# Example: Start a specific server (replace 'MyServer' with an actual server name)
|
|
73
|
+
# server_name_to_start = "MyServer"
|
|
74
|
+
# if any(s['name'] == server_name_to_start for s in servers):
|
|
75
|
+
# print(f"\nAttempting to start server: {server_name_to_start}")
|
|
76
|
+
# start_response = await client.async_start_server(server_name_to_start)
|
|
77
|
+
# print(f"Start response: {start_response.get('message')}")
|
|
78
|
+
# else:
|
|
79
|
+
# print(f"\nServer '{server_name_to_start}' not found, cannot start.")
|
|
80
|
+
|
|
81
|
+
except AuthError as e:
|
|
82
|
+
print(f"Authentication Error: {e}")
|
|
83
|
+
except ServerNotFoundError as e:
|
|
84
|
+
print(f"Server Not Found Error: {e}")
|
|
85
|
+
except APIError as e:
|
|
86
|
+
print(f"An API Error occurred: {e}")
|
|
87
|
+
print(f" Status Code: {e.status_code}")
|
|
88
|
+
print(f" API Message: {e.api_message}")
|
|
89
|
+
print(f" API Errors: {e.api_errors}")
|
|
90
|
+
except CannotConnectError as e:
|
|
91
|
+
print(f"Connection Error: {e}")
|
|
92
|
+
except ValueError as e:
|
|
93
|
+
print(f"Input Error: {e}")
|
|
94
|
+
finally:
|
|
95
|
+
# The `async with client:` block handles closing the session.
|
|
96
|
+
# If not using context manager, you would call:
|
|
97
|
+
# await client.close()
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
asyncio.run(main())
|
|
102
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# pyproject.toml
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["setuptools>=61.0"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "bsm-api-client"
|
|
8
|
+
version = "1.0.0"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="DMedina559", email="dmedina559-github@outlook.com" },
|
|
11
|
+
]
|
|
12
|
+
description = "A Python client library for the Bedrock Server Manager API"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.8"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Framework :: AsyncIO",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"aiohttp>=3.8.0,<4.0.0",
|
|
30
|
+
]
|
|
31
|
+
keywords = ["minecraft", "bedrock", "server", "manager", "api", "client", "asyncio", "aiohttp", "bsm"]
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["src"]
|
|
35
|
+
include = ["bsm_api_client*"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
"Homepage" = "https://github.com/DMedina559/bsm-api-client"
|
|
39
|
+
"Bug Tracker" = "https://github.com/DMedina559/bsm-api-client/issues"
|
|
40
|
+
"Changelog" = "https://github.com/DMedina559/bsm-api-client/blob/main/docs/CHANGELOG.md"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# src/bsm_api_client/__init__.py
|
|
2
|
+
"""Python client library for the Bedrock Server Manager API."""
|
|
3
|
+
import logging
|
|
4
|
+
from importlib import metadata
|
|
5
|
+
|
|
6
|
+
from .exceptions import (
|
|
7
|
+
APIError,
|
|
8
|
+
AuthError,
|
|
9
|
+
NotFoundError,
|
|
10
|
+
ServerNotFoundError,
|
|
11
|
+
ServerNotRunningError,
|
|
12
|
+
CannotConnectError,
|
|
13
|
+
InvalidInputError,
|
|
14
|
+
OperationFailedError,
|
|
15
|
+
APIServerSideError,
|
|
16
|
+
)
|
|
17
|
+
from .api_client import BedrockServerManagerApi
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"BedrockServerManagerApi",
|
|
21
|
+
"APIError",
|
|
22
|
+
"AuthError",
|
|
23
|
+
"ServerNotFoundError",
|
|
24
|
+
"ServerNotRunningError",
|
|
25
|
+
"CannotConnectError",
|
|
26
|
+
"InvalidInputError",
|
|
27
|
+
"OperationFailedError",
|
|
28
|
+
"APIServerSideError",
|
|
29
|
+
"__version__",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
__version__ = metadata.version(__name__)
|
|
34
|
+
except metadata.PackageNotFoundError:
|
|
35
|
+
__version__ = "0.0.0"
|
|
36
|
+
|
|
37
|
+
# Add a NullHandler to the root logger of the library.
|
|
38
|
+
# This prevents log messages from being output by default if the
|
|
39
|
+
# consuming application/script doesn't configure logging.
|
|
40
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# src/bsm_api_client/client.py
|
|
2
|
+
"""Main API client class for Bedrock Server Manager.
|
|
3
|
+
Combines the base client logic with specific endpoint method mixins.
|
|
4
|
+
"""
|
|
5
|
+
import logging
|
|
6
|
+
from .client_base import ClientBase
|
|
7
|
+
from .client._manager_methods import ManagerMethodsMixin
|
|
8
|
+
from .client._server_info_methods import ServerInfoMethodsMixin
|
|
9
|
+
from .client._server_action_methods import ServerActionMethodsMixin
|
|
10
|
+
from .client._content_methods import ContentMethodsMixin
|
|
11
|
+
from .client._scheduler_methods import SchedulerMethodsMixin
|
|
12
|
+
|
|
13
|
+
_LOGGER = logging.getLogger(__name__.split(".")[0] + ".client")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BedrockServerManagerApi(
|
|
17
|
+
ClientBase,
|
|
18
|
+
ManagerMethodsMixin,
|
|
19
|
+
ServerInfoMethodsMixin,
|
|
20
|
+
ServerActionMethodsMixin,
|
|
21
|
+
ContentMethodsMixin,
|
|
22
|
+
SchedulerMethodsMixin,
|
|
23
|
+
):
|
|
24
|
+
"""
|
|
25
|
+
API Client for the Bedrock Server Manager.
|
|
26
|
+
|
|
27
|
+
This class combines the base connection/authentication logic with
|
|
28
|
+
methods for interacting with various API endpoints, organized via mixins.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
# __init__ is inherited from ClientBase.
|
|
32
|
+
# All async API methods are inherited from mixins.
|
|
33
|
+
pass
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# src/bsm_api_client/client/__init__.py
|