Getting Started with Python
In a production setup, do not store passwords in the host's environment variables or in the source code. See our backup and security recommendations for production setups.
Requirements
- Python 3.x
- pip ^21.x
Rust
andCargo
to compile the binding. Install them here.
Install the IOTA SDK
Install Using a Pip
To start using the IOTA SDK in your Python project, you can use pip to install:
pip install iota-sdk
Build the Binding from Source
- Move to the Python bindings directory:
cd iota-sdk/bindings/python
- (optional) You can run the following commands create a virtual environment and use it:
- Linux or Mac OS
- Windows
python3 -m venv iota_sdk_venv
source iota_sdk_venv/bin/activate
.\iota_sdk_venv\Scripts\activate
- Install the required dependencies and build the wheel by running the following commands:
pip install -r requirements-dev.txt
pip install .
- (optional) If you want to deactivate the virtual environment, run the following command:
deactivate
Usage
Client
After you installed the library, you can create a Client
instance and interface with it.
from iota_sdk import Client
# Create a Client instance
client = Client(nodes=['https://api.testnet.shimmer.network'])
# Get the node info
node_info = client.get_info()
print(f'{node_info}')
Wallet
After you installed the library, you can create a Wallet
instance and interact with it.
from iota_sdk import Wallet, StrongholdSecretManager, CoinType
# This example creates a new database and account
wallet_options = {
'nodes': ['https://api.testnet.shimmer.network'],
}
secret_manager = StrongholdSecretManager("wallet.stronghold", "some_hopefully_secure_password")
wallet = Wallet('./alice-database', wallet_options, coin_type=CoinType.SHIMMER, secret_manager)
# Store the mnemonic in the Stronghold snapshot. This only needs to be done once
account = wallet.store_mnemonic("flame fever pig forward exact dash body idea link scrub tennis minute " +
"surge unaware prosper over waste kitten ceiling human knife arch situate civil")
account = wallet.create_account('Alice')
print(account)
What's next?
How-To Guides
Once you have installed the IOTA SDK, you can start building your application. You can find usage examples in this Wiki's how-to guides.
More Examples
You can use the provided code examples to get acquainted with the IOTA SDK. You can use the following command to run any example:
python3 example/[example file]
- Where
[example file]
is the file name from the example folder. For example:
python3 examples/client/00_get_info.py
API Reference
You can generate the Python API reference with the following command from this directory:
pip install pydoc-markdown && pydoc-markdown
API Reference
The IOTA SDK Rust API Reference is in the crate documentation.