A Python API for interacting with IoTeX
Project description
IoTeX API for Python
Install it in a system-wide location via pip:
.. code-block:: bash
sudo pip install iotexpai
Install it locally using virtualenv:
.. code-block:: bash
virtualenv .env
source .env/bin/activate
pip install iotexapi
Base Example
.. code-block:: python
from iotexapi import Iotex
from google.protobuf.json_format import MessageToJson
import json
import logging
import time
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger()
iotex = Iotex()
acc = iotex.create_account
logger.debug('Generated account: ')
logger.debug('- Private Key: ' + acc.private_key)
logger.debug('- Public Key: ' + acc.public_key)
logger.debug('- Address: ')
logger.debug('-- IO: ' + acc.address.io)
logger.debug('-- ETH: ' + acc.address.eth)
logger.debug('-----------')
address = iotex.address.from_private_key("b5a4cea271ff424d7c31dc12a3e43e401df7a40d7412a15750f3f0b6b5449a28")
logger.debug('Address from PrivateKey: ')
logger.debug('- IO: ' + address.io)
logger.debug('- ETH: ' + address.eth)
logger.debug('-----------')
iotex.private_key = "b5a4cea271ff424d7c31dc12a3e43e401df7a40d7412a15750f3f0b6b5449a28"
logger.debug('Default PrivateKey: ')
logger.debug('- Private Key: ' + iotex.private_key)
logger.debug('- Public Key: ' + iotex.public_key)
logger.debug('- Address: ')
logger.debug('-- IO: ' + iotex.default_address.io)
logger.debug('-- ETH: ' + iotex.default_address.eth)
logger.debug('-----------')
chainMeta = iotex.iotx.getChainMeta().chainMeta
logger.debug('Chain Meta: ')
logger.debug('- Height: ' + str(chainMeta.height))
logger.debug('- NumActions: ' + str(chainMeta.numActions))
logger.debug('- Epoch: ' + str(chainMeta.epoch.num))
logger.debug('-----------')
accountInfo = iotex.iotx.getAccount("io1epvezy0jns0pupsjvk62lyl2run544u2a4jpn3").accountMeta
logger.debug('Account Info: ')
logger.debug('- Address: ' + accountInfo.address)
logger.debug('- Balance: ' + accountInfo.balance)
logger.debug('- Nonce: ' + str(accountInfo.nonce))
logger.debug('- PendingNonce: ' + str(accountInfo.pendingNonce))
logger.debug('- NumActions: ' + str(accountInfo.numActions))
logger.debug('-----------')
actions = iotex.iotx.getActionsByAddress("io1epvezy0jns0pupsjvk62lyl2run544u2a4jpn3",0,2)
actions = MessageToJson(actions)
logger.debug('Actions by Address: ')
logger.debug('- List: ' + json.dumps(actions, indent=2))
logger.debug('-----------')
blocks = iotex.iotx.getBlockMetas(start=1, count=5)
blocks = MessageToJson(blocks)
logger.debug('Blocks by height: ')
logger.debug('- List: ' + json.dumps(blocks, indent=2))
logger.debug('-----------')
block = iotex.iotx.getBlockMetas(hash="fda7d0e46023628198589cc31d7eb2a085e866b8cf8329e784685a54527b2745")
block = MessageToJson(block)
logger.debug('Block by Hash: ')
logger.debug('- Block: ' + json.dumps(block, indent=2))
logger.debug('-----------')
epoch = iotex.iotx.getEpochMeta(epoch=100)
epoch = MessageToJson(epoch)
logger.debug('Epoch by Num')
logger.debug('- Data: ' + json.dumps(epoch, indent=2))
logger.debug('-----------')
logger.debug('Transfer')
txId = iotex.iotx.transferTo("io12aymfg8gp2kjeugwdjd50lv3v7wh23v4qgm3x4", 1, {"message": "IoTASK Test"})
logger.debug('Watting...')
time.sleep( 15 )
receipt = iotex.iotx.getReceiptByAction(actionHash=txId.actionHash)
receipt = MessageToJson(receipt)
logger.debug('Transaction: ')
logger.debug('- Hash: ' + txId.actionHash)
logger.debug('- Transaction: ' + json.dumps(receipt, indent=2))
logger.debug('-----------')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
iotexapi-0.0.1.tar.gz
(33.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
iotexapi-0.0.1-py3-none-any.whl
(41.7 kB
view details)
File details
Details for the file iotexapi-0.0.1.tar.gz.
File metadata
- Download URL: iotexapi-0.0.1.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d293ac16b3924a904f46a8e6f23c03289e325ff78f4282cadc157c70ae3088f2
|
|
| MD5 |
882b4e6c7d8f4a141c2f127d7608f0d3
|
|
| BLAKE2b-256 |
b7ab461bffada75bf4bedfe1ba1fef17d0cd3c0aeeb051a4da4f4155c49453f5
|
File details
Details for the file iotexapi-0.0.1-py3-none-any.whl.
File metadata
- Download URL: iotexapi-0.0.1-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c41b9948737e51ecc7f4e934311f10a48855b58ad50c1699615a3692371d06e
|
|
| MD5 |
4151a42e2a4b71b55c1cc62fd345070e
|
|
| BLAKE2b-256 |
52cde776b406282832cf737e6916fb19f04b6c37caa43ca84d5773b684f48190
|