Skip to main content

WarEra browser game API wrapper

Project description

This package is EXPERIMENTAL, NOT stable and NOT intended for use in anything other than your own private projects.

pywarera is a simple Python wrapper for the WarEra API. It provides high-level classes for working with game models and a low-level wareraapi module for making raw API requests.

API documentation is available at https://api2.warera.io/docs/.

License: GNU General Public License v3.0

Features

  • high-level classes to work with API models
  • ability to manually send API requests
  • caching (x5 - x20 less requests!)
  • batching
  • delays
  • exceptions

Supported models

  • 🟢 the wrapper can reliably reproduce this model from the get request

  • 🟡 the wrapper can reproduce most properties, but reliability has not been tested

  • 🔴 the wrapper is not yet able to work with this model, so you will have to process the response from the API yourself

  • 🟡company

  • 🟡country

  • 🔴event

  • 🟡government

  • 🟡region

  • 🔴battle

  • 🔴round

  • 🔴battleRanking

  • 🔴itemTrading

  • 🔴tradingOrder

  • 🔴workOffer

  • 🔴ranking

  • 🔴search

  • 🔴gameConfig

  • 🟡user

  • 🔴article

  • 🟡mu

  • 🔴transaction

  • 🔴upgrade

  • 🟡workers

  • 🟡party

How to install

Requires Python 3.10+

pip install pywarera

Examples

import pywarera

s = pywarera.WarEraSession(api_token="xxx")

# Returns country id
country_id = s.get_country_id_by_name("Ukraine")
print(country_id)

# I want to know if Ukraine has a president
government = s.get_government(country_id)

is_there_a_president = government.has_president()

if is_there_a_president:
    president_id = government.president
    print(president_id)

# Let's check the wealth of a random citizen
import random

romania_citizens = s.get_country_citizens_by_name("Romania")
random_citizen = random.choice(romania_citizens)
print(random_citizen.wealth)

Example of a manual API request

from pywarera import wareraapi

api_s = wareraapi.WarEraApiSession(api_token="xxx")

# Regular request, will be cached
user_response = wareraapi.user_get_user_lite(user_id="123456").execute(api_s)

# Batched request, will be cached
from pywarera.wareraapi import BatchSession

with BatchSession(api_s) as batch:
    batch.add(wareraapi.user_get_user_lite(user_id="123456"))
    batch.add(wareraapi.user_get_user_lite(user_id="7891011"))

print(batch.responses)

Functions

General

  • clear_cache()
  • update_api_token(new_api_token)

Region

  • get_region(region_id) -> returns instance of Region class

Items

  • get_items() -> access to resources and products
  • get_item(item_code)
  • get_trading_prices()
  • get_item_price(item_code)

User

  • get_user(user_id) -> returns instance of User class
  • get_users(user_ids) -> returns list with instances of User class
  • get_user_wage(user_id)

Government

  • get_government(country_id) -> returns instance of Government clas

Country

  • get_country(country_id) -> returns instance of Country class
  • get_all_countries(return_list: bool) -> returns dict with instances of Country object, where key is country's ID
  • get_country_id_by_name(country_name)
  • get_country_citizens_ids(country_id)
  • get_country_citizens(country_id) -> returns list with instances of User class
  • get_country_citizens_ids_by_name(country_name)
  • get_country_citizens_by_name(country_name) -> returns list with instances of User class

Company

  • get_user_company_ids(user_id)
  • get_users_company_ids(user_ids: list[str])
  • get_country_citizens_company_ids(country_id)
  • get_company(company_id) -> returns instance of Company class
  • get_companies(company_ids: list[str]) -> returns list with instances of Company class
  • get_country_citizens_companies(country_id) -> returns list with instances of Company class

MUs

  • get_military_unit(mu_id) -> returns instance of MilitaryUnit class
  • get_military_units_from_paginated(items: list) -> to work with mu.getManyPaginated request

Parties

  • get_party(party_id)
  • get_parties(party_ids)

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

pywarera-0.3.0.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

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

pywarera-0.3.0-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file pywarera-0.3.0.tar.gz.

File metadata

  • Download URL: pywarera-0.3.0.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pywarera-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7ee3abc4a0c4db85f599c68075c13405a24017774291e818b2c2817cf27b42e2
MD5 c88dd949c7b64847b4b7d849abaf63c4
BLAKE2b-256 c16da03237f6a5f8a4d8e08aa9bfb07416dcda16226307e8f77a4646e4d8420b

See more details on using hashes here.

File details

Details for the file pywarera-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pywarera-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pywarera-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 786f17d4456973192d789ecc132ec1635a3e13857ca40c04a2303cf72d5651d6
MD5 e90adf37361dd3ab4a5667c3b47fb17f
BLAKE2b-256 d0b3b282c9bb9f14bb806c4437ade0ce6b211480c488c9f0f0577d5312bcf93f

See more details on using hashes here.

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