PyOTA API Classes¶
PyOTA offers you the Python API to interact with the IOTA network. The available methods can be grouped into two categories:
Core API |
Extended API |
---|---|
API commands for direct
interaction with a node.
|
Builds on top of the Core API to
perform more complex operations,
and abstract away low-level IOTA
specific procedures.
|
PyOTA supports both synchronous and asynchronous communication with the network, therefore the Core and Extended API classes are available in synchronous and asynchronous versions.
To use the API in your Python application or script, declare an API instance of any of the API classes. Since the Extended API incorporates the Core API, usually you end up only using the Extended API, but if for some reason you need only the core functionality, the library is there to help you.
1 2 3 4 5 6 7 8 | # Synchronous API classes
from iota import Iota, StrictIota
# This is how you declare a sync Extended API, use the methods of this object.
api = Iota('adapter-specification')
# This is how you declare a sync Core API, use the methods of this object.
api = StrictIota('adapter-specification')
|
The PyOTA speific StrictIota
class implements the Core API,
while Iota
implements the Extended API. From a Python
implementation point of view, Iota
is a subclass of
StrictIota
, therefore it inherits every method and attribute
the latter has.
To use the functionally same, but asynchronous API classes, you can do the following:
1 2 3 4 5 6 7 8 | # Asynchronous API classes
from iota import AsyncIota, AsyncStrictIota
# This is how you declare an async Extended API, use the methods of this object.
api = AsyncIota('adapter-specification')
# This is how you declare an async Core API, use the methods of this object.
api = AsyncStrictIota('adapter-specification')
|
Take a look on the class definitions and notice that Iota
and
AsyncIota
have a Seed
attribute. This is because the
Extended API is able to generate private keys, addresses and signatures from
your seed. Your seed never leaves the library and your machine!
Core API Classes¶
Synchronous¶
-
class
iota.
StrictIota
(adapter: Union[str, BaseAdapter], devnet: bool = False, local_pow: bool = False)¶ Synchronous API to send HTTP requests for communicating with an IOTA node.
This implementation only exposes the “core” API methods. For a more feature-complete implementation, use
Iota
instead.References:
- Parameters
adapter (AdapterSpec) – URI string or BaseAdapter instance.
devnet (Optional[bool]) – Whether to use devnet settings for this instance. On the devnet, minimum weight magnitude is set to 9, on mainnet it is 14 by default.
local_pow (Optional[bool]) –
Whether to perform proof-of-work locally by redirecting all calls to
attach_to_tangle()
to ccurl pow interface.See Optional Local Pow for more info and find out how to use it.
-
set_local_pow
(local_pow: bool) → None¶ Sets the
local_pow
attribute of the adapter of the api instance. If it isTrue
,attach_to_tangle()
command calls external interface to perform proof of work, instead of sending the request to a node.By default,
local_pow
is set toFalse
. This particular method is needed if one wants to change local_pow behavior dynamically.- Parameters
local_pow (bool) – Whether to perform pow locally.
- Returns
None
Asynchronous¶
-
class
iota.
AsyncStrictIota
(adapter: Union[str, BaseAdapter], devnet: bool = False, local_pow: bool = False)¶ Asynchronous API to send HTTP requests for communicating with an IOTA node.
This implementation only exposes the “core” API methods. For a more feature-complete implementation, use
AsyncIota
instead.References:
- Parameters
adapter (AdapterSpec) – URI string or BaseAdapter instance.
devnet (Optional[bool]) – Whether to use devnet settings for this instance. On the devnet, minimum weight magnitude is set to 9, on mainnet it is 1 by default.
local_pow (Optional[bool]) –
Whether to perform proof-of-work locally by redirecting all calls to
attach_to_tangle()
to ccurl pow interface.See Optional Local Pow for more info and find out how to use it.
-
set_local_pow
(local_pow: bool) → None¶ Sets the
local_pow
attribute of the adapter of the api instance. If it isTrue
,attach_to_tangle()
command calls external interface to perform proof of work, instead of sending the request to a node.By default,
local_pow
is set toFalse
. This particular method is needed if one wants to change local_pow behavior dynamically.- Parameters
local_pow (bool) – Whether to perform pow locally.
- Returns
None
Extended API Classes¶
Synchronous¶
-
class
iota.
Iota
(adapter: Union[str, BaseAdapter], seed: Union[AnyStr, bytearray, TryteString, None] = None, devnet: bool = False, local_pow: bool = False)¶ Implements the synchronous core API, plus additional synchronous wrapper methods for common operations.
- Parameters
adapter (AdapterSpec) – URI string or BaseAdapter instance.
seed (Optional[Seed]) –
Seed used to generate new addresses. If not provided, a random one will be generated.
Note
This value is never transferred to the node/network.
devnet (Optional[bool]) –
Whether to use devnet settings for this instance. On the devnet, minimum weight magnitude is decreased, on mainnet it is 14 by default.
For more info on the Mainnet and the Devnet, visit the official docs site<https://docs.iota.org/docs/getting-started/0.1/network/iota-networks/>.
local_pow (Optional[bool]) –
Whether to perform proof-of-work locally by redirecting all calls to
attach_to_tangle()
to ccurl pow interface.See Optional Local Pow for more info and find out how to use it.
References:
https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
https://github.com/iotaledger/wiki/blob/master/api-proposal.md
-
set_local_pow
(local_pow: bool) → None¶ Sets the
local_pow
attribute of the adapter of the api instance. If it isTrue
,attach_to_tangle()
command calls external interface to perform proof of work, instead of sending the request to a node.By default,
local_pow
is set toFalse
. This particular method is needed if one wants to change local_pow behavior dynamically.- Parameters
local_pow (bool) – Whether to perform pow locally.
- Returns
None
Asynchronous¶
-
class
iota.
AsyncIota
(adapter: Union[str, BaseAdapter], seed: Union[AnyStr, bytearray, TryteString, None] = None, devnet: bool = False, local_pow: bool = False)¶ Implements the async core API, plus additional async wrapper methods for common operations.
- Parameters
adapter (AdapterSpec) – URI string or BaseAdapter instance.
seed (Optional[Seed]) –
Seed used to generate new addresses. If not provided, a random one will be generated.
Note
This value is never transferred to the node/network.
devnet (Optional[bool]) –
Whether to use devnet settings for this instance. On the devnet, minimum weight magnitude is decreased, on mainnet it is 14 by default.
For more info on the Mainnet and the Devnet, visit the official docs site<https://docs.iota.org/docs/getting-started/0.1/network/iota-networks/>.
local_pow (Optional[bool]) –
Whether to perform proof-of-work locally by redirecting all calls to
attach_to_tangle()
to ccurl pow interface.See Optional Local Pow for more info and find out how to use it.
References:
https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
https://github.com/iotaledger/wiki/blob/master/api-proposal.md
-
set_local_pow
(local_pow: bool) → None¶ Sets the
local_pow
attribute of the adapter of the api instance. If it isTrue
,attach_to_tangle()
command calls external interface to perform proof of work, instead of sending the request to a node.By default,
local_pow
is set toFalse
. This particular method is needed if one wants to change local_pow behavior dynamically.- Parameters
local_pow (bool) – Whether to perform pow locally.
- Returns
None