Python library for Hyperledger Iroha 2.
You should install rust (cargo) and python.
pip install maturin
maturin build
After the build, you'll a name of the generated package "wheel" in the log, similar to this one:
📦 Built wheel for CPython 3.10 to …/iroha-python/target/wheels/iroha_python-0.1.0-cp310-cp310-linux_x86_64.whl
Remember the version, change the directory and install the package:
cd target/wheels
pip install iroha_python-VERSION-linux_x86_64.whl
cd ~
After an installation, do a small test to check the installation was successful.
Normally, this test will display the library's contents:
python3 -c "import iroha2; print(dir(iroha2))"
['ClassPath', 'Client', 'Dict', 'Enum', 'KeyPair', 'List', 'Struct', 'Tuple', '_Client', '_Instruction', '_Query', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'data_model', 'get_class', 'import_module', 'iroha2', 'query', 'sys', 'to_rust']
If there was no error, you should be able to use iroha2-python library.
You may also see an error that ends like this:
ModuleNotFoundError: No module named 'iroha2.iroha2'
If it appears, your current directory may be the same as the directory with iroha2
and Python may be attempting to import it instead of the module. Switch to another directory and repeat the test.
Architecturally python library uses rust client library. It is done
via wrapping classes using rust library pyo3
.
The data model of iroha itself is expected to be just classes without
some special methods (without sidechannels, like doing http request).
Communication channel for rust python methods using rust data model
is achieved using pythonize
rust library. It allows to represent almost all rust structures using
python objects (via serde serialization).
Python library right now is in iroha_python/iroha2
. This directory has some
directories:
iroha2
-- iroha2 library itself. Contains client and key generation at rootiroha2.crypto
-- iroha crypto bindingsiroha2.data_model
-- data model with all instructions, queries and expressionsiroha2.sys
-- raw bindings to rust structures wrapped around python objects
iroha_python
is rust sys library (sys in terms of raw bindings without abstractions)iroha_python/generate
is used for generating classes for rust structures
There is a need to regenerate sys sources and update client library after major rust updates in data model.
cargo run -p generate -- iroha2/sys
yapf --style pep8 -r -i iroha2 example