A drop in library to provide requests and responses to the various Tap Titans 2 APIs
- Modern Pythonic API using
async
/await
syntax - Easy to use with an object-oriented design
- Cross version compatibility.
- Interfaces for all TapTitans2 APIs; SocketIO, Rest, PublicAPI
- Fully annotated using python typehinting
- You need to request a Player Token of a clan Master or GrandMaster. They can create one for you by going to the
Settings -> Player API Tokens
in the app - You will need to join the GameHive Discord and ask for an API Token in the channel #app-token-request.
- You need to be prepared to run this 24/7 with a stable connection. GameHive does not store events and so if this isn't running, events will be skipped with no way to get them again. I recommend Google Compute Engine which has a permanent free tier on a E2-micro instance.
Python 3.10 or higher is required Download Here
Installation is done by using the pip install command. Usually it is already included with the python install.
To install the library
# Linux/macOS
python3 -m pip install -U git+https://github.com/SilicalNZ/TapTitans2py
# Windows
py -3 -m pip install -U git+https://github.com/SilicalNZ/TapTitans2py
import asyncio
from tap_titans.providers import providers
from tap_titans.models import models
AUTH_TOKEN = "auth_token"
PLAYER_TOKENS = ["player_token"]
async def connected():
print("Connected")
r = providers.RestAPI(AUTH_TOKEN)
resp = await r.subscribe(PLAYER_TOKENS)
if len(resp.refused) > 0:
print("Failed to subscribe to clan with reason:", resp.refused[0].reason)
else:
print("Subscribed to clan:", resp.ok[0].clan_code)
async def clan_added_cycle(message: models.raid_models.RaidCycleResetClanAdded):
print("Clan Added Cycle", message)
print("Raid level of clan", message.raid.level)
async def raid_attack_end(message: models.raid_models.RaidAttackEnd):
print("Raid Attack", message)
async def player_connected():
print("Player WS is connected, can now use the rest API /player endpoints")
r = providers.RestAPI(AUTH_TOKEN)
resp = await r.player_data(PLAYER_TOKENS[0], providers.PlayerDataProperties.all())
print("Name of the player who owns the token:", resp.name)
websocket = providers.WebsocketClient(
connected=connected,
raid_attack_end=raid_attack_end,
clan_added_cycle=clan_added_cycle,
setting_validate_arguments=True,
player_connected=player_connected,
)
asyncio.run(websocket.connect(AUTH_TOKEN))
Find more examples in the examples directory
- Report bugs in the issue tracker
- Reach out on Discord to the maintainer
silical
- Join the Discord Server