-
Notifications
You must be signed in to change notification settings - Fork 6
Using Library
Quixote edited this page Dec 31, 2022
·
1 revision
You can use different instances in the same program, so you can balance the load or run concurrent queries:
import koios_python
# Default Koios Endpoint
kp = koios_python.URLs()
# Custom Koios Endpoint
kp_custom = koios_python.URLs(url="https://koios-otg.tosidrop.io/api/v0/", network='mainnet')
Get the tip info about the latest block seen by chain:
import koios_python
import pprint
# Default Koios Endpoint
kp = koios_python.URLs() # We need to create an instance of the class URLs. Here is where you can add Testnet or your custom endpoint
pprint.pp(kp.get_tip())
Output:
[{'hash': '748cbd952c188aa8ff7690193432c72f9729fc7373981699bfdf288d449b41d3',
'epoch_no': 384,
'abs_slot': 80880713,
'epoch_slot': 355913,
'block_no': 8207908,
'block_time': 1672447004}]
Get the Genesis parameters used to start specific era on chain:
import koios_python
import pprint
# Default Koios Endpoint
kp = koios_python.URLs() # We need to create an instance of the class URLs. Here is where you can add Testnet or your custom endpoint
pprint.pp(kp.get_genesis())
Output:
[{'networkmagic': '764824073',
'networkid': 'Mainnet',
'activeslotcoeff': '0.05',
'updatequorum': '5',
'maxlovelacesupply': '45000000000000000',
'epochlength': '432000',
'systemstart': 1506203091,
'slotsperkesperiod': '129600',
'slotlength': '1',
'maxkesrevolutions': '62',
'securityparam': '2160',
'alonzogenesis': '{"lovelacePerUTxOWord":34482,"executionPrices":{"prSteps":{"numerator":721,"denominator":10000000},"prMem":{"numerator":577,"denominator":10000}},"maxTxExUnits":{"exUnitsMem":10000000,"exUnitsSteps":10000000000},"maxBlockExUnits":{"exUnitsMem":50000000,"exUnitsSteps":40000000000},"maxValueSize":5000,"collateralPercentage":150,"maxCollateralInputs":3,"costModels":{"PlutusV1":{"sha2_256-memory-arguments":4,"equalsString-cpu-arguments-constant":1000,"cekDelayCost-exBudgetMemory":100,"lessThanEqualsByteString-cpu-arguments-intercept":103599,"divideInteger-memory-arguments-minimum":1,"appendByteString-cpu-arguments-slope":621,"blake2b-cpu-arguments-slope":29175,"iData-cpu-arguments":150000,"encodeUtf8-cpu-arguments-slope":1000,"unBData-cpu-arguments":150000,"multiplyInteger-cpu-arguments-intercept":61516,"cekConstCost-exBudgetMemory":100,"nullList-cpu-arguments":150000,"equalsString-cpu-arguments-intercept":150000,"trace-cpu-arguments":150000,"mkNilData-memory-arguments":32,"lengthOfByteString-cpu-arguments":150000,"cekBuiltinCost-exBudgetCPU":29773,"bData-cpu-arguments":150000,"subtractInteger-cpu-arguments-slope":0,"unIData-cpu-arguments":150000,"consByteString-memory-arguments-intercept":0,"divideInteger-memory-arguments-slope":1,"divideInteger-cpu-arguments-model-arguments-slope":118,"listData-cpu-arguments":150000,"headList-cpu-arguments":150000,"chooseData-memory-arguments":32,"equalsInteger-cpu-arguments-intercept":136542,"sha3_256-cpu-arguments-slope":82363,"sliceByteString-cpu-arguments-slope":5000,"unMapData-cpu-arguments":150000,"lessThanInteger-cpu-arguments-intercept":179690,"mkCons-cpu-arguments":150000,"appendString-memory-arguments-intercept":0,"modInteger-cpu-arguments-model-arguments-slope":118,"ifThenElse-cpu-arguments":1,"mkNilPairData-cpu-arguments":150000,"lessThanEqualsInteger-cpu-arguments-intercept":145276,"addInteger-memory-arguments-slope":1,"chooseList-memory-arguments":32,"constrData-memory-arguments":32,"decodeUtf8-cpu-arguments-intercept":150000,"equalsData-memory-arguments":1,"subtractInteger-memory-arguments-slope":1,"appendByteString-memory-arguments-intercept":0,"lengthOfByteString-memory-arguments":4,"headList-memory-arguments":32,"listData-memory-arguments":32,"consByteString-cpu-arguments-intercept":150000,"unIData-memory-arguments":32,"remainderInteger-memory-arguments-minimum":1,"bData-memory-arguments":32,"lessThanByteString-cpu-arguments-slope":248,"encodeUtf8-memory-arguments-intercept":0,"cekStartupCost-exBudgetCPU":100,"multiplyInteger-memory-arguments-intercept":0,"unListData-memory-arguments":32,"remainderInteger-cpu-arguments-model-arguments-slope":118,"cekVarCost-exBudgetCPU":29773,"remainderInteger-memory-arguments-slope":1,"cekForceCost-exBudgetCPU":29773,"sha2_256-cpu-arguments-slope":29175,"equalsInteger-memory-arguments":1,"indexByteString-memory-arguments":1,"addInteger-memory-arguments-intercept":1,"chooseUnit-cpu-arguments":150000,"sndPair-cpu-arguments":150000,"cekLamCost-exBudgetCPU":29773,"fstPair-cpu-arguments":150000,"quotientInteger-memory-arguments-minimum":1,"decodeUtf8-cpu-arguments-slope":1000,"lessThanInteger-memory-arguments":1,"lessThanEqualsInteger-cpu-arguments-slope":1366,"fstPair-memory-arguments":32,"modInteger-memory-arguments-intercept":0,"unConstrData-cpu-arguments":150000,"lessThanEqualsInteger-memory-arguments":1,"chooseUnit-memory-arguments":32,"sndPair-memory-arguments":32,"addInteger-cpu-arguments-intercept":197209,"decodeUtf8-memory-arguments-slope":8,"equalsData-cpu-arguments-intercept":150000,"mapData-cpu-arguments":150000,"mkPairData-cpu-arguments":150000,"quotientInteger-cpu-arguments-constant":148000,"consByteString-memory-arguments-slope":1,"cekVarCost-exBudgetMemory":100,"indexByteString-cpu-arguments":150000,"unListData-cpu-arguments":150000,"equalsInteger-cpu-arguments-slope":1326,"cekStartupCost-exBudgetMemory":100,"subtractInteger-cpu-arguments-intercept":197209,"divideInteger-cpu-arguments-model-arguments-intercept":425507,"divideInteger-memory-arguments-intercept":0,"cekForceCost-exBudgetMemory":100,"blake2b-cpu-arguments-intercept":2477736,"remainderInteger-cpu-arguments-constant":148000,"tailList-cpu-arguments":150000,"encodeUtf8-cpu-arguments-intercept":150000,"equalsString-cpu-arguments-slope":1000,"lessThanByteString-memory-arguments":1,"multiplyInteger-cpu-arguments-slope":11218,"appendByteString-cpu-arguments-intercept":396231,"lessThanEqualsByteString-cpu-arguments-slope":248,"modInteger-memory-arguments-slope":1,"addInteger-cpu-arguments-slope":0,"equalsData-cpu-arguments-slope":10000,"decodeUtf8-memory-arguments-intercept":0,"chooseList-cpu-arguments":150000,"constrData-cpu-arguments":150000,"equalsByteString-memory-arguments":1,"cekApplyCost-exBudgetCPU":29773,"quotientInteger-memory-arguments-slope":1,"verifySignature-cpu-arguments-intercept":3345831,"unMapData-memory-arguments":32,"mkCons-memory-arguments":32,"sliceByteString-memory-arguments-slope":1,"sha3_256-memory-arguments":4,"ifThenElse-memory-arguments":1,"mkNilPairData-memory-arguments":32,"equalsByteString-cpu-arguments-slope":247,"appendString-cpu-arguments-intercept":150000,"quotientInteger-cpu-arguments-model-arguments-slope":118,"cekApplyCost-exBudgetMemory":100,"equalsString-memory-arguments":1,"multiplyInteger-memory-arguments-slope":1,"cekBuiltinCost-exBudgetMemory":100,"remainderInteger-memory-arguments-intercept":0,"sha2_256-cpu-arguments-intercept":2477736,"remainderInteger-cpu-arguments-model-arguments-intercept":425507,"lessThanEqualsByteString-memory-arguments":1,"tailList-memory-arguments":32,"mkNilData-cpu-arguments":150000,"chooseData-cpu-arguments":150000,"unBData-memory-arguments":32,"blake2b-memory-arguments":4,"iData-memory-arguments":32,"nullList-memory-arguments":32,"cekDelayCost-exBudgetCPU":29773,"subtractInteger-memory-arguments-intercept":1,"lessThanByteString-cpu-arguments-intercept":103599,"consByteString-cpu-arguments-slope":1000,"appendByteString-memory-arguments-slope":1,"trace-memory-arguments":32,"divideInteger-cpu-arguments-constant":148000,"cekConstCost-exBudgetCPU":29773,"encodeUtf8-memory-arguments-slope":8,"quotientInteger-cpu-arguments-model-arguments-intercept":425507,"mapData-memory-arguments":32,"appendString-cpu-arguments-slope":1000,"modInteger-cpu-arguments-constant":148000,"verifySignature-cpu-arguments-slope":1,"unConstrData-memory-arguments":32,"quotientInteger-memory-arguments-intercept":0,"equalsByteString-cpu-arguments-constant":150000,"sliceByteString-memory-arguments-intercept":0,"mkPairData-memory-arguments":32,"equalsByteString-cpu-arguments-intercept":112536,"appendString-memory-arguments-slope":1,"lessThanInteger-cpu-arguments-slope":497,"modInteger-cpu-arguments-model-arguments-intercept":425507,"modInteger-memory-arguments-minimum":1,"sha3_256-cpu-arguments-intercept":0,"verifySignature-memory-arguments":1,"cekLamCost-exBudgetMemory":100,"sliceByteString-cpu-arguments-intercept":150000}}}'}]
Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified epoch, all epochs if empty.
import koios_python
import pprint
# Default Koios Endpoint
kp = koios_python.URLs() # We need to create an instance of the class URLs. Here is where you can add Testnet or your custom endpoint
pprint.pp(kp.get_totals(373))
Output:
[{'epoch_no': 373,
'circulation': '33400935206112250',
'treasury': '1084442000419800',
'reward': '611809805180207',
'supply': '35101471140918966',
'reserves': '9898528859081034'}]
Get the epoch information, all epochs if no epoch specified
import koios_python
import pprint
# Default Koios Endpoint
kp = koios_python.URLs() # We need to create an instance of the class URLs.
# With this query will show info from epoch 380
pprint.pp(kp.get_epoch_info(380))
Output:
[{'epoch_no': 373,
'out_sum': '49607548350874704',
'fees': '132833713956',
'tx_count': 417375,
'blk_count': 21094,
'start_time': 1667339091,
'end_time': 1667771091,
'first_block_time': 1667339091,
'last_block_time': 1667771060,
'active_stake': '25090663550263367',
'total_rewards': '13000498017753',
'avg_blk_reward': '616312602'}]
Get the protocol parameters for specific epoch, returns information about all epochs if no epoch specified
import koios_python
import pprint
# Default Koios Endpoint
kp = koios_python.URLs() # We need to create an instance of the class URLs.
# With this query will show params of the epoch 380
pprint.pp(kp.get_epoch_params(380))
Output:
[{'epoch_no': 380,
'min_fee_a': 44,
'min_fee_b': 155381,
'max_block_size': 90112,
'max_tx_size': 16384,
'max_bh_size': 1100,
'key_deposit': '2000000',
'pool_deposit': '500000000',
'max_epoch': 18,
'optimal_pool_count': 500,
'influence': 0.3,
'monetary_expand_rate': 0.003,
'treasury_growth_rate': 0.2,
'decentralisation': 0,
'extra_entropy': None,
'protocol_major': 7,
'protocol_minor': 0,
'min_utxo_value': '4310',
'min_pool_cost': '340000000',
'nonce': '3950677ef48bb212ad335f253ad1998be4e9fe4ae2a26d402607850461398125',
'block_hash': '50a41a4841185a4f01def36c35f565ee2e1c27ee0e3ddb56885c244e49b24bf4',
'cost_models': '{"PlutusV1": {"bData-cpu-arguments": 1000, '
'"iData-cpu-arguments": 1000, "trace-cpu-arguments": 212342, '
.
. # Output cutted
.
'"remainderInteger-cpu-arguments-model-arguments-intercept": '
'453240}}',
'price_mem': 0.0577,
'price_step': 7.21e-05,
'max_tx_ex_mem': 14000000,
'max_tx_ex_steps': 10000000000,
'max_block_ex_mem': 62000000,
'max_block_ex_steps': 40000000000,
'max_val_size': 5000,
'collateral_percent': 150,
'max_collateral_inputs': 3,
'coins_per_utxo_size': '4310'}]
Get the information about block protocol distribution in epoch
import koios_python
import pprint
# Default Koios Endpoint
kp = koios_python.URLs() # We need to create an instance of the class URLs.
# With this query will show block distribution in the epoch 380
pprint.pp(kp.get_epoch_block_protocols(380))
Output:
[{'proto_major': 7, 'proto_minor': 0, 'blocks': 8930},
{'proto_major': 8, 'proto_minor': 0, 'blocks': 12340}]