Access
Connect cross-platform accounts & identity management
You can use AccelByte Cloud’s Python SDK to implement our backend services within your game. The SDK acts as a bridge between your game and our services. This guide will show you how to create an application that uses Python Server SDK from scratch.
AB_BASE_URL
environment variable.Confidential
.Client ID
value for AB_CLIENT_ID
environment variable.Client Secret
value for AB_CLIENT_SECRET
environment variable.Create a folder and use venv
to create a Python virtual environment.
Install SDK dependencies.
$ pip install requests httpx websockets pyyaml
Install the SDK.
$ pip install git+https://github.com/AccelByte/accelbyte-python-sdk.git@{VERSION}#egg=accelbyte_py_sdk
TIP
We recommended using the Python Server SDK version that matches your AccelByte Cloud version.
Create an SDK instance, log in using client credentials, and call an AccelByte Cloud API in app.py
.
The EnvironmentConfigRepository
gets its values from AB_BASE_URL
, AB_CLIENT_ID
, and AB_CLIENT_SECRET
environment variables.
# app.py
import accelbyte_py_sdk
from accelbyte_py_sdk.core import (
RequestsHttpClient,
EnvironmentConfigRepository,
InMemoryTokenRepository,
)
import accelbyte_py_sdk.services.auth as auth_service
import accelbyte_py_sdk.api.iam as iam_service
def main():
# Create default HTTP client, token repository, and config repository instances
http_client = RequestsHttpClient()
config_repository = EnvironmentConfigRepository()
token_repository = InMemoryTokenRepository()
# Initialize the SDK
accelbyte_py_sdk.initialize(
options={
"config": config_repository,
"token": token_repository,
"http": http_client,
}
)
# Login using client credentials
token, error = auth_service.login_client()
if error:
exit(1) # Login failed
# Call an AccelByte Cloud API e.g. GetCountryLocationV3
response, error = iam_service.get_country_location_v3()
if error:
exit(1) # Response error
print(response.country_name)
if __name__ == "__main__":
main()
Set the required environment variables and run the code using the Python interpreter.
$ export AB_BASE_URL="https://demo.accelbyte.io" # AccelByte Cloud Base URL e.g. demo environment
$ export AB_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # AccelByte Cloud OAuth Client ID
$ export AB_CLIENT_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # AccelByte Cloud OAuth Client Secret
$ python app.py
Now you can start using any of the following AccelByte services in your application, by importing the following syntax to your code. See the model for each service below or in the integration test (opens new window) folder inside the accelbyte-python-sdk (opens new window) repository.
Now you can start using any of the following AccelByte Cloud services in your application, by importing the following syntax to your code. See the model for each service below or in the integration test (opens new window) folder inside the accelbyte-python-sdk (opens new window) repository.
SDK reference (opens new window)
from accel_py_sdk.api.iam import *
from accelbyte_py_sdk.services.auth import *