Skip to main content

A Python client library for the Bedrock Server Manager API

Project description

BSM Logo

bsm-api-client

PyPI version Python Versions License

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 asyncio and aiohttp.
  • 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

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(
        host="host",                   # e.g., "127.0.0.1" or "bsm.example.internal"
        username="username",           # Username for BSM login
        password="password",           # Password for BSM login
        port=11325,                    # Optional: Not required for example if using domain such as bsm.example.internal
        use_ssl=False                  # Set to True if your manager uses HTTPS
        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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bsm_api_client-1.0.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bsm_api_client-1.0.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file bsm_api_client-1.0.0.tar.gz.

File metadata

  • Download URL: bsm_api_client-1.0.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bsm_api_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a9df5327c69bf34eb0c798371f0b221f84c6667da6b93d036f495d0fbdfd383e
MD5 5d41b5f7daa423153056e84abf2fefcb
BLAKE2b-256 917d9f783406e70215a922087cc8ba1030eed2793573c4722796d55de37f0df5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bsm_api_client-1.0.0.tar.gz:

Publisher: publish-to-pypi.yaml on DMedina559/bsm-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bsm_api_client-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bsm_api_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bsm_api_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2678fedc59b1f9dd561873934548d2a0b682593b9226879f3aa472de93973b5b
MD5 23c4c52bf21d30b5de5a4c0d71f61d8c
BLAKE2b-256 a93e753ff4d5cf67da0e8f8d567da6e85a996738ec8ca71f3f06eb46b41dcbeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for bsm_api_client-1.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yaml on DMedina559/bsm-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page