Koios API is a very useful tool for those who want to develop on Cardano, but don’t want or don’t have the resources and the knowledge to run a full node and cardano-db-sync. I was using it very often, and every time I had to implement new functions in order to use new api endpoints for new queries. Some of the endpoints are GET endpoints, some are POST endpoints, and some of them have or need pagination, some of them don’t need pagination. Sometimes, when the API is overloaded, the requests are failing, and you need to retry the request. For all these reasons, I decided to implement all the possible queries to the Koios API in a python module, which takes care internally of all these problems that need to be resolved. The result is this: https://pypi.org/project/koios-api/. The source code and the documentation are available on Github (https://github.com/cardano-apexpool/koios-api-python). Suggestions and comments are welcome (on Github).
Installing the module is easy:
pip3 install koios_api
Using the module is also straightforward. Importing the complete module and calling get_tip():
import koios_api
koios_api.get_tip()
The result will be like this:
[
{
"hash": "442765ab5660346a6af3ba7667bbd35934e6219a52f0f53a80f28d27a70309c1",
"epoch_no": 381,
"abs_slot": 79265882,
"epoch_slot": 37082,
"block_no": 8129347,
"block_time": 1670832173
}
]
Import only specific functions:
from koios_api.network import get_tip
get_tip()
The result will be identical.
For the complete documentation and usage examples, go to the Github repository, and for even more detailed information about each API endpoint, visit https://api.koios.rest/.
Have fun using the module!