Porting Python modules

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
andreagrandi
Posts: 16
Joined: Fri Feb 05, 2016 6:48 pm
Contact:

Porting Python modules

Post by andreagrandi » Sat Mar 05, 2016 6:04 pm

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

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Porting Python modules

Post by pfalcon » Sat Mar 05, 2016 7:49 pm

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).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
Ivoah
Posts: 5
Joined: Wed Mar 02, 2016 10:43 pm

Re: Porting Python modules

Post by Ivoah » Sun Mar 06, 2016 11:03 pm

Will bottlepy be making the jump to MicroPython?

mad474
Posts: 60
Joined: Sun Dec 29, 2013 7:48 pm

Re: Porting Python modules

Post by mad474 » Mon Mar 07, 2016 7:45 am

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.

User avatar
andreagrandi
Posts: 16
Joined: Fri Feb 05, 2016 6:48 pm
Contact:

Re: Porting Python modules

Post by andreagrandi » Mon Mar 07, 2016 10:53 am

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

User avatar
deshipu
Posts: 1348
Joined: Thu May 28, 2015 5:54 pm

Re: Porting Python modules

Post by deshipu » Mon Mar 07, 2016 11:51 am

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.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Porting Python modules

Post by platforma » Mon Mar 07, 2016 1:07 pm

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.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Porting Python modules

Post by pfalcon » Tue Mar 08, 2016 5:35 am

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.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

balloob
Posts: 1
Joined: Wed Mar 09, 2016 6:13 am

Re: Porting Python modules

Post by balloob » Wed Mar 09, 2016 9:48 pm

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.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Porting Python modules

Post by pfalcon » Thu Mar 10, 2016 4:13 pm

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.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply