Skip to main content

stalcraft api unofficial python library

Project description

stalcraft-api unofficial python library


Official API documentation: https://eapi.stalcraft.net

Before you can use the API, you must register your application and receive approval

For testing Demo API is available

more about applications


🔧 Install

Pip

pip install stalcraft-api --upgrade
Manual
git clone git@github.com:onejeuu/stalcraft-api.git
cd stalcraft-api
pip install -r requirements.txt

⚡ Quick Start

from stalcraft import AppClient

TOKEN = "YOUR_TOKEN"

client = AppClient(token=TOKEN)

📎 Usage Examples

App Client
from stalcraft import AppClient, Region, Sort, Order

CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"

TOKEN = "YOUR_TOKEN"

# Method 1:
client = AppClient(token=TOKEN)

# Method 2:
client = AppClient(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)

print()
print("List of regions")
print(client.regions())

print()
print("List of clans with limit 2")
print(client.clans(limit=2))

print()
print("Information about emission on NA server")
print(client.emission(Region.NA))

print()
print("List of lots for item with id '1r756'")
print("With offset 5, limit 2, sort by buyout price and order by descending")
print(client.auction("1r756").lots(offset=5, limit=2, sort=Sort.BUYOUT_PRICE, order=Order.DESC))

print()
print("List of price history for item with id '1r756'")
print(client.auction("1r756").price_history())

print()
print("Information about clan with id '562968e7-4282-4ac6-900f-f7f1581495e8'")
print(client.clan("562968e7-4282-4ac6-900f-f7f1581495e8").info())

User Client
from stalcraft import UserClient, BaseUrl, Region

TOKEN = "YOUR_TOKEN"

client = UserClient(token=TOKEN, base_url=BaseUrl.DEMO)

# + all methods from AppClient

print("List of characters created by the user on EU server by which used access token was provided")
print(client.characters(Region.EU))

print()
print("List of friends character names who are friend with 'Test-1'")
print(client.friends("Test-1"))


# Members in clan with id '562968e7-4282-4ac6-900f-f7f1581495e8'
# (Can be used only when using user access token and that user has at least one character in that clan)
# client.clan("562968e7-4282-4ac6-900f-f7f1581495e8").members()

#
# Information about player's profile. Includes alliance, profile description, last login time, stats, etc.
# (Not working in DEMO API)
# client.character_profile("ZIV")

Find Item ID by name
from stalcraft import AppClient, LocalItem, WebItem, ItemFolder

TOKEN = "YOUR_TOKEN"

client = AppClient(token=TOKEN)

print()
print("Search by local file")
print(client.auction(LocalItem("Snowflake")).lots())

print()
print("(Not reliable)")
print("Search by listing.json in stalcraft-database github repository")
print(client.auction(WebItem("Snowflake", folder=ItemFolder.GLOBAL)).lots())

Exceptions
from stalcraft import UserClient, LocalItem

from stalcraft.exceptions import (
    InvalidToken, StalcraftApiException, ItemException
)

TOKEN = "YOUR_TOKEN"

client = UserClient(token=TOKEN)

def handle_exception(func, exception):
    try:
        func()
    except exception as e:
        print("Error:", e)

print()
print("If token is invalid")
handle_exception(lambda: UserClient("test1234567890"), InvalidToken)

print()
print("If an item with that name does not exist")
handle_exception(lambda: LocalItem("test"), ItemException)

print()
print("If one of parameters is invalid")
handle_exception(lambda: client.auction("test").price_history(), StalcraftApiException)

🔑 About Tokens

Get User and App Token

CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"

auth = Authorization(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)

print()
print("Get App Token")
print(auth.get_app_token())

print()
print("Get User Code")
print(auth.get_user_code())

auth.input_code()

# or
# auth.code = "USER_CODE"

print()
print("Get User Token")
print(auth.get_user_token())

Refresh User Token

CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"

auth = Authorization(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)

REFRESH_TOKEN = "USER_REFRESH_TOKEN"

print()
print("Refresh User Token")
print(auth.update_token(REFRESH_TOKEN))

📋 Output Formats

from stalcraft import AppClient

# Optional
from rich import print

TOKEN = "YOUR_TOKEN"

client = AppClient(token=TOKEN)

print()
print("Object:")
print(client.emission())

# or client = AppClient(TOKEN, json=True)
client.json = True

print()
print("Json:")
print(client.emission())

Output:

Object:
Emission(
    current_start=None,
    previous_start=datetime.datetime(2023, 1, 30, 5, 16, 52, tzinfo=datetime.timezone.utc),
    previous_end=datetime.datetime(2023, 1, 30, 5, 21, 52, tzinfo=datetime.timezone.utc)
)

Json:
{
    'previousStart': '2023-01-30T05:16:52Z',
    'previousEnd': '2023-01-30T05:21:52Z'
}

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

stalcraft_api-0.2.5.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

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

stalcraft_api-0.2.5-py3-none-any.whl (55.3 kB view details)

Uploaded Python 3

File details

Details for the file stalcraft_api-0.2.5.tar.gz.

File metadata

  • Download URL: stalcraft_api-0.2.5.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for stalcraft_api-0.2.5.tar.gz
Algorithm Hash digest
SHA256 f33da8120452838f9271b59a91b4f2293cc15a3c89909470928bd5eec8d4cc00
MD5 d9238718c038eafab664d7d5b81592a2
BLAKE2b-256 e18bfed95a088d3b7e1c9d40314b78a7d9810098a8597656906f9c0cbc4bd246

See more details on using hashes here.

File details

Details for the file stalcraft_api-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: stalcraft_api-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 55.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for stalcraft_api-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bb6b7d3d25aed214d532cfce1c4e6058ad2d956768ceee7844dc4a2225fbd371
MD5 02d58297aabba89336234674859b8830
BLAKE2b-256 1197f112291001ed1ceca37627dfb5ce8d8c7d7e0c89d6376cb4a5ff85036551

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