Skip to main content

A Python wrapper around the Ballchasing API

Project description

Python Ballchasing

An easy-to-use and comprehensive Python wrapper for the ballchasing.com API.

Installation

You can install the library from PyPI using pip:

pip install python-ballchasing

Authentication

Before you can use the library, you need an API authentication key from ballchasing.com.

  1. Log in to ballchasing.com.
  2. Navigate to the Upload tab.
  3. Create an API key and copy it.

Keep your API key secure and do not share it publicly.

API

For detailed information, please refer to the docs inside the code. For the most part it follows the API spec closely, but there are some differences.

The API is exposed via the BallchasingApi class.

Making the client:

from ballchasing import BallchasingApi
api = BallchasingApi("Your token here")

or equivalently

import ballchasing
api = ballchasing.Api("Your token here")

By default this will also ping the API to make sure it's working.


Some simple examples:

# Get lots of SSL replays

from ballchasing import Rank  # there's also Playlist, Season, Map, and more

replays = api.get_replays(
  min_rank=Rank.SUPERSONIC_LEGEND,
  count=10_000  # The API limits you to 200 replays per request but the library handles this for you
)

for replay in replays:  # (replays is an iterable so you don't need to wait for all the replays to be collected)
  ...  # Do something with the replays
# Get a specific replay with more detail than the iterator (including stats!)
replay = api.get_replay("2627e02a-aa46-4e13-b66b-b76a32069a07")
# Get groups by the "RLCS Referee" account
groups = api.get_groups(creator="76561199225615730")

for group in groups:
  # Download the group
  api.download_group(
    group_id=group["id"],
    path="/path/to/destination/"
    recursive=True,  # To download all the replays and retain the group structure with subfolders
  )

  # Get replays from the group
  replays = get_group_replays(
    group_id=group["id"],
    deep=True,  # To get detailed replay info
  )
  for replay in replays:
    api.download_replay(replay_id=replay["id"], path="/path/to/destination/")  # You could also download like this

Additionally, there's the option to put responses (replays, groups) into typed objects for better type hinting and validation. It also attempts to fill in missing variables not returned by ballchasing (e.g. if a team has 0 goals they won't have a "goal" entry in the response) The classes can also be found under the typing folder and used as a reference for what the API returns.

# When creating the API, you can specify a default setting for typing (defaults to False)
api = ballchasing.Api("Your token here", typed=True)

# or you can specify it explicitly
replay = api.get_replay("2627e02a-aa46-4e13-b66b-b76a32069a07", typed=True)
print(replay.blue.players[0].name)  # Example of easy attribute access

group = api.get_group("g2-vs-bds-hwbf2eyolb", typed=True)
print(group.players[0].name)

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

python_ballchasing-0.5.0.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

python_ballchasing-0.5.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file python_ballchasing-0.5.0.tar.gz.

File metadata

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

File hashes

Hashes for python_ballchasing-0.5.0.tar.gz
Algorithm Hash digest
SHA256 edd84c07ebfac8b0c2312d3a58825e63b9903c606c9c0f95164b2842debc664b
MD5 dd714765ca098e61e296d49df6b3b76e
BLAKE2b-256 400329beb8008c6b00588f04130c12c897fb1647bd301be4943bce19a979a4cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_ballchasing-0.5.0.tar.gz:

Publisher: python-publish.yml on Rolv-Arild/python-ballchasing

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

File details

Details for the file python_ballchasing-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_ballchasing-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63224f16f03b1c480cdca1cc2f884d31723f27732d35ef0c3acecf8fde813c47
MD5 e46445918e8043b63a62261de8ca96e8
BLAKE2b-256 2cc9857ded7f51a674daf70cd6af4862284790a72ff54f889b13f4c9750c7f2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_ballchasing-0.5.0-py3-none-any.whl:

Publisher: python-publish.yml on Rolv-Arild/python-ballchasing

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