-
Notifications
You must be signed in to change notification settings - Fork 6
Starting
To go into this section you need to install koios-python library how you can see in Installation section.
Import to your python file this library:
import koios_python
In this example we will get and print the parameters of epoch 370:
First we have to create a python file for our test, in this easy example we will use nano editor:
nano test.py
Now just copy & paste this code:
#!/usr/bin/env python3
import pprint # We recommend use pprint library to print your outputs
import koios_python
# Default Koios Endpoint
# We need to create an instance of the class URLs.
# Here is where you can add Testnet or your custom endpoint
kp = koios_python.URLs()
# If you want to use Koios API with a Bearer Token you must use:
#kp = koios_python.URLs(bearer='YOUR_BEARER_TOKEN')
# Get info of current epoch 370:
pprint.pp(kp.get_epoch_info(370))
Save the file with "Crt + o and" exit nano "Crt + x" and then you can run test.py:
python3 test.py
You will get this Output, where you can read all parameters of epoch 370:
[{'epoch_no': 370,
'out_sum': '48419024475787171',
'fees': '152910650102',
'tx_count': 457656,
'blk_count': 21169,
'start_time': 1666043091,
'end_time': 1666475091,
'first_block_time': 1666043308,
'last_block_time': 1666474990,
'active_stake': '25170337993638844',
'total_rewards': '13183440432221',
'avg_blk_reward': '622771054'}]
In this library We are handling Pagination with Content-Range as a parameter in the function, so You can manage in your program pagination selecting the range you want or reading all records using a loop.
Important: each page has a maximum of 1000 records, so if you select a bigger range, you will get fist 1000 records.
Here We show you an example:
#!/usr/bin/env python
import pprint # We recommend use pprint library to print your outputs
import koios_python
# Get the Pool List from the record 2001 to 3000
pprint.pp(kp.get_pool_list("2001-3000"))
You can run more examples uncomment the line you want to try of this python file: