Skip to content

Commit

Permalink
adding pagination & ordering to asset.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Quixote committed Jul 16, 2023
1 parent c8c5a50 commit 85cf12b
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 35 deletions.
Binary file modified __pycache__/test_koios.cpython-310-pytest-7.2.0.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions koios_python.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: koios-python
Version: 1.3.0
Version: 1.3.1
Summary: Python wrapper Library using Koios API for accessing information stored on the Cardano Blockchain
Home-page: https://github.com/QuixoteSystems
Author: Quixote Stake Pool
Expand All @@ -21,7 +21,7 @@ License-File: LICENSE.md

![koios-python](https://user-images.githubusercontent.com/82296005/194378368-6d2de904-8eec-48bf-a0d9-37118f299470.png)

# Koios Python ![PyPI - Python Version](https://img.shields.io/badge/python-%3E%3D3.8-blue) [![PyPI - Python Version](https://img.shields.io/badge/pypi%20package-v1.2.0-green)](https://pypi.org/project/koios-python/)
# Koios Python ![PyPI - Python Version](https://img.shields.io/badge/python-%3E%3D3.8-blue) [![PyPI - Python Version](https://img.shields.io/badge/pypi%20package-v1.3.0-green)](https://pypi.org/project/koios-python/)

## Overview
**Koios Python** is Python wrapper which allow interacting with all information and parameters stored on the Cardano blockchain using [Koios REST API](https://api.koios.rest/)
Expand Down
Binary file modified koios_python/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/account.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/address.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/address.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/asset.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/asset.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/block.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/environment.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/epoch.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/network.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/pool.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/scripts.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/transactions.cpython-311.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/urls.cpython-311.pyc
Binary file not shown.
46 changes: 37 additions & 9 deletions koios_python/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,32 @@ def get_asset_list(self, content_range="0-999"):
Get the list of all native assets (paginated, sorted)
:return: list with all asset list.
:param str content_range: number of selected elements to return
:rtype: list.
"""
timeout = get_timeout()
custom_headers = {"Range": str(content_range)}
custom_params = {"order": "asset_name.asc"}
asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, params = custom_params, timeout=timeout)
asset_list = json.loads(asset_list.content)

return asset_list


@Exception_Handler
def get_asset_token_registry(self, content_range="0-999"):
"""
Get a list of assets registered via token registry on github
Get a list of assets registered via token registry on Github
:return: list of all asset token registry.
:param str content_range: number of selected elements to return
:rtype: list.
"""
timeout = get_timeout()
custom_headers = {"Range": str(content_range)}
token_registry = requests.get(self.ASSET_TOKEN_REGISTRY_URL, headers = custom_headers, timeout=timeout)
token_registry = json.loads(token_registry.content)

return token_registry


Expand All @@ -44,6 +49,7 @@ def get_asset_addresses(self, asset_policy, asset_name, content_range="0-999"):
:param str asset_policy: asset Policy ID in hexadecimal format (hex).
:param str asset_name: string with Asset Name in hexadecimal format (hex).
:param str content_range: number of selected elements to return
:return: list of all addresses.
:rtype: list.
"""
Expand All @@ -53,8 +59,10 @@ def get_asset_addresses(self, asset_policy, asset_name, content_range="0-999"):
info = requests.get(f"{self.ASSET_ADDRESSES_URL}{asset_policy}&_asset_name={asset_name}", \
headers = custom_headers, params = custom_params, timeout=timeout)
info = json.loads(info.content)

return info


@Exception_Handler
def get_asset_nft_address(self, asset_policy, asset_name):
"""
Expand All @@ -68,6 +76,7 @@ def get_asset_nft_address(self, asset_policy, asset_name):
timeout = get_timeout()
info = requests.get(f"{self.ASSET_NFT_ADDRESS_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout)
info = json.loads(info.content)

return info


Expand All @@ -84,8 +93,10 @@ def get_asset_info(self, asset_policy, asset_name):
timeout = get_timeout()
info = requests.get(f"{self.ASSET_INFO_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout)
info = json.loads(info.content)

return info


@Exception_Handler
def get_asset_info_bulk(self, *asset_list):
"""
Expand Down Expand Up @@ -115,14 +126,17 @@ def get_asset_history(self, asset_policy, asset_name):
timeout = get_timeout()
history = requests.get(f"{self.ASSET_HISTORY_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout)
history = json.loads(history.content)

return history


@Exception_Handler
def get_policy_asset_addresses(self, asset_policy, content_range="0-420"):
def get_policy_asset_addresses(self, asset_policy, content_range="0-500"):
"""
Get the list of addresses with quantity for each asset on the given policy
:param str asset_policy: asset Policy ID in hexadecimal format (hex).
:param str content_range: number of selected elements to return
:return: list of all addresses.
:rtype: list.
"""
Expand All @@ -132,6 +146,7 @@ def get_policy_asset_addresses(self, asset_policy, content_range="0-420"):
info = requests.get(f"{self.POLICY_ASSET_ADDRESSES_LIST_URL}{asset_policy}",
headers = custom_headers, params = custom_params, timeout = timeout)
info = json.loads(info.content)

return info


Expand All @@ -147,15 +162,17 @@ def get_policy_asset_info(self, asset_policy):
timeout = get_timeout()
info = requests.get(f"{self.POLICY_ASSET_INFO_URL}{asset_policy}", timeout=timeout)
info = json.loads(info.content)

return info


@Exception_Handler
def get_policy_asset_list(self, asset_policy):
def get_policy_asset_list(self, asset_policy, content_range="0-999"):
"""
Get the list of asset under the given policy (including balances)
:param str asset_policy: asset Policy ID in hexadecimal format (hex).
:param str content_range: number of selected elements to return
:return: list of all assets under the same policy.
:rtype: list.
"""
Expand All @@ -165,6 +182,7 @@ def get_policy_asset_list(self, asset_policy):
info = requests.get(f"{self.POLICY_ASSET_LIST_URL}{asset_policy}",
headers = custom_headers, params = custom_params, timeout = timeout)
info = json.loads(info.content)

return info


Expand All @@ -182,27 +200,37 @@ def get_asset_summary(self, asset_policy, asset_name):
timeout = get_timeout()
summary = requests.get(f"{self.ASSET_SUMMARY_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout)
summary = json.loads(summary.content)

return summary


@Exception_Handler
def get_asset_txs(self, asset_policy, asset_name, after_block_height=0, history=False, content_range="0-515"):
def get_asset_txs(self, asset_policy, asset_name, after_block_height=0, history=False, content_range="0-999"):
"""
Get the list of asset under the given policy (including balances)
Get the list of current or all asset transaction hashes (newest first)
:param str asset_policy: asset Policy ID in hexadecimal format (hex).
:param str asset name: Asset Name in hexadecimal format (hex), empty asset name returns royalties
:param int after_block_height: Block height for specifying time delta
:param bool history: Include all historical transactions, setting to false includes only the non-empty ones
:param str content_range: number of selected elements to return
:return: list of all assets under the same policy.
:rtype: list.
"""
timeout = get_timeout()
custom_headers = {"Range": str(content_range)}

if history == True:
if history is True:
history = "true"
txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name}&_after_block_height={after_block_height}&_history={history}", headers=custom_headers, timeout=timeout)
txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \
&_after_block_height={after_block_height}&_history={history}",
headers=custom_headers, timeout=timeout)
txs = json.loads(txs.content)
if history == False:
if history is False:
history = "false"
txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name}&_after_block_height={after_block_height}&_history={history}", headers=custom_headers, timeout=timeout)
txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \
&_after_block_height={after_block_height}&_history={history}",
headers=custom_headers, timeout=timeout)
txs = json.loads(txs.content)

