Skip to main content

Asyncronous Python wrapper for the BattleMetrics API.

Project description

BattleMetrics API Wrapper

Ruff PyPI - Version PyPI - Downloads

An async Python wrapper for the BattleMetrics API with full type safety using Pydantic models.

[!CAUTION] This API Wrapper is very new and partly untested. Please report any issues instantly.

[!NOTE] Since the BattleMetrics API Documentation is partly finished not every endpoint might be included. Make an Issue Report for any missing endpoints.

Installation

To install the latest published version off of PyPI, you can run the following command:

pip install battlemetrics

To install the development version from GitHub (requires Git):

pip install git+https://github.com/OseSem/battlemetrics

Usage

Basic Example

import asyncio
from battlemetrics import Battlemetrics

async def main():
    client = Battlemetrics("your-api-key")

    # Get server information
    server = await client.get_server(12345)
    print(f"Server: {server.attributes.name}")
    print(f"Players: {server.attributes.players}/{server.attributes.max_players}")

    await client.close()

asyncio.run(main())

Using the Context Manager

import asyncio
from battlemetrics import Battlemetrics

async def main():
    async with Battlemetrics("your-api-key") as client:
        # Search for players
        players = await client.list_players(search="username", game="rust")
        for player in players:
            print(f"Player: {player.attributes.name} (ID: {player.id})")

        # Get player session history
        if players:
            sessions = await client.player_session_history(players[0].id)
            for session in sessions:
                print(f"Session: {session.attributes.start} - {session.attributes.stop}")

asyncio.run(main())

Searching for Servers

import asyncio
from battlemetrics import Battlemetrics

async def main():
    async with Battlemetrics("your-api-key") as client:
        # Search for Rust servers in the US
        servers = await client.list_servers(
            search="vanilla",
            game="rust",
            countries=["US"],
            page_size=10
        )
        for server in servers:
            print(f"{server.attributes.name} - {server.attributes.players} players")

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

battlemetrics-2.1.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

battlemetrics-2.1.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file battlemetrics-2.1.0.tar.gz.

File metadata

  • Download URL: battlemetrics-2.1.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for battlemetrics-2.1.0.tar.gz
Algorithm Hash digest
SHA256 7c9c47d4bd54e30805239161be8fd01e0e2169e62d03d7dc81233a87b5079514
MD5 c36bcaaedef2a9bbd4c060576e4176b6
BLAKE2b-256 a8638cd07ef8c8f3e0f94207fa342186b5069a3c82b43739e721b7bb19d08901

See more details on using hashes here.

Provenance

The following attestation bundles were made for battlemetrics-2.1.0.tar.gz:

Publisher: release.yml on OseSem/battlemetrics

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

File details

Details for the file battlemetrics-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: battlemetrics-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for battlemetrics-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd0aac8b6d67dd637e93a7a378111cc23089643665f257e34f263d9531aa08d3
MD5 b6248b89c25433c349f2566d9aec10a5
BLAKE2b-256 6f8eca9654ee83da2d6517166268a49f7c5ce525766919f84703a60cbf2162ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for battlemetrics-2.1.0-py3-none-any.whl:

Publisher: release.yml on OseSem/battlemetrics

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