I am currently trying to create an API-wrapper. For that, I connect to the endpoint (for example https://host.example.com/api/accounts/open) with the request module. Since there are a bunch of endpoints, I need a way to sort them. Currently I have a constants file, where most of the endpoints are created like this:
HOST = 'https://wallet.shiftnrg.org' START = ''.join([HOST, '/api']) ACCOUNTS = ''.join([START, '/accounts']) ACCOUNTS_OPEN = ''.join([ACCOUNTS, '/open']) ... LOADER = ''.join([START, '/loader']) LOADER_GET_STATUS = ''.join([LOADER, '/status'])
And I access them like this (one example):
def accounts_get_balance(address): payload = {'address': address} response = requests.get(constants.ACCOUNTS_GET_BALANCE, params=payload, timeout=constants.TIMEOUT )
While this is working, I was wondering if there is a more efficient, pythonic way of doing this, since I am just a beginner (especially the constants.py, but if you find anything else, feel free to tell me as well!)