return txs
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
LONG_DESCRIPTION = (HERE / "README.md").read_text(encoding='utf-8')

setup(
version = '1.3.0',
version = '1.3.1',
name = 'koios-python',
author = 'Quixote Stake Pool',
author_email = 'quixotepool@proton.me',
Expand Down
15 changes: 11 additions & 4 deletions test_koios.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ def test_get_asset_list():
if len(asset_list_mainnet) > 0:
assert 'code' not in asset_list_mainnet[0]

# Get a list of assets registered via token registry on Github
def test_get_asset_token_registry():

asset_token_registry = kp.get_asset_token_registry()
if len(asset_token_registry) > 0:
assert 'code' not in asset_token_registry[0]

# get asset address list
def test_get_asset_address_list():

Expand Down Expand Up @@ -218,7 +225,7 @@ def test_get_asset_history():
# get policy asset addresses
def test_get_policy_asset_addresses():

asset_policy_asset_addresses_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501")
asset_policy_asset_addresses_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "0-50")
if len(asset_policy_asset_addresses_mainnet) > 0:
assert 'code' not in asset_policy_asset_addresses_mainnet[0]

Expand All @@ -231,7 +238,7 @@ def test_get_policy_asset_info():

def test_get_policy_asset_list():

asset_policy_asset_list_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501")
asset_policy_asset_list_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "0-99")
if len(asset_policy_asset_list_mainnet) > 0:
assert 'code' not in asset_policy_asset_list_mainnet[0]

