The usecases enabled by this are:
- "MicroPython first" module development. I.e. modules can be developed and optimized for MicroPython, the efficient Python language implementation, while still work on bloated implementations like CPython.
- Reuse of the wealth of tools available for CPython, like debuggers, syntax/style checkers, coverage, etc.
- Porting large MicroPython libs/apps to CPython. For example, uasyncio used to work on CPython by monkey-patching CPython's asyncio, but as it evolved, it became impractical/inefficient to do that. Implementing uasyncio dependencies, like utime, uselect, etc. is a better way.
- Overall proof that despite differences in standard libraries, MicroPython and CPython are members of one big Python ecosystem.
Code: Select all
$ pip3 install --user micropython-cpython-uhashlib ... $ python3 ... >>> import uhashlib >>> uhashlib.sha1(b"test").hexdigest() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'sha1' object has no attribute 'hexdigest' # MicroPython's uhashlib doesn't have hexdigest(), use ubinascii.hexlify(.digest()) >>> uhashlib.sha1(b"test").digest() b'\xa9J\x8f\xe5\xcc\xb1\x9b\xa6\x1cL\x08s\xd3\x91\xe9\x87\x98/\xbb\xd3'
To remind, the master micropython-lib repository is https://github.com/pfalcon/micropython-lib . Issues reports and patches adhering to Contributor Guidelines are welcome.