Skip to main content

Simple rewards for your app or website

Project description

Scrimmage Rewards

The low-code loyalty program maker.

This library is a part of the Scrimmage Rewards Program that is providing a solution for loyalty programs and rewards.

Tutorial can be found at Scrimmage Rewards Tutorial.

Getting started

Install

pip install scrimmage-sdk

Configuration

from scrimmage_sdk import Scrimmage

# Configure Scrimmage:
Scrimmage.init_rewarder(
    api_server_endpoint="YOUR_SCRIMMAGE_API_SERVER_ENDPOINT", # your api server endpoint
    private_key="YOUR_SCRIMMAGE_PRIVATE_KEY", # your private key
    namespace="YOUR_SCRIMMAGE_NAMESPACE", # environment, e.g. staging or production
)

Usage

Get user token

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

token = Scrimmage.get_user_token("unique-user-id")

Track rewardable for a user

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

user_id = 'nanachi'
data_type = 'helloWorld'
rewards = [{
    'amount': 10,
    'currency': 'USD'
}]
response = Scrimmage.reward.track_rewardable(user_id, data_type, rewards=rewards)

Track rewardable for a user only once (with idempotency key)

from scrimmage_sdk import Scrimmage

# Configure Scrimmage...

user_id = 'nanachi'
data_type = 'helloWorld'
idempotency_key = 'idempotency_key_12345'
reward = {
    'amount': 10,
    'currency': 'USD'
}
response = Scrimmage.reward.track_rewardable_once(user_id, data_type, idempotency_key, reward=reward)

Using multiple Scrimmage instances at once

from scrimmage_sdk import Scrimmage

# Using multiple Scrimmage instances at once

# Instance 1
scrimmage1 = Scrimmage.create_rewarder(
    api_server_endpoint=os.getenv('SCRIMMAGE_API_SERVER_ENDPOINT_1'),
    private_key=os.getenv('SCRIMMAGE_PRIVATE_KEY_1'),
    namespace=os.getenv('SCRIMMAGE_NAMESPACE_1'),
)
scrimmage1.user.get_user_token(...)
scrimmage1.reward.track_rewardable(...)


# Instance 2
scrimmage2 = Scrimmage.create_rewarder(
    api_server_endpoint=os.getenv('SCRIMMAGE_API_SERVER_ENDPOINT_2'),
    private_key=os.getenv('SCRIMMAGE_PRIVATE_KEY_2'),
    namespace=os.getenv('SCRIMMAGE_NAMESPACE_2'),
)
scrimmage2.user.get_user_token(...)
scrimmage2.reward.track_rewardable(...)

Async Usage

To use the SDK in an async environment, you can append _async to the functions to use the async version of the function.

import asyncio

from scrimmage_sdk import Scrimmage

# Configure Scrimmage
Scrimmage.init_rewarder(
    api_server_endpoint="YOUR_SCRIMMAGE_API_SERVER_ENDPOINT",
    private_key="YOUR_SCRIMMAGE_PRIVATE_KEY",
    namespace="YOUR_SCRIMMAGE_NAMESPACE",
)

# Async usage
async def main():
    token = await Scrimmage.get_user_token_async("unique-user-id")
    print(token)

    user_id = 'nanachi'
    data_type = 'helloWorld'
    rewards = [{
        'amount': 10,
        'currency': 'USD'
    }]
    response = await Scrimmage.reward.track_rewardable_async(user_id, data_type, rewards=rewards)
    print(response)

    user_id = 'nanachi'
    data_type = 'helloWorld'
    idempotency_key = 'idempotency_key_12345'
    reward = {
        'amount': 10,
        'currency': 'USD'
    }
    response = await Scrimmage.reward.track_rewardable_once_async(user_id, data_type, idempotency_key, reward=reward)
    print(response)

asyncio.run(main())

Examples

See the examples folder for different use cases.

Usage on other platforms

Development

  1. Add .env.test to your environment with the following variables
SCRIMMAGE_API_SERVER_ENDPOINT=SCRIMMAGE_API_SERVER_ENDPOINT
SCRIMMAGE_PRIVATE_KEY=YOUR_SCRIMMAGE_PRIVATE_KEY
SCRIMMAGE_NAMESPACE=YOUR_SCRIMMAGE_NAMESPACE
  1. Install dependencies
pip install -r requirements.txt
pip install pytest pytest-asyncio
  1. Start your development - you can add tests in the tests folder

  2. Run tests using pytest from the root directory

pytest

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Scrimmage-co/python-sdk.

License

The SDK is available as open source under the terms of the MIT License.

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

scrimmage-sdk-1.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

scrimmage_sdk-1.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file scrimmage-sdk-1.1.0.tar.gz.

File metadata

  • Download URL: scrimmage-sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for scrimmage-sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d304904e0df2c4f96efccfd9e49ff4b115fe4999c93c029e4dd7fa318b49830b
MD5 8527910613d94aa69e2f59f85c2b32db
BLAKE2b-256 01950132cf09ff53228a0b86f66920db45c0900f6bcf20587ad213208a52b33f

See more details on using hashes here.

File details

Details for the file scrimmage_sdk-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for scrimmage_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14346d382f90fd8ff9b7719d362adfe642f8c865b4418f64cbf1cca592a6b7c3
MD5 b561108b1dbb524fe837f2ba11124fc4
BLAKE2b-256 c72d0e0b6e9886d52c1d777047cf0541b49a620ed71a2024979c0df5a4d3280d

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