Skip to content

Commit 8513bfb

Browse files
jimmodpgeorge
authored andcommitted
requests: Rename urequests to requests.
This module implements a subset of the Python requests module, and so it should have the same name. Added a backwards-compatibility wrapper to allow people to continue to use `import urequests`. This lives in micropython/urequests. Changed requests to be a package, so that we can implement extension packages in the future for optional functionality. Added a basic README.md to both. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 5004436 commit 8513bfb

File tree

11 files changed

+49
-10
lines changed

11 files changed

+49
-10
lines changed

micropython/bundles/bundle-networking/manifest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55

66
require("mip")
77
require("ntptime")
8-
require("urequests")
8+
require("requests")
99
require("webrepl")
10+
11+
# Provide urequests (which just forwards to requests) for backwards
12+
# compatibility.
13+
require("urequests")

micropython/mip/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
metadata(version="0.2.0", description="On-device package installer for network-capable boards")
22

3-
require("urequests")
3+
require("requests")
44

55
package("mip", opt=3)

micropython/mip/mip/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MicroPython package installer
22
# MIT license; Copyright (c) 2022 Jim Mussared
33

4-
import urequests as requests
4+
import requests
55
import sys
66

77

micropython/urequests/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## urequests compatibility
2+
3+
The MicroPython version of
4+
[requests](https://requests.readthedocs.io/en/latest/) was previously called
5+
`urequests` and a lot of existing code depends on being able to still
6+
import the module by that name.
7+
8+
This package provides a wrapper to allow this. Prefer to install and use the
9+
`requests` package instead.

micropython/urequests/manifest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
metadata(version="0.8.0", pypi="requests")
2+
3+
require("requests")
4+
5+
module("urequests.py")

micropython/urequests/urequests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This module provides a backwards-compatble import for `urequests`.
2+
# It lazy-loads from `requests` without duplicating its globals dict.
3+
4+
5+
def __getattr__(attr):
6+
import requests
7+
8+
return getattr(requests, attr)

python-ecosys/requests/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## requests
2+
3+
This module provides a lightweight version of the Python
4+
[requests](https://requests.readthedocs.io/en/latest/) library.
5+
6+
It includes support for all HTTP verbs, https, json decoding of responses,
7+
redirects, basic authentication.
8+
9+
### Limitations
10+
11+
* Certificate validation is not currently supported.
12+
* A dictionary passed as post data will not do automatic JSON or
13+
multipart-form encoding of post data (this can be done manually).
14+
* Compressed requests/responses are not currently supported.
15+
* File upload is not supported.
16+
* Chunked encoding in responses is not supported.

python-ecosys/urequests/example_xively.py renamed to python-ecosys/requests/example_xively.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
try:
2-
import urequests as requests
3-
except ImportError:
4-
import requests
1+
import requests
52

63
r = requests.get("http://api.xively.com/")
74
print(r)

python-ecosys/requests/manifest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
metadata(version="0.8.0", pypi="requests")
2+
3+
package("requests")

python-ecosys/urequests/manifest.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)