Expand All @@ -243,9 +250,9 @@ def test_get_asset_summary():
assert 'code' not in asset_summary_mainnet[0]

# get asset transaction history
def test_get_asset_txs_history():
def test_get_asset_txs():

asset_txs_history_mainnet = kp.get_asset_txs('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501','424f4f4b')
asset_txs_history_mainnet = kp.get_asset_txs('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501','424f4f4b', True, "0-99")
if len(asset_txs_history_mainnet) > 0:
assert 'code' not in asset_txs_history_mainnet[0]

Expand Down
41 changes: 22 additions & 19 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@
pp.pp(kp.get_totals())
pp.pp(kp.get_pool_delegators_history("pool1hrv8gtrm0dgjg6zyss5uwa4nkruzfnh5vrdkr2sayj7x2nw6mjc", 391))
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
# check_big_account = kp.get_account_addresses(["stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6"])
# pp.pp(check_big_account)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_asset_list = kp.get_asset_list(content_range="999-1999")
print(get_asset_list)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
get_asset_addresses = kp.get_asset_addresses(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501',asset_name='424f4f4b',content_range="0-99")
get_asset_token_registry = kp.get_asset_token_registry("0-5")
pp.pp(get_asset_token_registry)
print('------------------------------------------------------------------------------------------')
get_asset_addresses = kp.get_asset_addresses(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501',asset_name='424f4f4b',content_range="999-1999")
pp.pprint(get_asset_addresses)
Expand All @@ -63,58 +66,58 @@
asset_name='68616e646c65')
pp.pprint(get_asset_nft_address)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_asset_info_bulk = kp.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"],["1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e","776f726c646d6f62696c65746f6b656e"])
pp.pprint(get_asset_info_bulk)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
get_policy_asset_addresses = kp.get_policy_asset_addresses(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', content_range="0-99")
print('------------------------------------------------------------------------------------------')
get_policy_asset_addresses = kp.get_policy_asset_addresses(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', content_range="0-500")
pp.pprint(get_policy_asset_addresses)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_policy_asset_info = kp.get_policy_asset_info(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501')
pp.pprint(get_policy_asset_info)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_policy_asset_list = kp.get_policy_asset_list(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501')
pp.pprint(get_policy_asset_list)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_asset_summary = kp.get_asset_summary(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b')
pp.pprint(get_asset_summary)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
get_asset_txs = kp.get_asset_txs(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b', after_block_height=50000, history=False, content_range="0-99")
print('------------------------------------------------------------------------------------------')
get_asset_txs = kp.get_asset_txs(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b', after_block_height=500000, history=False, content_range="0-99")
pp.pprint(get_asset_txs)
get_asset_txs_hist_true = kp.get_asset_txs(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b', after_block_height=50000, history=True, content_range="0-99")
pp.pprint(get_asset_txs_hist_true)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_address_info = kp.get_address_info("addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv","addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y")
pp.pprint(get_address_info)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_address_txs = kp.get_address_txs("addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv","addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y",after_block=6238675)
pp.pprint(get_address_txs)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_address_credential_utxos = kp.get_credential_utxos("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52","025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52")
pp.pprint(get_address_credential_utxos)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_address_assets = kp.get_address_assets("addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv","addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y")
pp.pprint(get_address_assets)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_address_credential_txs = kp.get_credential_txs("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555", after_block=6238675)
pp.pprint(get_address_credential_txs)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_network_params = kp.get_param_updates()
pp.pprint(get_network_params)
print('------------------------------------------------------------------------------------------------------------------------------------------------------')
print('------------------------------------------------------------------------------------------')
get_epoch_320_info = kp.get_epoch_info(epoch_no=320, include_next_epoch=True)
pp.pprint(get_epoch_320_info)
Expand Down

0 comments on commit 85cf12b

Please sign in to comment.