diff --git a/bindings/python/README.md b/bindings/python/README.md index 750203dfb..539574bd8 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -12,14 +12,38 @@ - Modify your `create_snapshot_alphanet.sh`, modify Line 14 to `go run ../main.go tool snapgen alphanet1 96f9de0989e77d0e150e850a5a600e83045fa57419eaf3b20225b763d4e23813 snapshots/alphanet1/full_export.bin` - `$ ./run_coo_bootstrap.sh ` -2. Build the iota-client-python library by yourself -- Go to `bindings/python/native` -- `$ cargo build --release` -- The built library is located in `target/release/` -- On MacOS, rename `libiota_client.dylib` to `iota_client.so`, on Windows, use `iota_client.dll` directly, and on Linux `libiota_client.so` to `iota_client.so`. -- Copy your renamed library to `bindings/python/examples/` -- Go to `bindings/python/examples` -- `$ python example.py` +2. To Build the iota_client python library by yourself, there are two ways. + - By using the `cargo` + - Go to `bindings/python/native` + - `$ cargo build --release` + - The built library is located in `target/release/` + - On MacOS, rename `libiota_client.dylib` to `iota_client.so`, on Windows, rename `iota_client.dll` to `iota_client.pyd`, and on Linux `libiota_client.so` to `iota_client.so`. + - Copy your renamed library to `bindings/python/examples/` + - Go to `bindings/python/examples` + - `$ python example.py` + - By using [`maturin`](#https://github.com/PyO3/maturin) + - Go to `bindings/python/native` + - `$ pip3 install maturin` + - `$ maturin develop` + - `$ maturin build --manylinux off` + - The wheel file is now created in `bindings/python/native/target/wheels` + - `$ pip3 install [THE_BUILT_WHEEL_FILE]` + +3. To Use the pre-build libraries + - To use the pre-built libraries for linux/macos/windows, please check the `Artifacts` files generated by the Github Action in the last commit. For example, there are the following 12 wheels in `https://github.com/iotaledger/iota.rs/actions/runs/596639195`. Please download the one which matches your os and python version. + - `linux-iota-client-py3.6-wheel` + - `linux-iota-client-py3.7-wheel` + - `linux-iota-client-py3.8-wheel` + - `linux-iota-client-py3.9-wheel` + - `osx-iota-client-py3.6-wheel` + - `osx-iota-client-py3.7-wheel` + - `osx-iota-client-py3.8-wheel` + - `osx-iota-client-py3.9-wheel` + - `windows-iota-client-py3.6-wheels` + - `windows-iota-client-py3.7-wheels` + - `windows-iota-client-py3.8-wheels` + - `windows-iota-client-py3.9-wheels` + - `$ pip3 install [THE_DOWNLOADED_WHEEL_FILE]` ## Python Example ```python @@ -35,24 +59,24 @@ LOCAL_NODE_URL = "http://0.0.0.0:14265" # USE THIS INSTEAD SEED = os.getenv('MY_IOTA_SEED') -EMPTY_ADDRESS = "iot1qxgamuxntdxq06q4zpmvmdnrerj2f94058ge3flfyx567unw25amvr978uw" +EMPTY_ADDRESS = "atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r" client = iota_client.Client( node=LOCAL_NODE_URL, node_sync_disabled=True) def main(): print('get_health()') - print(f'health: client.get_health()') + print(f'health: {client.get_health()}') print('get_info()') - print(f'node_info: client.get_info()') + print(f'node_info: {client.get_info()}') print('get_tips()') - print(f'tips: client.get_tips()') + print(f'tips: {client.get_tips()}') print('get_addresses') address_changed_list = client.get_addresses( - seed=SEED, account_index=0, begin=0, end=10, get_all=True) + seed=SEED, account_index=0, input_range_begin=0, input_range_end=10, get_all=True) print(f'address_changed list: {address_changed_list}') # Get the (address, changed ) for the first found address @@ -68,7 +92,7 @@ def main(): print(f'message() 100 tokens to address {EMPTY_ADDRESS}') message_id = client.message( - seed=SEED, outputs=[{'address': EMPTY_ADDRESS, 'amount': 100}]) + seed=SEED, outputs=[{'address': EMPTY_ADDRESS, 'amount': 100}])['message_id'] print(f'Token sent with message_id: {message_id}') print(f'Please check http://127.0.0.1:14265/api/v1/messages/{message_id}') @@ -82,7 +106,10 @@ def main(): print(f'get_message_raw() for message_id {message_id}') message_raw = client.get_message_raw(message_id) - print(f"message_raw: {bytearray(message_raw, 'utf-8')}") + print(f"raw_data = {message_raw.encode('utf-8')}") + print( + f"Note the raw data is exactly the same from http://127.0.0.1:14265/api/v1/messages/{message_id}/raw") + print(', which is not utf-8 format. The utf-8 format here is just for ease of demonstration') print(f'get_message_children() for message_id {message_id}') children = client.get_message_children(message_id) @@ -90,7 +117,16 @@ def main(): print(f'message() Indexation') message_id_indexation = client.message( - index="Hello", data=bytes("Tangle", 'utf-8')) + index="Hello", data=[84, 97, 110, 103, 108, 101]) + print(f'Indexation sent with message_id: {message_id_indexation}') + print( + f'Please check http://127.0.0.1:14265/api/v1/messages/{message_id_indexation}') + + # Note that in rust we need to specify the parameter type explicitly, so if the user wants + # to use the utf-8 string as the data, then the `data_str` field can be used. + print(f'message() Indexation') + message_id_indexation = client.message( + index="Hi", data_str="Tangle") print(f'Indexation sent with message_id: {message_id_indexation}') print( f'Please check http://127.0.0.1:14265/api/v1/messages/{message_id_indexation}') @@ -121,6 +157,7 @@ def main(): if __name__ == "__main__": main() + ``` ## API Reference diff --git a/bindings/python/examples/iota_client.so b/bindings/python/examples/iota_client.so deleted file mode 100755 index c5ae46e69..000000000 Binary files a/bindings/python/examples/iota_client.so and /dev/null differ