5 ms·
MicroPython seems to be heavily focused on embedded systems. Is there any support for embedding it within an application, i.e. as a replacement for Lua? Or is
by pansa2 6y ago
MicroPython seems to be heavily focused on embedded systems.
Is there any support for embedding it within an application, i.e. as a replacement for Lua? Or is there another lightweight Python implementation (or Python-like language) that supports this?
- vsgzusnex 6y agoIt's slightly more constrained for performance but maybe Starlark is what you're looking for? https://github.com/bazelbuild/starlark https://github.com/bazelbuild/starlark
- HALtheWise 6y agoIt should be supported, although I don't have any good examples of people doing it. There is work being put into making micropython into a powerful webasm package for frontend development. https://github.com/micropython/micropython/tree/master/examples/embedding https://github.com/micropython/micropython/tree/master/examp...
- as-j 6y agoWhy not just use Lua? :) yes I get it, Lua is yet another language to your stack. But so is MicroPython. We were looking for a higher lever than C language for an embedded Linux system* and one engineer was massively in favor of MicroPython. But it’s not python, it’s based on 3.4 so it’s like python but not. It has its own rules and particularities. When I hire a new engineer I’d rather say “here read this book and learn this language” than “ok we have this python work alike/fork, now learn all these exceptions.” It’s also not a good fit for embedded Linux system programming like Lua is. *) this is an in production, professional environment, which decision will have years of legacy support and ramifications.
- marktangotango 6y ago“Not quite python” is a subtle point many people miss and indeed can be an issue. Third party library support is also huge, does micropython support the cpython library ecosystem? In this case the plethora of lua libraries readily available via luarocks is a huge advantage.
- toastal 6y agoWhy would you want to replace Lua in this space? At least why replace with another dynamically typed, imperative scripting language, but without tail-call optimization? What would be the gain?
- mottosso 6y agoI was wondering the same as the parent, and in my case it's library support (e.g. NumPy) and compatibility/familiarity in the space (VFX) where Python is everywhere and Lua is unheard of.
- otterlicious 6y agoIf you want NumPy support in particular you basically have to use CPython. The only other implementation that really supports it is PyPy which is not in any sense more lightweight.
- matt_trentini 6y agoAlthough much smaller in scope than NumPy, MicroPython (and CircuitPython) now have the ulab library which provides similar fast array manipulations: https://github.com/v923z/micropython-ulab https://github.com/v923z/micropython-ulab
- drran 6y agoSo, use Python instead of MicroPython.
- londons_explore 6y ago> Why would you want to replace Lua in this space? The crowd of people who speak Lua is pretty different than those who speak Python. I would guess the Lua crowd to be older, more experienced, but smaller. The Python crowd is much bigger, and includes people who dabble in coding rather than those of us who do it for a living. It depends on the user base of your application, but I can totally see why Python would be a better embedding language for users to use. You build the product for the users after all. In todays world, I'd make some V8 bindings and get users to use javascript, because that's even easier to embed, has a bigger ecosystem via nodejs/npm, and has a probably larger userbase... It's got a nice remote debugger/UI too, which is quite a plus if you're expecting inexperienced users to write plugins/modules for you.
- albertzeyer 6y agoWhat is lightweight for you? I bundled the official Python (CPython 2.7, that was some years ago; but I don't think CPython 3 would be so much different) in an application (http://albertz.github.io/music-player/ http://albertz.github.io/music-player/), and the whole MacOSX app zip file ended up at 11 MB. This includes my whole app + whole CPython 2.7 (including all stdlib) + extra Python libs (all the ObjC/Cocoa bindings, which I use for the GUI). I find this is still pretty ok. (Still much smaller than Qt, wxWidgets, Electron, or whatever else there is. But maybe this comparison is unfair.) The scripts to build CPython suitable for embedding it into an app are here: https://github.com/albertz/python-embedded/ https://github.com/albertz/python-embedded/ (But this is not really updated, and so far for CPython 2.7, not CPython 3. But this is not really so difficult anyway. These scripts are mostly such that you have it as a Xcode project and also compiles on iOS.) I think Dropbox does the same, as far as I remember.
- ngcc_hk 6y agoWow. Very interesting. Hope it can be upgraded to 3
- jononor 6y agoIf it is a desktop-type application, just use CPython itself? It has good embedding support since forever, and is the "Python" that most people know and are used to. Best compatibility with existing code, for third party libraries and tooling. https://docs.python.org/3/extending/embedding.html https://docs.python.org/3/extending/embedding.html Many applications in the graphics space embed or otherwise allow Python scripting. Some open source examples are: Blender, FreeCAD, GIMP, Inkscape.
- pjc50 6y agoThere used to be Jython, for embedding inside JVM apps, but the 2/3 transition killed it.
- tomlogic 6y agoDigi International embedded it into some of their XBee wireless radios (802.15.4-based and Cellular models) to allow customers to run an on-device application without compromising any certifications for the radio portion of the firmware. Easier than needing to design hardware with an additional host processor and work out the serial communications between that host and the radio module. While MicroPython was designed to be "bare iron", it wasn't overly difficult to port it to run as a separate task inside the XBee firmware, and connect it up with internals for I/O and file system access. These are ARM Cortex products with firmware sizes in the area of 500KB to 700KB.
- matt_trentini 6y agoYes, and this has recently attracted some focus. Take a look at the example for embedding MicroPython: https://github.com/micropython/micropython/tree/master/examples/embedding https://github.com/micropython/micropython/tree/master/examp...
- stinos 6y agoWe've been running it like that for multiple desktop applications for years. So it's supported in the sense that it works but depending on what you do with it exactly it needs some boilerplate code which mostly means copy-pasting some parts from one of the main.c files for the different ports, no big deal. Creating bindings is another point which requires boilerplate code but that's no diferent from other scripting embeddings.