diff --git a/micropython/bundles/bundle-networking/manifest.py b/micropython/bundles/bundle-networking/manifest.py index 1db1b08c..79d5e9d9 100644 --- a/micropython/bundles/bundle-networking/manifest.py +++ b/micropython/bundles/bundle-networking/manifest.py @@ -5,5 +5,9 @@ metadata( require("mip") require("ntptime") -require("urequests") +require("requests") require("webrepl") + +# Provide urequests (which just forwards to requests) for backwards +# compatibility. +require("urequests") diff --git a/micropython/mip/manifest.py b/micropython/mip/manifest.py index f6d47e22..00efa545 100644 --- a/micropython/mip/manifest.py +++ b/micropython/mip/manifest.py @@ -1,5 +1,5 @@ metadata(version="0.2.0", description="On-device package installer for network-capable boards") -require("urequests") +require("requests") package("mip", opt=3) diff --git a/micropython/mip/mip/__init__.py b/micropython/mip/mip/__init__.py index 0593e2e0..5f6f4fcd 100644 --- a/micropython/mip/mip/__init__.py +++ b/micropython/mip/mip/__init__.py @@ -1,7 +1,7 @@ # MicroPython package installer # MIT license; Copyright (c) 2022 Jim Mussared -import urequests as requests +import requests import sys diff --git a/micropython/urequests/README.md b/micropython/urequests/README.md new file mode 100644 index 00000000..f6612b35 --- /dev/null +++ b/micropython/urequests/README.md @@ -0,0 +1,9 @@ +## urequests compatibility + +The MicroPython version of +[requests](https://requests.readthedocs.io/en/latest/) was previously called +`urequests` and a lot of existing code depends on being able to still +import the module by that name. + +This package provides a wrapper to allow this. Prefer to install and use the +`requests` package instead. diff --git a/micropython/urequests/manifest.py b/micropython/urequests/manifest.py new file mode 100644 index 00000000..3fbe61c2 --- /dev/null +++ b/micropython/urequests/manifest.py @@ -0,0 +1,5 @@ +metadata(version="0.8.0", pypi="requests") + +require("requests") + +module("urequests.py") diff --git a/micropython/urequests/urequests.py b/micropython/urequests/urequests.py new file mode 100644 index 00000000..227a1ae5 --- /dev/null +++ b/micropython/urequests/urequests.py @@ -0,0 +1,8 @@ +# This module provides a backwards-compatble import for `urequests`. +# It lazy-loads from `requests` without duplicating its globals dict. + + +def __getattr__(attr): + import requests + + return getattr(requests, attr) diff --git a/python-ecosys/requests/README.md b/python-ecosys/requests/README.md new file mode 100644 index 00000000..d6ceaadc --- /dev/null +++ b/python-ecosys/requests/README.md @@ -0,0 +1,16 @@ +## requests + +This module provides a lightweight version of the Python +[requests](https://requests.readthedocs.io/en/latest/) library. + +It includes support for all HTTP verbs, https, json decoding of responses, +redirects, basic authentication. + +### Limitations + +* Certificate validation is not currently supported. +* A dictionary passed as post data will not do automatic JSON or + multipart-form encoding of post data (this can be done manually). +* Compressed requests/responses are not currently supported. +* File upload is not supported. +* Chunked encoding in responses is not supported. diff --git a/python-ecosys/urequests/example_xively.py b/python-ecosys/requests/example_xively.py similarity index 80% rename from python-ecosys/urequests/example_xively.py rename to python-ecosys/requests/example_xively.py index 88b890cb..60e139b9 100644 --- a/python-ecosys/urequests/example_xively.py +++ b/python-ecosys/requests/example_xively.py @@ -1,7 +1,4 @@ -try: - import urequests as requests -except ImportError: - import requests +import requests r = requests.get("http://api.xively.com/") print(r) diff --git a/python-ecosys/requests/manifest.py b/python-ecosys/requests/manifest.py new file mode 100644 index 00000000..7fc2d63b --- /dev/null +++ b/python-ecosys/requests/manifest.py @@ -0,0 +1,3 @@ +metadata(version="0.8.0", pypi="requests") + +package("requests") diff --git a/python-ecosys/urequests/urequests.py b/python-ecosys/requests/requests/__init__.py similarity index 100% rename from python-ecosys/urequests/urequests.py rename to python-ecosys/requests/requests/__init__.py diff --git a/python-ecosys/urequests/manifest.py b/python-ecosys/urequests/manifest.py deleted file mode 100644 index 4c134081..00000000 --- a/python-ecosys/urequests/manifest.py +++ /dev/null @@ -1,3 +0,0 @@ -metadata(version="0.7.0", pypi="requests") - -module("urequests.py")