Skip to content

python-ecosys/uminio: Add uminio package.#1040

Open
paluigi wants to merge 2 commits into
micropython:masterfrom
paluigi:uminio
Open

python-ecosys/uminio: Add uminio package.#1040
paluigi wants to merge 2 commits into
micropython:masterfrom
paluigi:uminio

Conversation

@paluigi

@paluigi paluigi commented Aug 4, 2025

Copy link
Copy Markdown

uminio is a MicroPython client for MinIO object storage.
This commit add the uminio folder and all its content in the python-ecosys folder.
Original implementation for AWS S3:
https://github.com/DanielMilstein/uboto3/

uminio is a MicroPython client for MinIO object storage.
This commit add the uminio filder and all its content in
the python-ecosys folder.
Original implementation for AWS S3:
https://github.com/DanielMilstein/uboto3/

Signed-off-by: Luigi Palumbo <paluigi@gmail.com>
@paluigi

paluigi commented Aug 4, 2025

Copy link
Copy Markdown
Author

I tried to figure our why the lint/formatting fails...but I'm lost.

@dpgeorge

dpgeorge commented Aug 4, 2025

Copy link
Copy Markdown
Member

If you look here: https://github.com/micropython/micropython-lib/actions/runs/16717239939/job/47313198532?pr=1040 it shows you the problems. Basically you need to put a few things on one line, instead of over many lines.

This commit remove redundant lines and correct formatting
for code in python-ecosys/uminio/uminio/__init__.py.

Signed-off-by: Luigi Palumbo <paluigi@gmail.com>
@paluigi

paluigi commented Aug 4, 2025

Copy link
Copy Markdown
Author

Thanks, code formatted!

@agatti agatti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I've had a quick look at the code and there are a couple of places where I believe this could be improved. It could also help if you'd squash the two commits into just one, since the second one is just minor changes to the source formatting.

Comment on lines +9 to +12
import urequests
import uhashlib
import ubinascii
import utime

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most, if not all, of these imports can now be accessed without the u prefix.

k_signing_bytes = self._hmac_sha256(k_service_bytes, b"aws4_request")
return k_signing_bytes

def sync_time(self) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If knowing the current time as retrieved by the NTP server is important, this function could be changed to return the time.gmtime() tuple instead.

Synchronizes the device's real-time clock with an NTP server.
This is crucial for generating a valid signature.
"""
print("Synchronizing time with NTP server...")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these print() statements could be taken out. Same applies to upload_file too.

now_utc[5],
)
)
except Exception as e:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd let the exception propagate rather than ignoring it here.

If the lack of exception propagation is critical then this bit could be either a simple pass statement or, if the function was modified to return the new timestamp, make it return None instead.

:param content_type: The MIME type of the file.
:return: True if upload was successful (HTTP 200), False otherwise.
"""
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These exceptions could also be let to propagate (file I/O and network). As far as I can see there's no recovery mechanism besides a print statement and returning a value, that can be handled by catching the exception upstream.

It also saves quite some space when compiled into bytecode :)

signed_headers_list.append(key)
signed_headers_str = ";".join(signed_headers_list)

canonical_request = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are all guaranteed to be strings, "\n".join(method, canonical_uri, canonical_querystring, canonical_headers_str, signed_headers_str, payload_hash_hex) is actually shorter by ~19 bytes when compiled into bytecode.

Even with "\n".join(map(str, (method, ...))) to pre-convert variables to strings, it is still shorter by 7 bytes.

hashed_canonical_request_bytes
).decode()

string_to_sign = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one could be converted into "\n".join(...) too.


## Usage Example

Here's how to use `uminio` to upload a local file from your MicroPython device to MinIO:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can just point to the example file in the same directory rather than reproducing it verbatim here.

* MicroPython firmware flashed on your device.
* Network connectivity (WiFi) configured on the device.
* The following MicroPython libraries:
* `urequests`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The u prefix for most modules has been deprecated,

But more importantly, they should be part of a manifest.py, rather than just documented.


## Setup

1. **Copy `__init__.py`:** Create a `uminio` folder in the `/lib` directory of your MicroPython device and copy the `__init__.py` file into it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installation for a package should be using mop, not copy

@@ -0,0 +1,3 @@
metadata(version="0.0.1", description="MIcroPython client for MinIO object storage.")

package("uminio")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the preqeq packages mentioned in the readme file?
The should be included in the manifest, so they are installed automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants