MICROPYTHON WITH THE ESP32 GUIDE SERIES

Find Python Packages At PyPI

PyPi is a repository of Python and MicroPython packages. You can search PyPi from Thonny IDE and install packages with a single click. In this lesson I'll show you how.

The Thonny PyPi tool

You can install a Python package directly from the Thonny ID user interface.

You will find the PyPi search and installation tool under Tools, Manage Packages.

Example 1: search, find, install a MicroPython package

PyPi contains thousands of Python packages. Only some of them are specifically written in MicroPython. Most MicroPython packages are written to be compatible with a specific microcontroller, like the ESP32 or the Micro:bit. 

You need to be mindful of this, and take care so that the package that you eventually download to your Thonny is actually compatible with your target device.

I'll show you an example of how to do this.

Let's start with a very broad search on the term "MicroPython" directly on the PyPi website. This search will return any packages that contain the term "MicroPython". 

A generic search on PyPi for the term "MicroPython" returns 884 projects.

As you can see there are almost a thousand project that contain this name, I am not familiar with any of the projects showing in the first page of the list.

I'll pick one randomly to take a closer look, from page two of the list.

The "lucky" project is titled "micropython-selectors 0.0.1".

I found this package in PyPi. Looks intersting. Let's install it in Thonny.

Let's say that this is a package that you would like to use in your MicroPython project. The next thing to do is to download it and install it in Thonny.

Copy the name, go to Thonny, bring up the Manage Packages window (under "Tools"), and copy the package name in the search field.

Search for a package in PyPi by name.

Click on the package name to see more informatio, then click on Install.

In the list of results, you'll find the package with the name you searched for at the top. Click on the package hyperlink to get to the package information page. Click on the Install button to download and install the package. 

A few seconds later, you'll see the package listed in the left-side packages list.

The installed packages appear in the list on the left of the Manage Packages window.

Example 2: search for a specific MicroPython package (gives error)

Let's look at another example. Unlike the previous generic search, now I'd like to be somewhat more specific. Let's look for a MicroPython package that is compatible with the ESP32.

Let's try this search term: "MicroPython dht ESP32". 

With this search I hope to find a DHT11 or DHT22 MicroPython driver for the ESP32.

Do the search in PyPi.org and take a minute to look at the results. 

A search for "micropython dht esp32".

Because MicroPython can be used across a lot of different hardware targets, not all the package search results will be compatible with the target you intend to use. However, ESP23 and ESP8266 are (generally) cross-compatible when it comes to MicroPython. So, in general, if you find a package that is marked to be compatible with the ESP8266, chances are that the package will also work with the ESP32.

In the result list for the term "micropython dht esp32", there are several hits. One that drew my interest is titled "micropython-wifimanager".

This package looks interesting, and is compatible with both ESP32 and ESP8266.

Let's install this package in Thonny.

Follow the exact same process as with example 1. Copy the package name into the Thonny package manager tool, and click on the "Install" button.

Unfortunately, the installation failed for me at the time I was writing this guide (it may work for you).

This package cannot be installed in Thonny.

I am not sure why the installation failed, but the error message suggest a problem with the configuration of the package itself, and not Thonny.

This is unfortunate, but not the end of the world.

Let's try something else.

Example 3: esp32-net-config

An interesting package is titled "esp32-net-config". It creates a local WiFi access point so that you can configure a hot-spot SSID and password without having to hard-wire this information on your ESP32.

Install it as you did with examples 1 and 2. The package contains several files, that will be listed in the left text box:

The "esp32-net-config" package consists of several files.

Close the package manager, and look at the file browser of the ESP32 target device in the left bottom corner of the Thonny IDE. Inside the lib directory you can see the files that make up the package you just installed.

Click on the config.py file (or any of the other files, if you prefer), to look inside.

The contents of the config.py file, and the files that make up the "esp32-net-config" package listed in the ESP32 file browser.

If you want to curious to learn how to use this package, you can have a look at the information in the project's GitHub repository which contains instructions and examples.

These were three simple examples of how you can find, install, and inspect MicroPython packages available in the PyPi repository.

Learn MicroPython for the ESP32

With this video course, you will learn how to use the
MicroPython programming language with the ESP32 micro-controller.


MicroPython is the perfect language for anyone looking for the easiest (yet still powerful) way to program a micro-controller.

We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community. One email per week, no spam; unsubscribe at any time

Image
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}