Package: wallet-sdk-Noah-Huppert
PyPiWallet Python SDKPython interface for a wallet service.Table Of ContentsOverviewWallet ClientRequest CredentialsDevelopmentOperationsOverviewWallet service Python 3 SDK.Firstfollow the instructions to request wallet service credentials.Next install thewallet-sdk-Noah-Huppertpip package and import thewallet_sdkmodule. Then use theWalletClientclass to interact with the wallet service API.# Import wallet service Python SDKimportwallet_sdk# Initialize the clientc=wallet_sdk.WalletClient.LoadFromConfig("./your-authority-client-config.json")# Add / remove value and items from user's walletsc.create_entry(user_id='foobar123',amount=99,reason='returned a lot of cans')try:c.create_entry(user_id='bobcats9',amount=-5,reason='bought a soda',item={'name':'Soda Can'})exceptwallet_sdk.NotEnoughFundsErrorase:print("Sorry user 'bobcats9' cannot afford to buy soda right now")# Get wallet valuesall_wallets=c.get_wallets()print(all_wallets)# [{ 'user_id': 'foobar123', 'total': 99},#  { 'user_id': 'bobcats9', 'total': 595 }]c.get_wallets(user_ids=['foobar123'],authority_id=['xxyyzz'])# Get itemsall_inventory=c.get_inventory()print(all_inventory)# [{'entry_id': 'xxx',#   'authority_id': 'xxx',#   'user_id': 'xxx',#   'item': { 'name': 'xxx', 'used': False, 'data': 'xxx' } },#  { ... }]c.get_inventory(entry_ids=['1234'],user_ids=['foobar123'],authority_ids=['yyzzii'])# Mark items as used upc.use_item(entry_id='998877')Wallet ClientThe wallet service stores arbitrary transaction data. Certain trusted applications, named "authorities", can create entries to add or remove value from a user's wallet, and optionally add an item to a user's inventory.A user's wallet value and items they own are aggregated and returned by the wallet service server.This SDK allows you to act as an authority, and perform these actions.Create EntriesExamples# Add 1000 to user 1 's walletc.create_entry(user_id='1',amount=1000,reason='payday')# Remove 100 from user 1 's wallet and give them an item named Cool Shadestry:c.create_entry(user_id='1',amount=-100,reason='bought sunglasses',item={'name':'Cool Shades','data':'{ "internal_id": "001122" }'})exceptwallet_sdk.NotEnoughFundsErrorase:print("Sorry, user 1 does not have enough money to buy cool shades right now")OverviewAs an authority you can create an entry to modify a user's wallet and inventory.Create entries with thecreate_entrymethod. Specify entry parameters via the arguments:user_id(str)amount(int)reason(str)item(object, optional)name(str)data(anything)SeeData Types - Entryfor descriptions of fields.ExceptionsNotEnoughFundsError: Raised when the API determines that the user cannot afford to back a transactionReturn ValueThecreate_entrymethod returns the newly created entry. SeeData Types - Entry.Query WalletsExamples# Get all walletsall_wallets=c.get_wallets()print(all_wallets)# [{'user_id': '1', 'total': 900},#  { ... },#  {'user_id': '60', 'total': 6000}]# Find wallets of only users 0 and 2wallets_0_and_2=c.get_wallets(user_ids=['0','2'])print(wallets_0_and_2)# [{'user_id': '0', 'total': 10},#  {'user_id': '2', 'total': 97000}]# Find wallets but only take into account entries we've mademy_transactions=c.get_wallets(authority_ids=['<your authority id>'])print(my_transactions)# [{'user_id': '1', 'total': 900},#  {'user_id': '34', 'total': 150000},#  {'user_id': '41', 'total': 700}]OverviewEntries are totaled for each user and can be retrieved using theget_walletsmethod.Queries can narrowed to only retrieve certain users by providing an array of their IDs via theuser_idsargument.Wallet totals can be limited to entries which only specific authorities created. This will omit entries not created by the specified authorities in the total value calculations. To do so provide an array of authorities IDs via theauthority_idsargument.These arguments can both be provided.Return ValueTheget_walletsmethod returns an array ofData Type - Wallet Totalobjects.Query InventoryExamples# Get all user inventory itemsall_inventory=c.get_inventory()print(all_inventory)# [{'entry_id': 'xxx',#   'authority_id': 'xxx',#   'user_id': 'xxx',#   'item': { 'name': 'xxx', 'used': False, 'data': 'xxx' } },#  { ... }]# Filter inventory by entry IDsc.get_inventory(entry_ids=['abc00','xyz99'])# Filter inventory by user IDsc.get_inventory(user_ids=['0','30'])# Filter inventory by authority IDsc.get_inventory(authority_ids=['xxx','zzz'])# Find inventory which has been usedc.get_inventory(used=True)# Do not filter by usedc.get_inventory(used=None)OverviewUser inventory items can be retrieved using theget_inventorymethod.The results can be filtered by entry ID, user ID, and authority ID via theentry_ids,user_ids,authority_idsarguments respectively.Results can also be filtered based off of if they are marked as used by providing theusedargument. By default only unused items are returned. SetTrueto find used items, and toNonein order to disable filtering based on used status.These arguments may be provided together.Return ValueTheget_inventorymethod returns an array ofData Type - Entry Itemobjects.Mark Item As UsedExample# Mark item from entry xyz012 as usedc.use_item(entry_id='xyz012')OverviewTo mark an item as used call theuse_itemmethod.The ID of the entry in which the item was created is used to specify the item.Return ValueTheuse_itemmethod returns theData Type - Entrywhich was modified.Ensure wallet service is operationalExampletry:c.check_service_health()exceptwallet_sdk.WalletAPIErrorase:print("Failed to ensure wallet service is running:",e)sys.exit(1)OverviewIf you would like to create a circuit breaker in your code and determine if the wallet service is running use thecheck_service_healthmethod.Return ValueThecheck_service_healthmethod returns aboolindicating if the wallet service server can be used. Awallet_sdk.WalletAPIErrorexception may be raised if the SDK fails to communicate with the wallet service server.Data TypesEntryA transaction entry.entry_id(str): Unique ID of entryauthority_id(str): ID of authority which created entryuser_id(str): ID of user for which entry pertainscreated_on(int): Unix timestamp of when entry was createdamount(int): Amount added (positive) or removed (negative) from the user's walletreason(str): User friendly description of why this transaction occurreditem(object, optional): Item given to user in this transactionname(str): User friendly name of itemused(bool): If item has been used updata(object, optional): Any arbitrary data which the creating authority would like to store for this itemWallet TotalDescribes the current value of a wallet.user_id(str): ID of user who owns wallettotal(int): Total amount of money in user's walletEntry ItemAn item a user owns from a transaction.entry_id(str): ID of the entry in which this item was given to the user, this is used as the unique ID for this itemauthority_id(str): ID of authority who gave the user the itemuser_id(str): ID of the user who owns the itemitem(object): Owned itemname(str): User friendly name of itemused(bool): If the item has been used updata(object, optional): Arbitrary data which the creating authority specifiedRequest CredentialsThe wallet service Python SDK is a generic interface to any wallet service.
There is no single wallet service. Instead this repository provides the
source code required for someone to host their own wallet service.To obtain credentials you must contact the administrator of the wallet service
with which you wish to interact. Ask them for an "authority client configuration
file". If they agree to give you access the administrator should provide you
with a JSON file.This file is secret, it authenticates you with the wallet
service, !!!and should never be made public!!!.Then simply provide theWalletClient.LoadFromConfig()function a path to
this file.DevelopmentA virtual environment is provided for development purposes.InstallPipenv, the official Python virtual
environment manager.Then install dependencies:pipenv installFinally activate the environment:pipenv shellOperationsRelease PyPi PackageThis section documents how thewallet-sdk-Noah-Huppertpip package
is generated.First activate the development python virtual environment:pipenv shellUpdate the versionPick newsemantic version. Change major if not
backwards compatible changes, minor for new backwards compatible features,
and patch for new backwards compatible bug fixes.Edit the version inwallet_sdk/VERSION.Ensure the API compatible versionCOMPATIBLE_API_VERSIONis correct.Updatethe compatibility matrix in the generalREADME.md.Merge code into themasterbranch.Publish to test pipmake clean
make publishInspect package page to ensure everything looks good.Tag the currentmasteraspy-sdk-v<version>.Create a new GitHub release namedPython SDK v<version>.Include a short one or two sentence summary of the changesInclude an h1 "Change log" section: list detailed changesPublish to pip:make clean
make publish PIP_REPO=pypi