Page 1 of 1

Porting Python modules

Posted: Sat Mar 05, 2016 6:04 pm
by andreagrandi
Hi,

I was wondering... what is required to port a module to MicroPython? Example: suppose I really want to have the "requests" Python module available.. do I just include it in the source code and then I build the firmware or there is a specific procedure required?

It would be nice (especially because we will have upip eventually) if more people in the community could port a few modules to MicroPython. Maybe we could mark them as "community" supported and not "officially" supported, but still it would be a nice thing to have.

What do you think about? Cheers

Re: Porting Python modules

Posted: Sat Mar 05, 2016 7:49 pm
by pfalcon
Initial version of unbloated "urequests" (micro-Requests) module is coming to micropython-lib soon (when I get a chance to clean it up, cleaning up of uPy code is higher priority).

Re: Porting Python modules

Posted: Sun Mar 06, 2016 11:03 pm
by Ivoah
Will bottlepy be making the jump to MicroPython?

Re: Porting Python modules

Posted: Mon Mar 07, 2016 7:45 am
by mad474
Ivoah wrote:Will bottlepy be making the jump to MicroPython?
A (micro) web framework for MicroPython already exists:
https://github.com/pfalcon/picoweb
https://pypi.python.org/pypi/picoweb
This might eventually also make it to the ESP8266-Port.

Re: Porting Python modules

Posted: Mon Mar 07, 2016 10:53 am
by andreagrandi
Hi,

thanks everyone for the reply. My question wanted to be a bit more generic by the way: what needs to be done to port an existing module to MicroPython? There must be some "generic steps" like creating a specific environment, setting the micropython interpreter, installing the module, try to run it, create a package, embed into the fw etc...

Thanks

Re: Porting Python modules

Posted: Mon Mar 07, 2016 11:51 am
by deshipu
There isn't really anything special. A simple pure-python module that doesn't interact with the hardware should work just like that. There may be room for some improvement in making it use less memory and so on, but generally Micropython is just Python. Things that touch the hardware need to be written for that particular hardware, though.

Re: Porting Python modules

Posted: Mon Mar 07, 2016 1:07 pm
by platforma
deshipu gave quite a concise answer to your question
embed into the fw
What you're talking about is called frozen modules that are compiled together with micropython and then flashed on the board. "Community" modules don't usually go that route and end up placed in the micropython-lib repository instead, this doesn't mean that you can't freeze them yourself, of course. But with the upip stretch goal on the kickstarter, you might as well be using that to pull your micropython-lib modules if you have a port of some python library.

As a side note, there are ESP modules that support SD cards (somebody ran another kickstarter with this), this will make life much easier since you won't even have to reinstall the modules and keep them on your SD card instead of Flash.

Re: Porting Python modules

Posted: Tue Mar 08, 2016 5:35 am
by pfalcon
andreagrandi, there's indeed no special "magic" how to write or port a Python module to MicroPython. It's also (in general) not really ESP8266 specific, and forum likely contains wealth of the information on that in suitable sections. See e.g. http://forum.micropython.org/viewtopic.php?f=15&t=104 , and http://forum.micropython.org/viewforum.php?f=15 subforum in general.

Re: Porting Python modules

Posted: Wed Mar 09, 2016 9:48 pm
by balloob
pfalcon wrote:Initial version of unbloated "urequests" (micro-Requests) module is coming to micropython-lib soon (when I get a chance to clean it up, cleaning up of uPy code is higher priority).
For people that want a similar project, I wrote an unbloated version too: https://github.com/balloob/micropython-http-client
It has a requests-like API but no SSL verification.

Re: Porting Python modules

Posted: Thu Mar 10, 2016 4:13 pm
by pfalcon
Aforementioned urequests module was pushed few days ago too: https://github.com/micropython/micropyt ... /urequests . To clarify, so far it was tested only with unix port.