Porting Python modules
- andreagrandi
- Posts: 16
- Joined: Fri Feb 05, 2016 6:48 pm
- Contact:
Porting Python modules
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
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
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/
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/
Re: Porting Python modules
Will bottlepy be making the jump to MicroPython?
Re: Porting Python modules
A (micro) web framework for MicroPython already exists:Ivoah wrote:Will bottlepy be making the jump to MicroPython?
https://github.com/pfalcon/picoweb
https://pypi.python.org/pypi/picoweb
This might eventually also make it to the ESP8266-Port.
- andreagrandi
- Posts: 16
- Joined: Fri Feb 05, 2016 6:48 pm
- Contact:
Re: Porting Python modules
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
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
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
deshipu gave quite a concise answer to your question
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.
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.embed into the fw
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
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/
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/
Re: Porting Python modules
For people that want a similar project, I wrote an unbloated version too: https://github.com/balloob/micropython-http-clientpfalcon 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).
It has a requests-like API but no SSL verification.
Re: Porting Python modules
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/
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/