API
- class belay.Device(*args, startup: str = '\nimport binascii, errno, hashlib, machine, os, time\nfrom machine import ADC, I2C, Pin, PWM, SPI, Timer\nfrom time import sleep\nfrom micropython import const\n', **kwargs)
Bases:
object
Belay interface into a micropython device.
- __call__(cmd: str, deserialize: bool = True, minify: bool = True) Union[None, bool, int, float, str, List, Dict]
Execute code on-device.
- Parameters
cmd (str) -- Python code to execute.
deserialize (bool) -- Deserialize the received bytestream from device stdout as JSON data. Defaults to
True
.minify (bool) -- Minify
cmd
code prior to sending. Reduces the number of characters that need to be transmitted. Defaults toTrue
.
- Return type
Return value from executing code on-device.
- sync(folder: Union[str, Path], minify=True) None
Sync a local directory to the root of remote filesystem.
For each local file, check the remote file's hash, and transfer if they differ. If a file/folder exists on the remote filesystem that doesn't exist in the local folder, then delete it.
- Parameters
folder (str, Path) -- Directory of files to sync to the root of the board's filesystem.
- task(f: Optional[Callable[[...], Union[None, bool, int, float, str, List, Dict]]] = None, /, minify: bool = True) Callable[[...], Union[None, bool, int, float, str, List, Dict]]
Send code to device that executes when decorated function is called on-host.
- Parameters
f (Callable) -- Function to decorate.
minify (bool) -- Minify
cmd
code prior to sending.
- Returns
Remote-executor function.
- Return type
Callable
- thread(f: Optional[Callable[[...], None]] = None, minify: bool = True) Callable[[...], None]
Send code to device that spawns a thread when executed.
- Parameters
f (Callable) -- Function to decorate.
minify (bool) -- Minify
cmd
code prior to sending.
- Returns
Remote-executor function.
- Return type
Callable
- exception belay.PyboardException
Bases:
Exception
Uncaught exception from the device.
- exception belay.SpecialFilenameError
Bases:
Exception
Not allowed filename like
boot.py
ormain.py
.
- belay.minify(code: str) str
Minify python code.
Naive code minifying that preserves names and linenos. Performs the following:
Removes docstrings.
Removes comments.
Removes unnecessary whitespace.
- Parameters
code (str) -- Python code to minify.
- Returns
Minified code.
- Return type
str