mBlock5 Extension – How to Upload a Custom Python Package to Extension Builder


#1

Normally, I upload my Python files to the device and use them with a simple import my_class statement in my main code.

Now, I’m working with mBlock5 Device Extension (Block Code), and I want to upload my custom package (along with some supporting libraries) to the device and then import them into my block code without showing all the internal code.

The issue is:
I currently have five files — four are library files (not included in the MicroPython firmware), and one is my custom module. Since mBlock5 requires code to be inserted directly into the blocks, I ended up packing everything into a single file, and when I add that into the first block, it turns into 10,000+ lines of messy code:

My question is:
Is there any way to upload these package files separately and use import in the block code without showing the full source code inside the blocks?

Thanks in advance!


#2

@PerfecXX For your very long code, have you uploaded it as a library (in common code settings, I think)? Then you can add an import for it (in your block’s settings) and all people will see is the import and not all the code.


#3

Thanks for the reply!

I saw this message:

“Add external JavaScript library like lodash, or some JS library implementing device protocol, such as Firmata for Arduino; Or you might upload your own JavaScript File (UMD module standard support needed)”

But in my case, my package consists of Python files designed to work as a MicroPython library (most of them are not implemented in CyberPi firmware).

Will it still work the same way if I upload my Python package instead of a JavaScript one?


#4

@PerfecXX Sorry, I got mixed up. You should upload libraries in the Transcode settings tab (scroll to the bottom of it).


#5

If uploading custom js files into the cyberpi work, could you show me how extacly you’ve done, and how does this works pls?


#6

@Idaill You can’t upload JS to CyberPi. I was answering how to upload a Python library to an extension. :slight_smile: