Skip to main content

Earn Alliance python SDK

Project description

Earn Alliance

Official Earn Alliance SDKs for Python

Links

  • Discord
  • Twitter Follow

Contents

Supported Platforms

Any platform capable of running python3

Prerequisites

  • python 3.11+

Installation and Usage

To install a SDK, simply run the build command

python3 -m pip install .

To build a ready-to-publish distribution, simply run the build command (ensure build command is available for your environment)

python3 -m build

To run tests - simply run (ensure pytest is available for your environment)

./run_test.sh

Initialize

Setup client so it can start sending events!

alliance = sdk.init(
    options.NodeOptions(
        clientId="[clientId]",
        clientSecret="[clientSecret]",
        gameId="[gameId]",
        dsn="[dsn]",
        ...
    )
)

The client configuration can also be read from environment variables if not provided as an option.

# If the client id, secret, game id and dsn are not specific, the init
# function will by default look for the environment variables
# `ALLIANCE_CLIENT_ID`, `ALLIANCE_CLIENT_SECRET`, `ALLIANCE_GAME_ID` and
# `ALLIANCE_DSN`.
alliance = sdk.init()

Set User Identifiers

Whenever a new user identifier is set, or a new user is registered, you can add or update the identifiers associated with the internal user id.

This is used to tell us the user has installed the app and enrich information when more game platform accounts or social accounts are added to help us map the user to the game events.

# This shows all of our currently supported platforms, but you only need to
# provide the identifiers that are relevant for your game.
properties = IdentifyingProperties(email="test@test.com", discordId="123456")
await alliance.set_user_identifiers("1234", properties)

Note that if you pass any falsey value identifier to set_user_identifiers, it will be ignored. This is the avoid unintentionally removing previously set identifiers. If you want to remove previously set identifiers, use the remove_identifiers function.

from model.identifier_prop_names import IdentifierPropNames as ipn
await alliance.remove_identifiers(identifier, ipn.DISCORD_ID, ipn.EMAIL)

Track User Start Session

Sends standard TRACK event for launching a game. This let's us know that the user has the game launched and is ready to start a challenge.

alliance.start_game("[internal user id]")

Track Events

Tracking events that happens in a game. Tracked events are batched together and sent after 30 seconds interval, or when a batch size of 100 events have accumulated, whichever comes first. Both the interval and the batch size are configurable in the client options.

The name of the events can be almost anything, but we recommend sticking to common terms as shown in the following examples.

# An event without any specific value, commonly used for counting event
# instances, i.e. "Kill X Zombies".
await alliance.track("[internal user id]", "KILL_ZOMBIE")

# An event with an associated value, commonly used for accumulating or
# checking min / max values, i.e. "Score a total of X" or "Achieve a
# highscore of at least X".
await alliance.track_with_value("[internal user id]", "SCORE", 100)

# The client can track events for multiple users in parallel.
await alliance.track_with_value("[internal user id]", "DAMAGE_DONE", 500)
await alliance.track_with_value("[another user id]", "DAMAGE_TAKEN", 500)

# Additional traits can be added to the event, which can be used to
# create more detailed challenges, i.e. "Kill X monsters with a knife".
weaponTrait = {"weapon": "knife"}
mobTrait = {"mob": "zombie"}
await alliance.track_with_traits("[internal user id]", "KILL", weaponTrait, mobTrait)

Group Tracked Events

You can group events together, i.e. a game round or a match, whichever makes sense for your game. This allows for natural challenge scopes like "Kill X players in a match".

# Generates unique group id which will be associated with all the events
round = alliance.start_round("[group id]")
await round.track("[internal user id]", "KILL_ZOMBIE")

Flush event queue

For events that have higher priority (i.e. setUserIdentifiers), instead of initiating a scheduled batch, they trigger the use of an event queue flush. This means that as long as the client has not been flushed prior to the event, the event will be sent to the api right away.

Once the queue has been has been flushed, the client enters a 10 second cooldown period, during which any subsequent calls to flush, will wait for the cooldown to finish, before it's triggered. Not that any normal procedures, like the queue size reaches the batch limit, will still send the events to the api.

The flush function can also be called manually on the client instance, but it is still restricted by the same cooldown mechanic.

await alliance.flush();

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

earnalliance_python-1.0.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

earnalliance_python-1.0.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file earnalliance_python-1.0.1.tar.gz.

File metadata

  • Download URL: earnalliance_python-1.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for earnalliance_python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cb947374d104560bca6a35e677ca2e0a21930244b2e557b05bd2ad77f270e98e
MD5 e075b7e0f0afae67a967d063e271789a
BLAKE2b-256 5275c74fcbf3cd064b320a096b9eafaab419cfe6047ba452b1f015c538528368

See more details on using hashes here.

File details

Details for the file earnalliance_python-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for earnalliance_python-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf17df8e36b94f633c08f02fc9b416b0c7a2017f40816b7d5c0fe90f6cc67f14
MD5 94d5614c3003c0f61d611682a8f0b7e2
BLAKE2b-256 67c7045f86f70bc895c17a31a56b13624519b7fead99563b06d7bf6f9a707d3c

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