Import Python libraries and packages

The plugin allows the import of specific libraries and packages in your project to extend the functionality of the Digi Python/MicroPython API within the device. Depending on the target platform you choose, you can import XBee MicroPython libraries for XBee modules, or Python packages for other Digi devices such as gateways, routers or ConnectCore modules.

XBee MicroPython libraries

The XBee MicroPython libraries are modules that Digi writes or modifies to address differences between XBee and other MicroPython platforms. There are two possible ways to import an XBee MicroPython library:

When creating a new MicroPython project using the New Digi project wizard, its third step allows the selection of the libraries for the project. Once the project is created, libraries are copied to the lib project folder and the library imports are automatically added to the main.py file.

Once a project is created, you can import one or more XBee MicroPython libraries. Use these steps:

  1. Select the Digi > Import Libraries menu option to open the Import Libraries dialog.
  2. Select the libraries you want to import and click OK.

Note Libraries are filtered to list only those compatible with the XBee platform selected when creating the XBee MicroPython project. If you want to see all the available libraries select Show non compatible libraries option.

  1. Libraries are copied to the lib folder of the project and the library imports are automatically added to file main.py.

Python packages

When working with a Digi Python project, you can add and use any standard Python package from the Python Package Index (PyPI) which is compatible with your target device. To do so:

  1. Create a file called requirements.txt in the root folder of your project—if not already created.

  2. Add the desired Python packages to the file, one per line.

  3. If they are not already installed on your local Python environment, PyCharm asks you to install them. Click Install requirements.

Note Packages are installed on the target device when you launch the application, so the device must have access to the Internet at that moment.