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
- Using
<iframe />
: github.com/Scrimmage-co/scrimmage-rewards-iframe - Using Android: github.com/Scrimmage-co/scrimmage-rewards-android
- Using iOS: github.com/Scrimmage-co/scrimmage-rewards-ios
- Using Flutter: github.com/Scrimmage-co/scrimmage-rewards-flutter
- Using NodeJS: github.com/Scrimmage-co/rewards/backend-library
- Using Ruby: https://github.com/Scrimmage-co/ruby-sdk
- Using Java: https://github.com/Scrimmage-co/java-sdk
- Using PHP: https://github.com/Scrimmage-co/php-sdk
- Using Golang: https://github.com/Scrimmage-co/golang-sdk
Development
- 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
- Install dependencies
pip install -r requirements.txt
pip install pytest pytest-asyncio
-
Start your development - you can add tests in the tests folder
-
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
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d304904e0df2c4f96efccfd9e49ff4b115fe4999c93c029e4dd7fa318b49830b |
|
MD5 | 8527910613d94aa69e2f59f85c2b32db |
|
BLAKE2b-256 | 01950132cf09ff53228a0b86f66920db45c0900f6bcf20587ad213208a52b33f |
File details
Details for the file scrimmage_sdk-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: scrimmage_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14346d382f90fd8ff9b7719d362adfe642f8c865b4418f64cbf1cca592a6b7c3 |
|
MD5 | b561108b1dbb524fe837f2ba11124fc4 |
|
BLAKE2b-256 | c72d0e0b6e9886d52c1d777047cf0541b49a620ed71a2024979c0df5a4d3280d |