ImportError: can't import name hub

Micropython is throwing this exception when I attempt to use the fluent API. I am importing as follows:

import notecard
from notecard import hub

I am not importing the notecard module in any other source files, so I don’t believe this is a circular reference issue. Any ideas?

Odd, I just ran this locally and it worked fine with me. note-python v1.3.1

>>> import notecard
>>> from notecard import hub

>>> hub.set
<function set at 0x10c672d30>

>>> dir(hub)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'get', 'log', 'notecard', 'set', 'status', 'sync', 'syncStatus', 'validate_card_object']

Can you share more details about the error you are getting? And is this on an ESP32, or another device?

Device is ESP32, this is what I’m seeing from the REPL:

MicroPython v1.14 on 2021-02-02; ESP32 module with ESP32
Type "help()" for more information.
>>> import notecard
>>> from notecard import hub
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: can't import name hub
>>> 

This is the note-python I have

c:\dev\projects\micropython\note-python>git show
commit 9e03c80f6c12f000ad6d5e152ca0215aae3a3a56 (HEAD -> master, tag: v1.3.0, origin/master, origin/HEAD)
Author: Brandon Satrom <bsatrom+gh@gmail.com>
Date:   Thu Jan 28 15:11:40 2021 -0600

    bump v1.2.2 -> v1.3.0

I pushed an update yesterday, but I don’t think it would fix this. Can you update to 1.3.1 and try though?

In the meantime, I will try to repro on an ESP32. I don’t have one on hand and the moment, but I should be able to try this weekend.

Hey @ec123 I haven’t forgotten about this, by my apologies for the delay. Assuming you are still seeing this issue, I will try to grab an ESP32 and look today.

Not sure I did the correct thing, but got it to work by changing the import in my source file to:

import notecard
import hub

and then had to remove the dot (.) from before validators here:

from validators import validate_card_object

and also add functools.py to the lib folder. After that, it works.

Ah, that looks like a bug unique to the MicroPython environment. Thanks for the additional context. Glad you found a workaround, and I’ll see about getting a proper fix into the library.

Thanks again for flagging these issues ed. I can throw a fix in for the validators issue specific to MicroPython and will push that along with some fixes that @gwolff just submitted.

For functools, you should actually be able to get it in MicroPython with upip install functools rather than manually copying it into the lib directory. Did you try that?

Update: Just published v1.3.2 with these fixes. GitHub - blues/note-python: Python API for Notecard