Skip to main content

Arknights python wrapper.

Project description

ArkPRTS

Arknights python wrapper.

Interacts directly with the game servers, no delays.

支持中文和 B 站账户!


Source Code: https://github.com/thesadru/arkprts


Installation

pip install -U arkprts

There may be some optional requirements, you can install them all with all.

pip install -U arkprts[all]

Usage

import arkprts

async def main() -> None:
    client = arkprts.Client()

    # search users by nickname
    users = await client.search_players("Doctor", server="en")
    print("User level: ", users[0].level)


    # =======

    # login with email or token
    auth = arkprts.YostarAuth("en")
    await auth.login_with_email_code("doctor@gmail.com")
    # or auth.login_with_token("123456", "abcdefg")
    client = arkprts.Client(auth=auth)

    # get logged-in user data
    data = await client.get_data()
    print("Level: ", data.status.level)

Returned data is in the form of pydantic models, however you can also request raw json with client.get_raw_player_info()/client.get_raw_data()/... to access even untyped data.

For convenience, static game data is automatically downloaded and updated on login. You can access the static data directly or through the models. This is useful for getting names and descriptions of objects.

users = await client.search_user("UserName")
operator = users[0].assist_char_list[0]  # type: arkprts.models.Character
print(f"Assist operator {operator.static.name} is level {operator.level}")

To disable downloading static data use arkprts.Client(gamedata=False). To choose the data download location set client.gamedata = akprts.GameData("/path/to/data").

ArkPRTS supports en, jp, kr, cn and bili servers. However only global/yostar servers (en, jp and kr) can be used without logging in.

Frequent usage cases

Get all of my operators.

data = await client.get_data()
for char in data.troop.chars.values():
    print(char.char_id)

Get my inventory.

data = await client.get_data()
# normal inventory items
for item_id, count in user.inventory.items():
    if count > 0:
        print(item_id, count)
# basic items like originium or green certificates
for item_id, count in user.status.basic_item_inventory.items():
    if count > 0:
        print(item_id, count)
# consumable expirable items
for item_id, subitems in user.consumable.items():
    for item in subitems.values():
        if count > 0:
            print(item_id, item.ts, item.count)

Logging in with email and password to the cn server.

auth = arkprts.HypergryphAuth()
await auth.login("doctor@qq.com", "wordpass12")
client = arkprts.Client(auth=auth)

await client.get_data()

Making a new client when a global guest client already exists; without excess overhead.

public_client = arkprts.Client()

# ----
auth = arkprts.YostarAuth("en", network=public_client.network)
await auth.login_with_token("123456", "abcdefg")
private_client = arkprts.Client(auth=auth, gamedata=public_client.gamedata)

Programmatically getting auth tokens from a user on your website.

@route("/code")
def code(request):
    auth = arkprts.YostarAuth(request.query["server"], network=...)
    await auth.get_token_from_email_code(request.query["email"])

    return "Code sent!"


@route("/login")
def login(request):
    auth = arkprts.YostarAuth(request.query["server"], network=...)
    channel_uid, yostar_token = await auth.get_token_from_email_code(request.query["email"], request.query["code"])

    return {"channel_uid": channel_uid, "yostar_token": yostar_token}

Contributing

Any kind of contribution is welcome. Please read CONTRIBUTING.md for more information.

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

arkprts-0.2.2.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

arkprts-0.2.2-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file arkprts-0.2.2.tar.gz.

File metadata

  • Download URL: arkprts-0.2.2.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for arkprts-0.2.2.tar.gz
Algorithm Hash digest
SHA256 47190a21c7e93ee9c5b3e37c97544fb6ae714dbcc28d4ecbc74bc3929057af9b
MD5 88566e39fcf02d9d44bedbe5aa7e3579
BLAKE2b-256 1728e3c861c0febd4fd94c156bb59fa024c3e75ac12b90f4a757088aba257685

See more details on using hashes here.

File details

Details for the file arkprts-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: arkprts-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for arkprts-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e526c197cb2c95b0c0a8fe2f91f865a3066db925dab4489e3ea0ec3288fb1eb8
MD5 f25bdc253acb795c716f03bc0dd6b2ff
BLAKE2b-256 a7b674c1b5740af98817f1b4641519396a64a935aba16079ca1cc9c7fd0db077

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page