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 -U
Manual
git clone git@github.com:onejeuu/stalcraft-api.git
cd stalcraft-api
poetry install

⚡ Quick Start

from stalcraft import AppClient, Region

# Only as example.
# Do not store your credentials in code.
TOKEN = "YOUR_TOKEN"

client = AppClient(token=TOKEN)

print(client.emission(Region.EU))
🐇 Asyncio
import asyncio
from stalcraft import Region
from stalcraft.asyncio import AsyncAppClient

TOKEN = "YOUR_TOKEN"

async def main():
    client = AsyncAppClient(token=TOKEN)

    print(await client.emission(Region.EU))

asyncio.run(main())

🚫 Exceptions

StalcraftApiException
├── InvalidToken
├── MissingCredentials
├── ApiRequestError
│   ├── RequestUnauthorised
│   ├── RequestInvalidParameter
│   ├── RequestNotFound
│   └── RateLimitReached
└── ItemIdError
    ├── ListingJsonNotFound
    └── ItemIdNotFound

🔑 Authorization

from stalcraft import AppAuth, UserAuth

# Only as example.
# Do not store your credentials in code.
CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"

app_auth = AppAuth(CLIENT_ID, CLIENT_SECRET)
user_auth = UserAuth(CLIENT_ID, CLIENT_SECRET)
Get App Token
print(app_auth.get_token())

Get User Token
print("Go to:", user_auth.code_url)

code = input("Enter code:")

print()
print(user_auth.get_token(code))

Refresh User Token
REFRESH_TOKEN = "REFRESH_TOKEN"

print(user_auth.refresh_token(REFRESH_TOKEN))

📋 Output Formats

from stalcraft import AppClient

TOKEN = "YOUR_TOKEN"

client = AppClient(token=TOKEN)

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

client = AppClient(TOKEN, json=True)

# or
# client.json = True

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

Output:

Pydantic Object:
Emission(
    current_start=None,
    previous_start=datetime.datetime(2023, 1, 30, 12, 0, 0, tzinfo=datetime.timezone.utc),
    previous_end=datetime.datetime(2023, 1, 30, 12, 5, 0, tzinfo=datetime.timezone.utc)
)

Json:
{
    'previousStart': '2023-01-30T12:00:00Z',
    'previousEnd': '2023-01-30T12:05:00Z'
}

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-1.1.1.tar.gz (62.2 kB view hashes)

Uploaded Source

Built Distribution

stalcraft_api-1.1.1-py3-none-any.whl (75.5 kB view hashes)

Uploaded Python 3

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