microweb 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,363 @@
1
+ Metadata-Version: 2.4
2
+ Name: microweb
3
+ Version: 0.1.1
4
+ Summary: A web server framework for MicroPython . Easily build and deploy web applications using MicroPython.
5
+ Home-page: https://github.com/ishanoshada/microweb
6
+ Author: Your Name
7
+ Keywords: micropython,esp32,web server,embedded,iot,http,microcontroller,python
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Software Development :: Embedded Systems
12
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: pyserial
15
+ Requires-Dist: esptool
16
+ Requires-Dist: click
17
+ Dynamic: author
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: keywords
23
+ Dynamic: requires-dist
24
+ Dynamic: summary
25
+
26
+ # MicroWeb
27
+
28
+ MicroWeb is a lightweight web server framework for MicroPython on the ESP32. It enables rapid development of web-based applications with dynamic routing, Wi-Fi configuration, query parameter handling, POST request support, JSON responses, and static file serving. The package includes a robust CLI for flashing MicroPython and running custom applications.
29
+
30
+
31
+ **Example: Minimal MicroWeb Server**
32
+
33
+ ```python
34
+ from microweb import MicroWeb
35
+
36
+ app = MicroWeb(ap={'ssid': 'MyWiFi', 'password': 'MyPassword'}, debug=True)
37
+
38
+ @app.route('/')
39
+ def index(req):
40
+ return {"message": "Welcome to MicroWeb API!"}
41
+
42
+ app.run()
43
+ ```
44
+
45
+ **Comparison: Raw MicroPython Web Server Example for ESP32**
46
+
47
+ For reference, here's how a basic web server looks using only MicroPython's built-in libraries on ESP32:
48
+
49
+ ```python
50
+ import network
51
+ import socket
52
+
53
+ ap = network.WLAN(network.AP_IF)
54
+ ap.active(True)
55
+ ap.config(essid='ESP32-AP', password='12345678')
56
+
57
+ addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
58
+ s = socket.socket()
59
+ s.bind(addr)
60
+ s.listen(1)
61
+
62
+ print('listening on', addr)
63
+
64
+ while True:
65
+ cl, addr = s.accept()
66
+ print('client connected from', addr)
67
+ request = cl.recv(1024)
68
+ response = """\
69
+ HTTP/1.1 200 OK
70
+
71
+ Hello from ESP32 MicroPython!
72
+ """
73
+ cl.send(response)
74
+ cl.close()
75
+ ```
76
+
77
+ With MicroWeb, you get routing, templates, JSON, static files, and more—making web development on ESP32 much easier compared to the raw socket approach above.
78
+
79
+ ---
80
+ ## Table of Contents
81
+
82
+ - [Features](#features)
83
+ - [Installation](#installation)
84
+ - [Usage](#usage)
85
+ - [Flashing the ESP32](#flashing-the-esp32)
86
+ - [Running a Custom Application](#running-a-custom-application)
87
+ - [Example Usage](#example-usage)
88
+ - [Minimal Example (`tests/2/app.py`)](#minimal-example-tests2apppy)
89
+ - [Static Files and Templates Example (`tests/1/app.py`)](#static-files-and-templates-example-tests1apppy)
90
+ - [Wi-Fi Configuration](#wi-fi-configuration)
91
+ - [Accessing the Web Server](#accessing-the-web-server)
92
+ - [CLI Tool Usage Examples](#cli-tool-usage-examples)
93
+ - [ Feature Updates ](#feature-updates)
94
+ - [Project Structure](#project-structure)
95
+ - [Troubleshooting](#troubleshooting)
96
+ - [Contributing](#contributing)
97
+ - [License](#license)
98
+
99
+
100
+
101
+ ## Features
102
+
103
+ - **Dynamic Routing**: Define routes like `@app.route('/welcome/<name>')` for flexible URL handling.
104
+ - **Wi-Fi Configuration**: Configure Wi-Fi via constructor parameters, an `internet` dictionary, or a web interface, with settings saved to `config.json`.
105
+ - **Query Parameters and POST Handling**: Support for URL query strings and form/JSON POST requests.
106
+ - **JSON Responses**: Return JSON data with customizable HTTP status codes.
107
+ - **Static File Serving**: Serve HTML, CSS, and other files from `static/`.
108
+ - **CLI Tools**: Flash MicroPython, upload, and run scripts with validation and auto-detection.
109
+ - **MicroPython Detection**: Verifies MicroPython before running scripts.
110
+ - **Easy Cleanup**: Remove all files from the ESP32 home directory using `microweb remove --port COM10 --remove`—try this if you need to reset or clean up your device.
111
+
112
+ ![uml](/uml.svg)
113
+
114
+ ---
115
+ ## Installation
116
+
117
+ You can install MicroWeb using pip (for the CLI and development tools):
118
+
119
+ ```bash
120
+ pip install microweb
121
+ ```
122
+
123
+ Or, to use the latest source code, clone the repository from GitHub:
124
+ ```bash
125
+ git clone https://github.com/ishanoshada/Microweb.git
126
+ cd Microweb
127
+ python -m venv venv
128
+ source venv/bin/activate # On Windows use: venv\Scripts\activate
129
+ pip install .
130
+ ```
131
+
132
+ > **Note:** The workspace does not contain a git repository. If you want to contribute or track changes, initialize one with `git init`.
133
+
134
+ ---
135
+
136
+ ## Usage
137
+
138
+ ### Flashing the ESP32
139
+
140
+ Flash MicroPython and MicroWeb:
141
+
142
+ ```bash
143
+ microweb flash --port COM10
144
+ ```
145
+
146
+ - Erases the ESP32 flash (if `--erase` is used).
147
+ - Uploads core files (`boot.py`, `main.py`, `microweb.py`, `wifi.py`, and all static files).
148
+
149
+ ---
150
+
151
+ ### Running a Custom Application
152
+
153
+ Upload and run a MicroPython script:
154
+
155
+ ```bash
156
+ microweb run app.py --port COM10
157
+ ```
158
+
159
+ After running `app.run()`, the ESP32 will host a Wi-Fi access point (AP) if it cannot connect to a configured network. You can then connect your device to this AP and access the web server using the ESP32's IP address (typically `http://192.168.4.1` in AP mode).
160
+
161
+
162
+ - Validates the `.py` file and checks for MicroPython.
163
+ - Uploads and executes the script.
164
+ - Prompts to run `microweb flash` if MicroPython is not detected.
165
+
166
+ ---
167
+
168
+ ## Example Usage
169
+
170
+ ### Minimal Example (`tests/2/app.py`)
171
+
172
+ ```python
173
+ from microweb import MicroWeb, Response
174
+
175
+ app = MicroWeb(debug=True, ap={'ssid': 'MyWiFi', 'password': 'MyPassword'})
176
+
177
+ @app.route("/")
178
+ def home(request):
179
+ return Response("Hello from MicroWeb!", content_type="text/plain")
180
+
181
+ @app.route("/json")
182
+ def json_example(request):
183
+ return {"message": "This is JSON"}
184
+
185
+ @app.route("/greet/<name>")
186
+ def greet(req, match):
187
+ name = match.group(1) if match else "Anonymous"
188
+ return {"message": f"Hello, {name}!", "status": "success"}
189
+
190
+ @app.route("/status")
191
+ def status(request):
192
+ return {"status": "OK"}
193
+
194
+ @app.route("/headers")
195
+ def headers_example(request):
196
+ resp = Response("Custom header set!", content_type="text/plain")
197
+ resp.headers["X-Custom-Header"] = "Value"
198
+ return resp
199
+
200
+ if __name__ == "__main__":
201
+ app.run()
202
+ ```
203
+
204
+ ---
205
+
206
+ ### Static Files and Templates Example (`tests/1/app.py`)
207
+
208
+ ```python
209
+ import wifi
210
+ from microweb import MicroWeb
211
+
212
+ app = MicroWeb(debug=True, ap={"ssid": "MyESP32", "password": "mypassword"})
213
+
214
+ @app.route('/')
215
+ def home(req):
216
+ return app.render_template('index.html', message="Welcome to MicroWeb API!")
217
+
218
+ @app.route('/api/status', methods=['GET'])
219
+ def status(req):
220
+ return app.json_response({"status": "running", "ip": wifi.get_ip()})
221
+
222
+ @app.route('/api/echo', methods=['POST'])
223
+ def echo(req):
224
+ data = req.form
225
+ return app.json_response({"received": data})
226
+
227
+
228
+ @app.route('/api/methods', methods=['GET', 'POST'])
229
+ def methods(req):
230
+ if req.method == 'GET':
231
+ return app.json_response({"method": "GET", "message": "This is a GET request"})
232
+ elif req.method == 'POST':
233
+ data = req.json()
234
+ return app.json_response({"method": "POST", "received": data})
235
+
236
+
237
+ @app.route('/submit', methods=['GET', 'POST'])
238
+ def submit_form(req):
239
+ if req.method == 'POST':
240
+ return app.render_template('result.html', data=str(req.form), method="POST")
241
+ else:
242
+ return app.render_template('form.html')
243
+
244
+ app.add_static('/style.css', 'style.css')
245
+ app.run()
246
+ ```
247
+
248
+ #### Example Static Files (`tests/1/static/`)
249
+
250
+ - `index.html`: Main page with API demo and buttons.
251
+ - `form.html`: Simple HTML form for POST testing.
252
+ - `result.html`: Displays submitted form data.
253
+ - `style.css`: Enhanced styling for the test app.
254
+
255
+ ---
256
+
257
+ ## Wi-Fi Configuration
258
+
259
+ Configure Wi-Fi via:
260
+
261
+ - Parameters: `MicroWeb(ssid='MyWiFi', password='MyPassword')`
262
+
263
+ If no credentials are provided, loads `config.json`. If connection fails, starts an access point (default: SSID `ESP32-MicroWeb`, password `12345678`).
264
+
265
+ ---
266
+
267
+ ## Accessing the Web Server
268
+
269
+ - Connect to the ESP32’s Wi-Fi (default: `ESP32-MicroWeb`/`12345678` in AP mode or the configured network).
270
+ - Access `http://<ESP32-IP>/` (e.g., `http://192.168.4.1` in AP mode).
271
+ - Use the control panel to update Wi-Fi, test routes, or submit forms.
272
+
273
+ ---
274
+ ## CLI Tool Usage Examples
275
+
276
+ The following table summarizes common `microweb` CLI commands. See also: #changes.
277
+
278
+ | Command Example | Description |
279
+ |----------------------------------------------|-----------------------------------------------------------|
280
+ | `microweb exmples ` | Show example commands for using microweb CLI.** |
281
+ | `microweb flash --port COM10` | Flash MicroPython firmware and upload MicroWeb files. |
282
+ | `microweb flash --port COM10 --erase` | Erase ESP32 flash before installing MicroPython. |
283
+ | `microweb run app.py --port COM10` | Upload and run a custom MicroPython script. |
284
+ | `microweb run app.py --check-only` | Check static/template dependencies without uploading. |
285
+ | `microweb run app.py --force` | Force upload all files, even if unchanged. |
286
+ | `microweb run app.py --add-boot` | Uploads a `boot.py` to auto-run your app on boot. |
287
+ | `microweb run app.py --remove-boot` | Removes `boot.py` from the ESP32. |
288
+ | `microweb run app.py --static static/` | Specify a custom static files folder. |
289
+ | `microweb run app.py --no-stop` | Do not reset ESP32 before running the app. |
290
+ | `microweb run app.py --timeout 600` | Set a custom timeout (in seconds) for app execution. |
291
+ | `microweb remove --port COM10` | List files on ESP32 (requires `--remove` to actually delete). |
292
+ | `microweb remove --port COM10 --remove` | Remove all files in ESP32 home directory. |
293
+
294
+ **Notes:**
295
+ - `microweb flash` auto-detects the ESP32 port if not specified.
296
+ - `microweb run` validates dependencies, uploads only changed files by default, and can manage static/template files.
297
+ - Use `--help` with any command for more options and details.
298
+
299
+ For more details, run `microweb --help`.
300
+
301
+
302
+ ---
303
+
304
+ ### Feature Updates
305
+
306
+ - Improved CLI usability and error messages.
307
+ - Added support for static file serving and template rendering.
308
+ - Enhanced Wi-Fi configuration with fallback AP mode.
309
+ - Added validation for MicroPython firmware before running scripts.
310
+ - CLI now supports file cleanup and dependency checking.
311
+ - Auto-detects ESP32 port for flashing and running.
312
+ - Added support for custom HTTP headers and JSON responses.
313
+ - Improved documentation and usage examples.
314
+ - Support for GET, POST, and custom HTTP methods in route handlers.
315
+ - Static and template file hot-reloading for faster development.
316
+ - Built-in JSON and form data parsing for request bodies.
317
+ - Customizable AP SSID/password and web-based Wi-Fi setup page.
318
+ - CLI options for forced upload, boot script management, and static directory selection.
319
+ - Enhanced error handling and troubleshooting guidance.
320
+ - Modular project structure for easier extension and maintenance.
321
+
322
+
323
+ ## Project Structure
324
+
325
+ ```
326
+ microweb/
327
+ ├── microweb/
328
+ │ ├── __init__.py
329
+ │ ├── microweb.py
330
+ │ ├── wifi.py
331
+ │ ├── uploader.py
332
+ │ ├── cli.py
333
+ │ ├── firmware/
334
+ │ │ ├── ESP32_GENERIC-20250415-v1.25.0.bin
335
+ │ │ ├── boot.py
336
+ │ │ ├── main.py
337
+ │ ├── static/
338
+ │ │ ├── index.html
339
+ │ │ ├── style.css
340
+ │ │ ├── welcome.html
341
+ │ │ ├── wifi_updated.html
342
+ ├── setup.py
343
+ ├── README.md
344
+
345
+ ```
346
+
347
+ ---
348
+
349
+ ## Troubleshooting
350
+
351
+ - **Port Issues**: Specify `--port COM10` if auto-detection fails.
352
+ - **MicroPython Missing**: Run `microweb flash`.
353
+ - **Wi-Fi Failure**: Verify credentials or connect to default AP.
354
+ - **File Errors**: Ensure `app.py` and static files exist.
355
+
356
+ ---
357
+
358
+ ## Contributing
359
+
360
+ Fork and submit pull requests at [https://github.com/ishanoshada/microweb](https://github.com/ishanoshada/microweb).
361
+
362
+ ---
363
+
@@ -0,0 +1,13 @@
1
+ microweb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ microweb/cli.py,sha256=RGrSlbzwfxB1SffKrxBcinPzft1L3VzdtTHNNWrxmnQ,27065
3
+ microweb/microweb.py,sha256=WlDV1Fk5M4EsvmmkWKVLWaoZh6Vgl9G0qORFsQEQ3iM,12799
4
+ microweb/uploader.py,sha256=EGUXscOAQ0gZJKBaRyAr5XzmxCWhabgh-QO3fBE2a38,3097
5
+ microweb/wifi.py,sha256=S2gOOmTKp2G1uUHxOH0DHQ_k7QSERKHDCm89qv-WlKs,904
6
+ microweb/firmware/ESP32_GENERIC-20250415-v1.25.0.bin,sha256=HrGohHPjKqak1F3BtbatQLwfBhKOeqhUjkOM-kYz2hs,1702240
7
+ microweb/firmware/boot.py,sha256=1522jvxAjGk-y7X4mzMilB4pMQ6KrAgosDXRAMtac8k,22
8
+ microweb/firmware/main.py,sha256=g_rg-1qpQEzvQoSnhXairx_v7xHNuGDJVrmbdziKt1A,10
9
+ microweb-0.1.1.dist-info/METADATA,sha256=R-CD1owSm-Sb3cqX0Rj0ApJmnVzTcpkSP3d3vaW_KGU,12058
10
+ microweb-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ microweb-0.1.1.dist-info/entry_points.txt,sha256=yBGjIy-e3mx-HHkmkGNLBcSDEALB327du5KuauZHmg4,46
12
+ microweb-0.1.1.dist-info/top_level.txt,sha256=CkRcDTo-nv4JTieAZPKFC-EGKYYQmKNq5C8zU2k5zRM,9
13
+ microweb-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ microweb = microweb.cli:cli
@@ -0,0 +1 @@
1
+ microweb