# Scrimmage Rewards
The low-code loyalty program maker.
This library is a part of the [Scrimmage Rewards Program](https://scrimmage.co)
that is providing a solution for loyalty programs and rewards.
Tutorial can be found at [Scrimmage Rewards Tutorial](https://scrimmage-rewards.readme.io/docs).
## Getting started
### Install
pip install scrimmage-sdk
### Configuration
```python
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
```python
from scrimmage_sdk import Scrimmage
# Configure Scrimmage...
token = Scrimmage.get_user_token("unique-user-id")
```
#### Track rewardable for a user
```python
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)
```python
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
```python
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.
```python
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](https://github.com/Scrimmage-co/python-sdk/tree/main/examples) folder for different use cases.
## Usage on other platforms
- Using `<iframe />`: [github.com/Scrimmage-co/scrimmage-rewards-iframe](https://github.com/Scrimmage-co/scrimmage-rewards-iframe)
- Using Android: [github.com/Scrimmage-co/scrimmage-rewards-android](https://github.com/Scrimmage-co/scrimmage-rewards-android)
- Using iOS: [github.com/Scrimmage-co/scrimmage-rewards-ios](https://github.com/Scrimmage-co/scrimmage-rewards-ios)
- Using Flutter: [github.com/Scrimmage-co/scrimmage-rewards-flutter](https://github.com/Scrimmage-co/scrimmage-rewards-flutter)
- Using NodeJS: [github.com/Scrimmage-co/rewards/backend-library](https://github.com/Scrimmage-co/rewards/backend-library)
- Using Ruby: [https://github.com/Scrimmage-co/ruby-sdk](https://https://github.com/Scrimmage-co/ruby-sdk)
- Using Java: [https://github.com/Scrimmage-co/java-sdk](https://https://github.com/Scrimmage-co/java-sdk)
- Using PHP: [https://github.com/Scrimmage-co/php-sdk](https://https://github.com/Scrimmage-co/php-sdk)
- Using Golang: [https://github.com/Scrimmage-co/golang-sdk](https://https://github.com/Scrimmage-co/golang-sdk)
## 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
```
2. Install dependencies
```
pip install -r requirements.txt
pip install pytest pytest-asyncio
```
2. Start your development - you can add tests in the tests folder
3. 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](https://opensource.org/licenses/MIT).
Raw data
{
"_id": null,
"home_page": "https://github.com/Scrimmage-co/python-sdk",
"name": "scrimmage-sdk",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "scrimmage, reward, rewards, loyalty, api, sdk, python",
"author": "Scrimmage Co <founders@scrimmage.co>",
"author_email": "founders@scrimmage.co",
"download_url": "https://files.pythonhosted.org/packages/01/95/0132cf09ff53228a0b86f66920db45c0900f6bcf20587ad213208a52b33f/scrimmage-sdk-1.1.0.tar.gz",
"platform": null,
"description": "# Scrimmage Rewards\r\n\r\nThe low-code loyalty program maker.\r\n\r\nThis library is a part of the [Scrimmage Rewards Program](https://scrimmage.co)\r\nthat is providing a solution for loyalty programs and rewards.\r\n\r\nTutorial can be found at [Scrimmage Rewards Tutorial](https://scrimmage-rewards.readme.io/docs).\r\n\r\n## Getting started\r\n\r\n### Install\r\n pip install scrimmage-sdk\r\n\r\n### Configuration\r\n```python\r\nfrom scrimmage_sdk import Scrimmage\r\n\r\n# Configure Scrimmage:\r\nScrimmage.init_rewarder(\r\n api_server_endpoint=\"YOUR_SCRIMMAGE_API_SERVER_ENDPOINT\", # your api server endpoint\r\n private_key=\"YOUR_SCRIMMAGE_PRIVATE_KEY\", # your private key\r\n namespace=\"YOUR_SCRIMMAGE_NAMESPACE\", # environment, e.g. staging or production\r\n)\r\n```\r\n\r\n### Usage\r\n\r\n#### Get user token\r\n```python\r\nfrom scrimmage_sdk import Scrimmage\r\n\r\n# Configure Scrimmage...\r\n\r\ntoken = Scrimmage.get_user_token(\"unique-user-id\")\r\n```\r\n\r\n#### Track rewardable for a user\r\n```python\r\nfrom scrimmage_sdk import Scrimmage\r\n\r\n# Configure Scrimmage...\r\n\r\nuser_id = 'nanachi'\r\ndata_type = 'helloWorld'\r\nrewards = [{\r\n 'amount': 10,\r\n 'currency': 'USD'\r\n}]\r\nresponse = Scrimmage.reward.track_rewardable(user_id, data_type, rewards=rewards)\r\n```\r\n\r\n#### Track rewardable for a user only once (with idempotency key)\r\n```python\r\nfrom scrimmage_sdk import Scrimmage\r\n\r\n# Configure Scrimmage...\r\n\r\nuser_id = 'nanachi'\r\ndata_type = 'helloWorld'\r\nidempotency_key = 'idempotency_key_12345'\r\nreward = {\r\n 'amount': 10,\r\n 'currency': 'USD'\r\n}\r\nresponse = Scrimmage.reward.track_rewardable_once(user_id, data_type, idempotency_key, reward=reward)\r\n\r\n```\r\n\r\n#### Using multiple Scrimmage instances at once\r\n```python\r\nfrom scrimmage_sdk import Scrimmage\r\n\r\n# Using multiple Scrimmage instances at once\r\n\r\n# Instance 1\r\nscrimmage1 = Scrimmage.create_rewarder(\r\n api_server_endpoint=os.getenv('SCRIMMAGE_API_SERVER_ENDPOINT_1'),\r\n private_key=os.getenv('SCRIMMAGE_PRIVATE_KEY_1'),\r\n namespace=os.getenv('SCRIMMAGE_NAMESPACE_1'),\r\n)\r\nscrimmage1.user.get_user_token(...)\r\nscrimmage1.reward.track_rewardable(...)\r\n\r\n\r\n# Instance 2\r\nscrimmage2 = Scrimmage.create_rewarder(\r\n api_server_endpoint=os.getenv('SCRIMMAGE_API_SERVER_ENDPOINT_2'),\r\n private_key=os.getenv('SCRIMMAGE_PRIVATE_KEY_2'),\r\n namespace=os.getenv('SCRIMMAGE_NAMESPACE_2'),\r\n)\r\nscrimmage2.user.get_user_token(...)\r\nscrimmage2.reward.track_rewardable(...)\r\n```\r\n\r\n### Async Usage\r\nTo use the SDK in an async environment, you can append _async to the functions to use the async version of the function.\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom scrimmage_sdk import Scrimmage\r\n\r\n# Configure Scrimmage\r\nScrimmage.init_rewarder(\r\n api_server_endpoint=\"YOUR_SCRIMMAGE_API_SERVER_ENDPOINT\",\r\n private_key=\"YOUR_SCRIMMAGE_PRIVATE_KEY\",\r\n namespace=\"YOUR_SCRIMMAGE_NAMESPACE\",\r\n)\r\n\r\n# Async usage\r\nasync def main():\r\n token = await Scrimmage.get_user_token_async(\"unique-user-id\")\r\n print(token)\r\n\r\n user_id = 'nanachi'\r\n data_type = 'helloWorld'\r\n rewards = [{\r\n 'amount': 10,\r\n 'currency': 'USD'\r\n }]\r\n response = await Scrimmage.reward.track_rewardable_async(user_id, data_type, rewards=rewards)\r\n print(response)\r\n\r\n user_id = 'nanachi'\r\n data_type = 'helloWorld'\r\n idempotency_key = 'idempotency_key_12345'\r\n reward = {\r\n 'amount': 10,\r\n 'currency': 'USD'\r\n }\r\n response = await Scrimmage.reward.track_rewardable_once_async(user_id, data_type, idempotency_key, reward=reward)\r\n print(response)\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n\r\n### Examples\r\nSee the [examples](https://github.com/Scrimmage-co/python-sdk/tree/main/examples) folder for different use cases.\r\n\r\n\r\n## Usage on other platforms\r\n\r\n- Using `<iframe />`: [github.com/Scrimmage-co/scrimmage-rewards-iframe](https://github.com/Scrimmage-co/scrimmage-rewards-iframe)\r\n- Using Android: [github.com/Scrimmage-co/scrimmage-rewards-android](https://github.com/Scrimmage-co/scrimmage-rewards-android)\r\n- Using iOS: [github.com/Scrimmage-co/scrimmage-rewards-ios](https://github.com/Scrimmage-co/scrimmage-rewards-ios)\r\n- Using Flutter: [github.com/Scrimmage-co/scrimmage-rewards-flutter](https://github.com/Scrimmage-co/scrimmage-rewards-flutter)\r\n- Using NodeJS: [github.com/Scrimmage-co/rewards/backend-library](https://github.com/Scrimmage-co/rewards/backend-library)\r\n- Using Ruby: [https://github.com/Scrimmage-co/ruby-sdk](https://https://github.com/Scrimmage-co/ruby-sdk)\r\n- Using Java: [https://github.com/Scrimmage-co/java-sdk](https://https://github.com/Scrimmage-co/java-sdk)\r\n- Using PHP: [https://github.com/Scrimmage-co/php-sdk](https://https://github.com/Scrimmage-co/php-sdk)\r\n- Using Golang: [https://github.com/Scrimmage-co/golang-sdk](https://https://github.com/Scrimmage-co/golang-sdk)\r\n\r\n## Development\r\n1. Add .env.test to your environment with the following variables\r\n```\r\nSCRIMMAGE_API_SERVER_ENDPOINT=SCRIMMAGE_API_SERVER_ENDPOINT\r\nSCRIMMAGE_PRIVATE_KEY=YOUR_SCRIMMAGE_PRIVATE_KEY\r\nSCRIMMAGE_NAMESPACE=YOUR_SCRIMMAGE_NAMESPACE\r\n```\r\n\r\n2. Install dependencies\r\n```\r\npip install -r requirements.txt\r\npip install pytest pytest-asyncio\r\n```\r\n\r\n2. Start your development - you can add tests in the tests folder\r\n\r\n3. Run tests using pytest from the root directory\r\n```\r\npytest\r\n```\r\n\r\n## Contributing\r\n\r\nBug reports and pull requests are welcome on GitHub at https://github.com/Scrimmage-co/python-sdk.\r\n\r\n## License\r\n\r\nThe SDK is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple rewards for your app or website",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/Scrimmage-co/python-sdk"
},
"split_keywords": [
"scrimmage",
" reward",
" rewards",
" loyalty",
" api",
" sdk",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c72d0e0b6e9886d52c1d777047cf0541b49a620ed71a2024979c0df5a4d3280d",
"md5": "b561108b1dbb524fe837f2ba11124fc4",
"sha256": "14346d382f90fd8ff9b7719d362adfe642f8c865b4418f64cbf1cca592a6b7c3"
},
"downloads": -1,
"filename": "scrimmage_sdk-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b561108b1dbb524fe837f2ba11124fc4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 13840,
"upload_time": "2024-06-28T15:42:36",
"upload_time_iso_8601": "2024-06-28T15:42:36.519785Z",
"url": "https://files.pythonhosted.org/packages/c7/2d/0e0b6e9886d52c1d777047cf0541b49a620ed71a2024979c0df5a4d3280d/scrimmage_sdk-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "01950132cf09ff53228a0b86f66920db45c0900f6bcf20587ad213208a52b33f",
"md5": "8527910613d94aa69e2f59f85c2b32db",
"sha256": "d304904e0df2c4f96efccfd9e49ff4b115fe4999c93c029e4dd7fa318b49830b"
},
"downloads": -1,
"filename": "scrimmage-sdk-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "8527910613d94aa69e2f59f85c2b32db",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 10944,
"upload_time": "2024-06-28T15:42:38",
"upload_time_iso_8601": "2024-06-28T15:42:38.047981Z",
"url": "https://files.pythonhosted.org/packages/01/95/0132cf09ff53228a0b86f66920db45c0900f6bcf20587ad213208a52b33f/scrimmage-sdk-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-28 15:42:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Scrimmage-co",
"github_project": "python-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "dependency-injector",
"specs": []
},
{
"name": "httpx",
"specs": []
},
{
"name": "pydantic",
"specs": []
}
],
"lcname": "scrimmage-sdk"
}