Installation¶
PyOTA is compatible with Python 3.7, 3.6, 3.5 and 2.7.
Install PyOTA using pip:
pip install pyota[ccurl,pow]
Note
The [ccurl]
extra installs the optional PyOTA-CCurl extension.
This extension boosts the performance of certain crypto operations significantly (speedups of 60x are common).
Note
The [pow]
extra installs the optional PyOTA-PoW extension.
This extension makes it possible to perform proof-of-work
(api call attach_to_tangle
) locally, without relying on an iota node.
Use the local_pow
parameter at api instantiation:
api = Iota('https://nodes.thetangle.org:443', local_pow=True)
Or the set_local_pow
method of the api class to dynamically enable/disable
the local proof-of-work feature.
Getting Started¶
In order to interact with the IOTA network, you will need access to a node.
You can:
Note that light wallet nodes often disable certain features like PoW for security reasons.
Once you’ve gotten access to an IOTA node, initialize an iota.Iota
object with the URI of the node, and optional seed:
from iota import Iota
# Generate a random seed.
api = Iota('http://localhost:14265')
# Specify seed.
api = Iota('http://localhost:14265', 'SEED9GOES9HERE')
Test your connection to the server by sending a getNodeInfo
command:
print(api.get_node_info())
You are now ready to send commands to your IOTA node!
Using the Sandbox Node¶
To connect to the sandbox node, you will need to inject a
SandboxAdapter
into your Iota
object. This will modify
your API requests so that they contain the necessary authentication metadata.
from iota.adapter.sandbox import SandboxAdapter
api = Iota(
# To use sandbox mode, inject a ``SandboxAdapter``.
adapter = SandboxAdapter(
# URI of the sandbox node.
uri = 'https://sandbox.iotatoken.com/api/v1/',
# Access token used to authenticate requests.
# Contact the node maintainer to get an access token.
auth_token = 'auth token goes here',
),
# Seed used for cryptographic functions.
# If null, a random seed will be generated.
seed = b'SEED9GOES9HERE',
)