-
Notifications
You must be signed in to change notification settings - Fork 2
Getting Started
Ready to build your first script with the WarEra Python Client? This guide will walk you through the absolute basics.
Install the library using pip:
pip install warera-clientWhile you can use the library anonymously, you will be heavily rate-limited. It is highly recommended to get an API key from the WarEra settings page.
You can set your API key by passing it to set_api_key():
import warera
warera.set_api_key("YOUR_API_KEY_HERE")Alternatively, you can just set the WARERA_API_KEY environment variable in your terminal, and the library will detect it automatically!
Let's write a simple script to fetch a specific country's data and print its name and treasury balance.
import asyncio
import warera
async def main():
# Fetch country ID '7'
country = await warera.country.get_by_id("7")
print(f"Welcome to {country.name}!")
# We can access nested fields safely!
if country.taxes:
print(f"Income Tax: {country.taxes.income}%")
if __name__ == "__main__":
asyncio.run(main())One of the best features of this library is how it handles multiple requests.
If you want to fetch 5 different users, you don't need to manually combine them into a single payload. Just use .get_many():
import asyncio
import warera
async def main():
# Pass a list of IDs to get_many()
user_ids = ["1", "2", "3", "4", "5"]
# The library will automatically bundle these into a SINGLE network request!
users = await warera.user.get_many(user_ids)
for user in users:
print(f"{user.name} is level {user.leveling.level}")
if __name__ == "__main__":
asyncio.run(main())Many endpoints in WarEra return cursor-paginated data (like lists of articles, battle logs, or users).
The library handles pagination tokens for you automatically via the auto_items=True parameter. This turns the response into an asynchronous generator that you can easily loop over!
import asyncio
import warera
async def main():
print("Fetching all users in country 7...")
# auto_items=True abstracts away the pagination logic!
async for user in await warera.user.get_by_country("7", auto_items=True):
print(user.name)
if __name__ == "__main__":
asyncio.run(main())If you need to fetch millions of records (like transaction logs or battle rankings), simple pagination is too slow.
The collect_all() engine solves this by dividing the timeline into chunks and fetching them all concurrently:
import asyncio
import warera
async def main():
print("Downloading massive transaction history concurrently...")
# This will fire 500 concurrent network requests!
transactions = await warera.transaction.collect_all(
oldest_date="2026-01-01T00:00:00Z",
concurrency=500
)
print(f"Downloaded {len(transactions)} transactions instantly.")
if __name__ == "__main__":
asyncio.run(main())Now that you know the basics, check out the Code Snippets page for quick copy-paste examples of common tasks, or explore the API Reference to see all the endpoints available!
- action_log
- alliance
- article
- battle
- battle_loot_summary
- battle_order
- battle_ranking
- company
- country
- donation
- election
- event
- game_config
- game_stat
- government
- inventory
- item_trading
- mercenary_contract_auction
- mu
- mu_member
- party
- ranking
- region
- round
- search
- tournament
- transaction
- upgrade
- user
- work
- work_offer
- worker