Skip to main content

Official Python API client for Nifty

Project description

Nifty-Client

Nifty Client is the official Python client for the nifty API. It does some heavy lifting to provide a simple and portable client. If you do find the client missing some features, please make a pull request or cut an issue.

Installation

Installing the client is simple with pip:

pip install niftyclient

Quickstart

After installing the client, get your api credentials from the nifty dashboard, configure the client with the credentials and you are good to go.

from niftyclient import NiftyWalletClient

class ExampleConfig:
    key_id = "f4664c39663272d70b7ebdc96ddac72e"
    secret = "4c198a69e108ce6f293734d4f0a511a0d1fd6bf70a26e9c2e5f147ff41615f9bf3b6349595aff7011ca28f806976715a"
    user_id = "15695297-f441-4b1c-a75b-831fbb1d1431"


client = NiftyWalletClient(ExampleConfig())

client.get_wallet()
# Response is wallet response with no wallet
# MutableDictionaryObject({'available_resultset_size': 0, 'tracking_uuid': UUID('89feedd2-2c51-11e7-bd4c-000c29e41bf4'), 'wallets': [] 'limit': 30, 'offset': 0, 'returned_resultset_size': 0})

client.create_wallet()
# wallet created.
# MutableDictionaryObject({'available_resultset_size': 1, 'tracking_uuid': UUID('89feedd2-2c51-11e7-bd4c-000c29e41bf4'), 'wallets': [DictionaryObject({'user_name': u'mike', 'created_at': datetime.datetime(2017, 4, 24, 23, 33, 52, 747695, tzinfo=tzoffset(None, 10800)), 'balance': Decimal('0.00'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'last_modified': datetime.datetime(2017, 4, 27, 21, 31, 15, 268358, tzinfo=tzoffset(None, 10800))})], 'limit': 30, 'offset': 0, 'returned_resultset_size': 1})
client.create_wallet()
# This operation is idempotent and will return the same result as above

client.get_wallet()
# MutableDictionaryObject({'available_resultset_size': 1, 'tracking_uuid': UUID('89feedd2-2c51-11e7-bd4c-000c29e41bf4'), 'wallets': [DictionaryObject({'user_name': u'mike', 'created_at': datetime.datetime(2017, 4, 24, 23, 33, 52, 747695, tzinfo=tzoffset(None, 10800)), 'balance': Decimal('0.00'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'last_modified': datetime.datetime(2017, 4, 27, 21, 31, 15, 268358, tzinfo=tzoffset(None, 10800))})], 'limit': 30, 'offset': 0, 'returned_resultset_size': 1})

# Consume token. This operation is not idempotent and is atomic.
client.consume_token(
    transaction_id="2TR46IBB5C", phone_number="254722123456", till_number=703648)
# MutableDictionaryObject({'transactions': [DictionaryObject({'till_number': u'703648', 'payment_id': UUID('d2c29c60-0b1a-11e7-8f7b-061cf2e0e94d'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'trans_amount': Decimal('799.23'), 'msisdn': u'254722123456', 'trans_time': datetime.datetime(2016, 5, 29, 21, 30, 52, 739072, tzinfo=tzoffset(None, 10800)), 'names': u'First M Last', 'trans_id': u'2TR46IBB5C'})], 'tracking_uuid': UUID('3582b27e-2c52-11e7-bd4c-000c29e41bf4'), 'available_resultset_size': 1, 'limit': 0, 'offset': 0, 'returned_resultset_size': 1})

# Operation should not succeed again
client.consume_token(
    transaction_id="2TR46IBB5C", phone_number="254722123456", till_number=703648)
# MutableDictionaryObject({'transactions': [], 'tracking_uuid': UUID('c63774da-2c52-11e7-bd4c-000c29e41bf4'), 'available_resultset_size': 0, 'limit': 0, 'offset': 0, 'returned_resultset_size': 0})

# Any incorrect field will not return a redemption transaction.
client.consume_token(
    transaction_id="2TR46IBB5C", phone_number="254716622446", till_number=703646)
# MutableDictionaryObject({'transactions': [], 'tracking_uuid': UUID('c63774da-2c52-11e7-bd4c-000c29e41bf4'), 'available_resultset_size': 0, 'limit': 0, 'offset': 0, 'returned_resultset_size': 0})

# Transactions list
client.transactions()
# MutableDictionaryObject({'transactions': [DictionaryObject({'till_number': u'703648', 'payment_id': UUID('d2c29c60-0b1a-11e7-8f7b-061cf2e0e94d'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'trans_amount': Decimal('799.23'), 'msisdn': u'254722123456', 'trans_time': datetime.datetime(2016, 5, 29, 21, 30, 52, 739072, tzinfo=tzoffset(None, 10800)), 'names': u'First M Last', 'trans_id': u'2TR46IBB5C'}), DictionaryObject({'till_number': u'703648', 'payment_id': UUID('d2c29c60-0b1a-11e7-8f7b-061cf2e0e94d'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'trans_amount': Decimal('581.37'), 'msisdn': u'254722123456', 'trans_time': datetime.datetime(2017, 1, 24, 21, 30, 52, 739243, tzinfo=tzoffset(None, 10800)), 'names': u'First M Last', 'trans_id': u'0OZC02Q1OZ'}), DictionaryObject({'till_number': u'703648', 'payment_id': UUID('d2c29c60-0b1a-11e7-8f7b-061cf2e0e94d'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'trans_amount': Decimal('657.56'), 'msisdn': u'254722123456', 'trans_time': datetime.datetime(2017, 1, 31, 21, 30, 52, 739409, tzinfo=tzoffset(None, 10800)), 'names': u'First M Last', 'trans_id': u'3PEYGJ6IVK'}), DictionaryObject({'till_number': u'703648', 'payment_id': UUID('d2c29c60-0b1a-11e7-8f7b-061cf2e0e94d'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'trans_amount': Decimal('837.30'), 'msisdn': u'254722123456', 'trans_time': datetime.datetime(2017, 2, 1, 21, 30, 52, 739964, tzinfo=tzoffset(None, 10800)), 'names': u'First M Last', 'trans_id': u'O65UCIF7I6'}), DictionaryObject({'till_number': u'703648', 'payment_id': UUID('d2c29c60-0b1a-11e7-8f7b-061cf2e0e94d'), 'user_id': UUID('8dad2dea-7d7f-4e8b-a61c-53150f1b7452'), 'trans_amount': Decimal('808.16'), 'msisdn': u'254722123456', 'trans_time': datetime.datetime(2017, 2, 15, 21, 30, 52, 740086, tzinfo=tzoffset(None, 10800)), 'names': u'First M Last', 'trans_id': u'ZJZCT31FQE'})], 'tracking_uuid': UUID('93b6845a-2c53-11e7-bf31-000c29e41bf4'), 'available_resultset_size': 5, 'limit': 30, 'offset': 0, 'returned_resultset_size': 5})

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

niftyclient-0.3.0.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file niftyclient-0.3.0.tar.gz.

File metadata

  • Download URL: niftyclient-0.3.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for niftyclient-0.3.0.tar.gz
Algorithm Hash digest
SHA256 caf194a3a2010546ae700a9874035319d645797f3c8ccb02279d8c0d7d7aa9b0
MD5 5510ef63d870a9eb7a920cc1b3a149d4
BLAKE2b-256 fbce8638a8fbf1d6d62132504bda75bd10450552ce579dfb407b6daaf1eb88fe

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