A Python client library for the Bedrock Server Manager API
Project description
bsm-api-client
Introduction
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.
Features
- Fully asynchronous using
asyncioandaiohttp. - Context manager support for session management.
- Handles authentication (JWT) automatically, including token refresh attempts.
- Provides methods for most BSM API endpoints:
- Manager Information & Global Actions
- Server Listing, Status & Configuration
- Server Actions (Start, Stop, Command, Update, etc.)
- Content Management (Backups, Worlds, Addons)
- OS-specific Task Scheduling (Cron for Linux, Task Scheduler for Windows)
- Custom exceptions for specific API errors, providing context like status codes and API messages.
- Supports connecting via HTTP or HTTPS.
Installation
Install the library using pip:
pip install bsm-api-client
or if you wish to use the Command Line Interface CLI:
pip install bsm-api-client[cli]
Quick Start
Here's a basic example of how to initialize the client and fetch server information:
For a complete list of endpoints and examples, see API_DOCS.md
import asyncio
from bsm_api_client import BedrockServerManagerApi, APIError, CannotConnectError
async def main():
client = BedrockServerManagerApi(
base_url="http://host:port", # e.g., "http://127.0.0.1:11325" or "https://bsm.example.internal"
username="username", # Username for BSM login
password="password", # Password for BSM login
verify_ssl=True # Set to False if using HTTPS with a self-signed cert
)
try:
async with client: # Handles session and token management
# Get manager info (no auth needed for this specific call, but client handles it)
manager_info = await client.async_get_info()
print(f"Manager OS: {manager_info.get('data', {}).get('os_type')}, Version: {manager_info.get('data', {}).get('app_version')}")
# Get list of all servers
servers = await client.async_get_servers_details()
if servers:
print("\nManaged Servers:")
for server in servers:
print(f" - Name: {server['name']}, Status: {server['status']}, Version: {server['version']}")
else:
print("No servers found.")
# Example: Start a specific server (replace 'MyServer' with an actual server name)
# server_name_to_start = "MyServer"
# if any(s['name'] == server_name_to_start for s in servers):
# print(f"\nAttempting to start server: {server_name_to_start}")
# start_response = await client.async_start_server(server_name_to_start)
# print(f"Start response: {start_response.get('message')}")
# else:
# print(f"\nServer '{server_name_to_start}' not found, cannot start.")
except AuthError as e:
print(f"Authentication Error: {e}")
except ServerNotFoundError as e:
print(f"Server Not Found Error: {e}")
except APIError as e:
print(f"An API Error occurred: {e}")
print(f" Status Code: {e.status_code}")
print(f" API Message: {e.api_message}")
print(f" API Errors: {e.api_errors}")
except CannotConnectError as e:
print(f"Connection Error: {e}")
except ValueError as e:
print(f"Input Error: {e}")
finally:
# The `async with client:` block handles closing the session.
# If not using context manager, you would call:
# await client.close()
pass
if __name__ == "__main__":
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
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 bsm_api_client-1.2.1.tar.gz.
File metadata
- Download URL: bsm_api_client-1.2.1.tar.gz
- Upload date:
- Size: 43.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14d3571def8e328312ae6c01b1d71ab2d3c3b48ee08df5e3c5537e1ef6498a95
|
|
| MD5 |
2d35cdcbfaa5d838204f561ed779f4a0
|
|
| BLAKE2b-256 |
a124d6c5cffc2f122692fbea13dcd937d0a61cf8f0c25e973868ce5515421e20
|
Provenance
The following attestation bundles were made for bsm_api_client-1.2.1.tar.gz:
Publisher:
publish-to-pypi.yaml on DMedina559/bsm-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bsm_api_client-1.2.1.tar.gz -
Subject digest:
14d3571def8e328312ae6c01b1d71ab2d3c3b48ee08df5e3c5537e1ef6498a95 - Sigstore transparency entry: 309794802
- Sigstore integration time:
-
Permalink:
DMedina559/bsm-api-client@88823afb7734d637a334472295a56b6e5bcb319a -
Branch / Tag:
refs/tags/1.2.1 - Owner: https://github.com/DMedina559
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yaml@88823afb7734d637a334472295a56b6e5bcb319a -
Trigger Event:
release
-
Statement type:
File details
Details for the file bsm_api_client-1.2.1-py3-none-any.whl.
File metadata
- Download URL: bsm_api_client-1.2.1-py3-none-any.whl
- Upload date:
- Size: 53.2 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 |
e1b8ef0f854d85f977b7628984b31c1a4e24f68037652d02188cea86209a9f65
|
|
| MD5 |
a87785cfe44881e2dabb4aba2a7103af
|
|
| BLAKE2b-256 |
c9c009410a896e5d8c31e8bc46ba264bf4e288558426840d4f8a8a1d4d561000
|
Provenance
The following attestation bundles were made for bsm_api_client-1.2.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yaml on DMedina559/bsm-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bsm_api_client-1.2.1-py3-none-any.whl -
Subject digest:
e1b8ef0f854d85f977b7628984b31c1a4e24f68037652d02188cea86209a9f65 - Sigstore transparency entry: 309794863
- Sigstore integration time:
-
Permalink:
DMedina559/bsm-api-client@88823afb7734d637a334472295a56b6e5bcb319a -
Branch / Tag:
refs/tags/1.2.1 - Owner: https://github.com/DMedina559
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yaml@88823afb7734d637a334472295a56b6e5bcb319a -
Trigger Event:
release
-
Statement type: