| 18 | |
| 19 | The API includes the following functions: |
| 20 | {{{ |
| 21 | muscle.init(sys.argv) |
| 22 | muscle.finalize() |
| 23 | |
| 24 | muscle.send(portName, data, [muscle.datatype]) |
| 25 | muscle.receive(portName, [muscle.datatype]) |
| 26 | |
| 27 | muscle.will_stop() |
| 28 | muscle.kernel_name() |
| 29 | muscle.tmp_path() |
| 30 | muscle.has_property(propName) |
| 31 | muscle.get_property(propName) |
| 32 | |
| 33 | muscle.log(msg) |
| 34 | muscle.fine(msg) |
| 35 | muscle.warning(msg) |
| 36 | muscle.severe(msg) |
| 37 | }}} |
| 38 | These functions behave just like their [wiki:"C++ API" C++ counterparts], except `init`, `send` and `receive`. For `init`, first run `import sys` and then `muscle.init(sys.argv)`. Send will accept a sequence of objects, given a muscle datatype. The following datatypes are recognized: |
| 39 | |= Object |= Python data type |= C data type | |
| 40 | | muscle.int | sequence of `int` | 32-bit `int` | |
| 41 | | muscle.long | sequence of `int` | 64-bit `long` | |
| 42 | | muscle.float | sequence of `double` | 32-bit `float` | |
| 43 | | muscle.double | sequence of `double` | 64-bit `double` | |
| 44 | | muscle.boolean | sequence of `bool` | `bool` | |
| 45 | | muscle.raw | `bytearray` | `char *` | |
| 46 | | muscle.string | `str` | `const char *` | |
| 47 | |
| 48 | The first five data types take any sequence, as long as the Python datatype that is contained matches. In some cases, it may be necessary to recreate a NumPy array so that the canonical Python datatypes are used. For example, with `int`: |
| 49 | {{{ |
| 50 | import numpy as np |
| 51 | import muscle |
| 52 | |
| 53 | data = np.zeros(100, np.int) |
| 54 | muscle.send([int(d) for d in data], 'out', muscle.int) |
| 55 | }}} |