MicroWebSrv Lightweight HTTP Web Server Supports HTML/Python Language Templating

There are many languages that can be used to create a web page: HTML,  HTML5, JavaScript, PHP, etc… But Python? Apparently yes, as MicroWebSrv  lightweight web server – mostly designed for ESP32 platforms running MicroPython such as Pycom boards – supports inserting Python code inside “HTML” files with the extension .pyhtml.

HTML/Python pyhtml file

The code can be found in Github, and is only comprised of three files.

  • microWebSrv.py – The Web server
  • microWebSocket.py – The optional support of WebSockets
  • microWebTemplate.py – The optional templating language for .pyhtml rendered pages

Beside HTML/Python files, the web server can handle GET, POST, … requests, an embedded full REST API, routing handlers, WebSockets, etc…

That’s what a mixed HTML + Python .pyhtml file may look like:


You can use double curly braces {{ and }} to insert MicroPython code, if statements, for loops, or includes.

I’m not sure if this makes really sense for all platforms, but if your board is resource limited, and already runs MicroPython firmware, it would already have a Python interpreter, and you might do without the extra ram/storage footprint for a JavaScript interpreter for example.

Via Guido Stepken on G+ Ubuntu Community

Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK Pi 4C Plus

4 Replies to “MicroWebSrv Lightweight HTTP Web Server Supports HTML/Python Language Templating”

    1. There may not be enough memory and storage to run lighttpd, let alone with PHP support on ESP32 hardware though (TBC).

  1. Thank you for bringing this, it’s a very versatile solution because it can easily access the underlying hardware

  2. Hello all,

    If you want, I propose a new powerful embedded Web Server for MicroPython (and CPython) that supports route handlers, modules like WebSockets or PyhtmlTemplate and a lot of simultaneous requests.

    Mostly used on ESP32, Pycom WiPy, STM32 on Pyboard, … Robust and efficient (thousands requests on CPython!)

    GitHub – Open Source – MIT.

    –> https://github.com/jczic/MicroWebSrv2 <–

Leave a Reply

Your email address will not be published. Required fields are marked *

Khadas VIM4 SBC
Khadas VIM4 SBC