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.0.5.tar.gz (28.1 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.0.5-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for battlemetrics-2.0.5.tar.gz
Algorithm Hash digest
SHA256 db76200bd7b4873ea5020e1bfc936498701e1c9f60f0e419fd32c783568876b8
MD5 7b55479cda33bfafc1646c51634ecc85
BLAKE2b-256 65b1de131135f9f03b87ab68de875ed3e159caba0c437b93875830ecf32f80c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for battlemetrics-2.0.5.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.0.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for battlemetrics-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8bc629867f6f796186872fc584f9f0669fec49fef3e75885ab8caa2dc2469ce2
MD5 dbeb0c4d2590a37f4bd8ff21463cab04
BLAKE2b-256 8e87efde4100600344bdb5b50ed223e5209ec2906f1842e34da0ff64a984bd25

See more details on using hashes here.

Provenance

The following attestation bundles were made for battlemetrics-2.0.5-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