9 ms·
Micro Python – a lean and efficient implementation of Python 3
- ashish01 12y agoIs there a way to try it on windows ?
- corysama 12y agohttps://github.com/micropython/micropython/tree/master/windows https://github.com/micropython/micropython/tree/master/windo... > This is experimental, community-supported Windows port of MicroPython. It is based on Unix port, and expected to remain so. The port requires additional testing, debugging, and patches. Please consider to contribute.
- stinos 12y agoIt works ok though: all tests pass both for msvc and mingw
- neil_s 12y agoNice! How much of this optimization can be ported back to CPython, keeping compatibility but improving memory usage and speed?
- carbon12 12y agoA lot of the internals are significantly different, and would be difficult to back port. Eg, a Micro Python object is a machine word which might be a pointer to a real object, a small integer, or an interned string. By stuffing small integers (and strings) into the unused bit-space of a machine word, Micro Python can do a lot of integer operations without allocating heap RAM. This is in contrast to CPython where all integers are on the heap (although the ones below 257 are cached). Another example: calling a function in CPython requires a heap allocation of the call frame. In Micro Python this is generally not needed (unless the function call is significantly complicated).
- est 12y agoThe problem is that CPython core developers does think performance is a priority. They think CPython is fast enough for everybody.
- keeperofdakeys 12y agoQuite simply, this project cut most of the features that big programs depend on, in order to make a smaller, faster core. Things like most of the standard library, meta-programming, and general scalability are included in these cuts. Most people don't realise how much python does underneath for them, which is why cpython is so "bloated" in comparison to this.
- ForHackernews 12y agoThis is pretty cool. Could it run on something like an Arduino?
- dorfsmay 12y agoIt runs on the micropython board: http://micropython.org http://micropython.org
- genofon 12y agofrom the kickstarter page: Pledge £1,000 or more Micro Python will be ported to run on a microcontroller of your choice. The microcontroller must have the capabilities, and you are responsible for set-up costs for the development board and/or software.
- eric_bullington 12y agoIf you're talking about the traditional 8-bit AVR Arduinos, the answer is almost certainly no. The AVR boards like the ATmega328 (on the Uno) only have a few kbyte of RAM available. But MicroPython apparently can run on some pretty tiny and inexpensive boards: namely the Arm Cortex microcontrollers. They are a bit more expensive than the chip in the Arduino, but well under $20 per chip. You can buy very nice evaluation Cortex boards for ~$10 from ST and Freescale[1,2]. Incidentally, Arduino now makes a board that uses the Arm Cortex chip: the Arduino Due[3]. I believe it's around $30. 1. http://www.element14.com/community/docs/DOC-46626/l/element14-presents-freescale-kinetis-l-based-freedom-development-board http://www.element14.com/community/docs/DOC-46626/l/element1... 2. http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252419 http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252... 3. http://arduino.cc/en/Main/arduinoBoardDue http://arduino.cc/en/Main/arduinoBoardDue
- chillingeffect 12y agoIt appears from [0] that the chip of choice is the STM32F045RGT (datasheet [1]). This is from the Cortex M4f series, which includes such wonderful things as a hardware floating-point unit. That is wonderful news, although, this board appears to have no external memory, so it would be limited to 128kB. [0] https://raw.githubusercontent.com/micropython/pyboard/master/schem.png https://raw.githubusercontent.com/micropython/pyboard/master... [1] http://www.alldatasheet.com/datasheet-pdf/pdf/510587/STMICROELECTRONICS/STM32F405RG.html http://www.alldatasheet.com/datasheet-pdf/pdf/510587/STMICRO...
- michaelhoffman 12y ago> Supports almost full Python 3 syntax, including yield (compiles 99.99% of the Python 3 standard library). What parts of Python 3 syntax are missing? Which parts of the library don't compile?
- deleted 12y ago[deleted]
- michaelhoffman 12y agoYeah, I actually spent a few minutes checking out that site before asking this question and the answer is not anywhere obvious.
- VeejayRampay 12y agoI am not sure what you went for with this, but it really strikes the reader as over the top and condescending, no need for that in a discussion thread about a programming language. There are people reading those pages who are thinking of engaging the programming community and behavior like this really gives a bad impression.
- hrttrht 12y agowtf?
- maxerickson 12y agoIt's discussed some here: https://github.com/micropython/micropython/wiki/Differences https://github.com/micropython/micropython/wiki/Differences But I guess they are still in the process of writing that/filling it out. The biggest difference listed is probably no Unicode. Another significant point is that lots of library functions are only partially implemented.
- AceJohnny2 12y ago> The biggest difference listed is probably no Unicode. Funny, considering that was the core reason for Python3 in the first place (though I can't immediately come up with a reference).
- meepmorp 12y agoThe project's website, from the linked post: http://micropython.org http://micropython.org Apparently, there's a kickstarter for a dev board that runs this version of python. Looks interesting.
- analog31 12y agoGot one! Haven't fired it up yet.
- ant_sz 12y agoThis project provide a so-called pyboard. It is interesting! The board's design can be found here https://github.com/micropython/pyboard https://github.com/micropython/pyboard
- stinos 12y agoSlowly gaining traction it seems. Has been posted before without even getting comments (https://news.ycombinator.com/item?id=6763123 https://news.ycombinator.com/item?id=6763123) and then some comments (https://news.ycombinator.com/item?id=6996692 https://news.ycombinator.com/item?id=6996692) but already has more points now :]
- mech4bg 12y agoThe kickstarter for the controller boards got a few votes too, but didn't get much traction: https://news.ycombinator.com/item?id=6727326 https://news.ycombinator.com/item?id=6727326 Glad to see people getting on board now, it's pretty awesome. Fitting Python onto such a resource limited microcontroller is a great achievement.
- ionforce 12y agoDoes it strike anyone else as odd that garbage collection is used in such a resource constrained environment? Also tangent question, what is it about languages like Python and Ruby that make it more amenable to reimplementation than Perl?
- Demiurge 12y agoTo take a stab at the second question, I think BNF that fits on one page https://docs.python.org/3.4/reference/grammar.html https://docs.python.org/3.4/reference/grammar.html vs http://perldoc.perl.org/perlfaq7.html#Can-I-get-a-BNF%2fyacc%2fRE-for-the-Perl-language%3f http://perldoc.perl.org/perlfaq7.html#Can-I-get-a-BNF%2fyacc... This basically means Perl is very complex and its grammar can be self contradicting, such that behavior is undefined. C++ has a similar problem to a lesser extent.
- riffraff 12y agoTo expand on the non-syntax, perl has an incredible amount of language-level features, which may appear very weird to people who have only seen it from afar. For example, perl formats[0] are language-level support for generating formatted text reports and charts, which is basically a whole sublanguage (much like perl regexen). [0] http://perldoc.perl.org/perlform.html http://perldoc.perl.org/perlform.html
- stcredzero 12y agoWhen I looked at such things last, Python had about 29 terminals & nonterminals in its grammar. Ruby had 110. (These are numbers I remember from playing with particular parser libraries, so YMMV.) By contrast, a commercial Smalltalk with some syntax extensions had 8. I have no idea about Perl, but I'd guess it's about the same as Ruby.
- ethanpil 12y agoWOW!! I see this as a serious competitor to Lua. I think lua because so popular because of its small footprint and easy embedability... Perhaps this is the first step to a Python revolution... I expect to see a lot of interesting devices and software embedding Micro Python.
- plorkyeran 12y agoIt's still well over an order of magnitude bigger than Lua. MicroPython is ~200k non-blank-non-comment lines of code (as reported by cloc), while Lua 5.1 is 12k.
- carbon12 12y agoActually, most of that SLOC is in the stmhal/ port, of which ~100k is the ST library. The true count comes from the py/ directory, for which cloc gives only 25k. And there are a lot of extra bits there, eg the inline assembler, the Thumb and X64 assembler helpers, etc. EDIT: without the additional assemblers, cloc gives 22k. Remember that Python has ints, floats, complex and bignum, and these are all included in Micro Python. So that 22k SLOC includes complex arithmetic and a 1k bignum implementation.
- nly 12y ago$ size /usr/bin/micropython text data bss dec hex filename 272356 1336 1216 274908 431dc /usr/bin/micropython $ size /usr/lib/liblua.so.5.2.3 text data bss dec hex filename 195101 6408 8 201517 3132d /usr/lib/liblua.so.5.2.3 I think it would really interesting for µPy to be opened up to run as a hosted runtime.
- trynumber9 12y agoAnd then there is LuaJIT. As fast as V8, smaller than Micro Python, with a dead simple FFI.
- freehunter 12y agoGod I wish we had Lua instead of Javascript in the browser.
- thearn4 12y agoJust got my board (kickstarter backer). Can't wait to take a few hours to play with it!
- Fuzzwah 12y agoCould you share what projects you can imagine this being great for? I'm excited by the idea of it all but I can't seem to come up with a project that I'd want to mess with enough to purchase one. Maybe I just need more coffee....
- thomasahle 12y agoIt always strikes me, that the things that parts of python that create problems for people trying to optimize it, are all things of relatively small importance. Like __new__, __del__ semantics and changing the stack by inspection. I wish Python3 had just let go of the slow scripting-only parts.
- dbpatterson 12y agoThe problem is that often while regular users are not directly using those features, they are using libraries that do use them. As a concrete example, people writing webapps with Django probably (often) aren't using some of the crazier class metaprogramming, but they are using Django's models, which use lots of it.
- dekhn 12y agoThis is pretty neat, I'm gaining an appreciate for microcontrollers and using high level languages is attractive. That said, the alternative I'm exploring is to upload a standard Firmata firmware to the microcontroller, then drive it remotely, say from python on a full computer (like raspberry pi). i think the interestng area comes when you can actually put a fairly "smart" microcontroller firmware on the device (GRBL) and then program it remotely, say with a scripting language. At that point, the boundaries between a firmware that is a dvice controller, and a firmware that is an open-ended remotely drivable VM starts to break down. Interesting area.
- andybak 12y agoIs this a route to a good Python stack for mobile? Any interest from the Kivy team or related projects?
- ogdenyogly 12y agoMy thoughts exactly. Python is a beast to embed on iOS.
- errordeveloper 12y agoShould be pretty easy, the interpreter core is damn clean and minimal. Look at arm-bare port, it should be pretty easy to convert that to a static library port. It uses 16-bit Thumb2 instruction set thought, that might involve additional hacking if you wanna target 64-bit ARM cores, which some of the latest phones have. Ping me at @errordeveloper if you wanna chat about that.
- knappador 12y agoYes, I'm trying to feel out the necessary work to get Cython and other Cpython modules working by hacking the Python headers to make a plain Cpython C module compile to a micro-python compatible module. It's not clear that there are C modules yet, so maybe there's a lot of work to do, but it just struck me how much both ecosystems can benefit if the headers can indeed be backed so that C modules (and Cython modules) "just work."
- pekk 12y agoPeople are constantly running Java on mobile and that's very heavy. With phone storage into the gigs. There's no reason Python couldn't have been used before Micropython, except that vendors didn't want to allow it in.
- andybak 12y agoIt's about: a) executable size (packaging a large runtime with every app b) RAM usage Python suffers on both counts on mobile.
- sandGorgon 12y agowe use a lot of python on the windows platform - especially the win32 and multiprocessing modules. Would love a variant of micropython on windows that can support them. There a large number of embedded Windows CE devices that run in retail.
- ngoldbaum 12y agoIt was just pointed out to me that micropython starts an order of magnitude faster than both python2 and python3: $ time ./micropython -c 'print(1)' 1 ./micropython -c 'print(1)' 0.00s user 0.00s system 0% cpu 0.002 total $ time ./python2 -c 'print(1)' 1 python2 -c 'print(1)' 0.01s user 0.00s system 52% cpu 0.019 total $ time ./python3 -c 'print(1)' 1 python3 -c 'print(1)' 0.03s user 0.00s system 85% cpu 0.035 total
- errordeveloper 12y agoBare in mind it's statically linked also, so it doesn't need to read a bunch of dynamic libraries from disk.
- carbon12 12y agoActually, no, the unix version is dynamically linked (against libc, libm, etc).
- stinos 12y agoIf you compare the startup code needed it is clear where at least a major part of this time comes from. Micropython has close to no startup code actually (it just initializes some dictionaries, stores arguments etc). Something like Python3 on the other hand: oh my. Recently I was stepping through pretty much all of it in the debugger to figure out a problem, day afterwards I had a cramp in my finger from hitting the 'Step' button too much :P
- huxley 12y agoI wonder how that would stack with PyPy3 or if there are too many changes that wouldn't port over.
- pekk 12y agoPyPy has a much slower startup.
- 12y ago
- brassattax 12y agoAnyone else read that as "Monty Python"?
- justincormack 12y agoThere is a talk about it here from a few weeks ago https://www.youtube.com/watch?v=hmGISrwPtyA https://www.youtube.com/watch?v=hmGISrwPtyA
- daGrevis 12y agoIf someone is wondering what's going on with unicode support: > No unicode support is actually implemented. Python3 calls for strict difference between str and bytes data types (unlike Python2, which has neutral unified data type for strings and binary data, and separates out unicode data type). MicroPython faithfully implements str/bytes separation, but currently, underlying str implementation is the same as bytes. This means strings in MicroPython are not unicode, but 8-bit characters (fully binary-clean).
- maxerickson 12y agoThis was linked in a later post to the mailing list thread: https://github.com/micropython/micropython/issues/657 https://github.com/micropython/micropython/issues/657 They plan on improving the Unicode support.
- kelvin0 12y agoI am truly very happy that he was able to fund this cool project. The funding went very well it seems, more more than 6x the initial proposed funding! I might just quit my job and do something similar!
- rectangletangle 12y agoAnyone know the "scale" of this re-implementation? Is it simply a fork of CPython with some performance tweaks, or is it a primarily new code-base? Regardless it's pretty cool.
- keeperofdakeys 12y agoIt'd definitely be a new code-base. In terms of comparison, I'd guess this uses "cheaper" algorithms, that use less memory, and don't scale as well. There are many things that CPython does behind the background that most people don't fully appreciate. Edit: Here is a good document on the differences https://github.com/micropython/micropython/wiki/Differences https://github.com/micropython/micropython/wiki/Differences
- lacion 12y agoi got one of the dev boards like a month ago, i was part of the kickstarter. this thing is amazing, it took me a week to stop using arduino.
- lerouxb 12y agoSo upset that I missed this kickstarter. I've been obsessively refreshing the homepage to see if I can buy a micropython board yet.
- knappador 12y agoAttn: Kivy can really use this for mobile deployements, but we use Cython and almost everyone needs cpython C modules. We need to investigate making drop-in replacements for Python.h and other cpython headers to stub out reference counting etc, which micro-python doesn't use. The compiler will just skip the calls entirely in some cases. If these drop-in replacements are technically feasible, not only does Cython magically work, but so does a lot of the Python ecosystem. There's probably more work to get linking and other aspects working, but this might also be a model for moving to alternative Python implementations in general. As long as straight Python "just works" and the headers are available for compiling C modules, we're very close to having a sensible alternative to cpython that can grow without being wedded to it. Please comment on technical requirements. Issue opened here: https://github.com/micropython/micropython/issues/658 https://github.com/micropython/micropython/issues/658
- zobzu 12y agoany benchmark vs cpython avail? (not startup speed). just curious.