{
  "id": "brainelectronics/micropython-package-template",
  "name": "micropython-package-template",
  "prettyName": "micropython-package-template",
  "description": "MicroPython PyPi package template project with auto deploy",
  "version": "",
  "author": "brainelectronics",
  "license": "MIT",
  "tags": [
    "deploy",
    "micropython",
    "package",
    "pypi-package",
    "template",
    "template-repository"
  ],
  "status": "VALID",
  "official": false,
  "source": "https://github.com/brainelectronics/micropython-package-template",
  "updatedAt": "2026-08-20T07:00:02.200Z",
  "page": "https://checkmim.com/packages/brainelectronics+micropython-package-template",
  "createdAt": "2025-05-27T04:35:47.139Z",
  "submittedBy": "oliverr",
  "install": {
    "mpremote": "mpremote mip install github:brainelectronics/micropython-package-template",
    "mip": "import mip; mip.install(\"github:brainelectronics/micropython-package-template\")"
  },
  "readme": "# MicroPython package template\n\n[![Downloads](https://pepy.tech/badge/micropython-package-template)](https://pepy.tech/project/micropython-package-template)\n![Release](https://img.shields.io/github/v/release/brainelectronics/micropython-package-template?include_prereleases&color=success)\n![MicroPython](https://img.shields.io/badge/micropython-Ok-green.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/github/brainelectronics/micropython-package-template/branch/main/graph/badge.svg)](https://app.codecov.io/github/brainelectronics/micropython-package-template)\n[![CI](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml/badge.svg)](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml)\n![Humans](https://img.shields.io/badge/Created_by-Humans-blue?style=flat\n)\n\nMicroPython (PyPI) package template project with auto deploy\n\n---------------\n\n## General\n\nMicroPython (PyPI) package template with GitHub Action based testing and deploy\n\n📚 The latest documentation is available at\n[MicroPython Package Template ReadTheDocs][ref-rtd-micropython-package-template] 📚\n\n<!-- MarkdownTOC -->\n\n- [Installation](#installation)\n\t- [Install required tools](#install-required-tools)\n- [Setup](#setup)\n\t- [Install package from the web](#install-package-from-the-web)\n\t\t- [General](#general)\n\t\t- [Specific version](#specific-version)\n\t\t- [Test version](#test-version)\n\t- [Manually](#manually)\n\t\t- [Upload files to board](#upload-files-to-board)\n\t\t\t- [mpremote](#mpremote)\n\t\t\t- [rshell](#rshell)\n- [Usage](#usage)\n- [Create a PyPI \\(micropython\\) package](#create-a-pypi-micropython-package)\n\t- [Setup](#setup-1)\n\t- [Create a distribution](#create-a-distribution)\n\t- [Upload to PyPI](#upload-to-pypi)\n- [Contributing](#contributing)\n\t- [Unittests](#unittests)\n- [Steps after using this template](#steps-after-using-this-template)\n- [Credits](#credits)\n\n<!-- /MarkdownTOC -->\n\n## Installation\n\n### Install required tools\n\nPython3 must be installed on your system. Check the current Python version\nwith the following command\n\n```bash\npython --version\npython3 --version\n```\n\nDepending on which command `Python 3.x.y` (with x.y as some numbers) is\nreturned, use that command to proceed.\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\n\n# to interact with a MicroPython board\npip install -r requirements.txt\n\n# to run all tests or contribute to this repo\npip install -r requirements-test.txt\n\n# to create and deploy a new version of this package\npip install -r requirements-deploy.txt\n```\n\n## Setup\n\n### Install package from the web\n\nConnect the MicroPython device to a network, otherwise check the section [Manually](#manually) down below.\n\n```python\nimport network\nstation = network.WLAN(network.STA_IF)\nstation.active(True)\nstation.connect('SSID', 'PASSWORD')\nstation.isconnected()\n```\n\n#### General\n\nInstall the latest package version of this lib on the MicroPython device\n\n```python\nimport mip\nmip.install(\"github:brainelectronics/micropython-package-template\")\n```\n\nFor MicroPython versions below `1.19.1` use the `upip` package instead of `mip`\n\n```python\nimport upip\nupip.install('micropython-package-template')\n```\n\nRun this code on the MicroPython device to check the used MicroPython version\n\n```python\ntry:\n    from os import uname\nexcept ImportError:\n    # u-packages might be deprecated in future\n    from uos import uname\nos.uname().version\n```\n\n#### Specific version\n\nInstall a specific, fixed package version of this lib on the MicroPython device\n\n```python\nimport mip\n# install a verions of a specific branch\nmip.install(\"github:brainelectronics/micropython-package-template\", version=\"feature/initial-implementation\")\n# install a tag version\nmip.install(\"github:brainelectronics/micropython-package-template\", version=\"0.6.0\")\n\n# install pre-compiled package\nmip.install(\"github:brainelectronics/micropython-package-template/package_mpy.json\")\nmip.install(\"github:brainelectronics/micropython-package-template/package_mpy.json\", version=\"feature/provide-mpy-cross-files\")\nmip.install(\"github:brainelectronics/micropython-package-template/package_mpy.json\", version=\"0.15.0\")\n```\n\nFor MicroPython versions below `1.19.1` use the `upip` package instead of `mip`.\n⚠️ There are no pre-compiled `.mpy` packages available.\n\n```python\nimport upip\nupip.install('micropython-package-template==0.12.0')\n```\n\n#### Test version\n\nInstall a specific release candidate version uploaded to\n[Test Python Package Index](https://test.pypi.org/) on every PR on the\nMicroPython device. If no specific version is set, the latest stable version\nwill be used.\n\n```python\nimport mip\nmip.install(\"github:brainelectronics/micropython-package-template\", version=\"0.6.0-rc9.dev13\")\nmip.install(\"github:brainelectronics/micropython-package-template/package_mpy.json\", version=\"0.15.0-rc5.dev37\")\n```\n\nFor MicroPython versions below `1.19.1` use the `upip` package instead of `mip`.\nIf no specific version is set, `upip` will always install the latest available version.\n⚠️ There are no pre-compiled `.mpy` packages available.\n\n```python\nimport upip\n# overwrite index_urls to only take artifacts from test.pypi.org\nupip.index_urls = ['https://test.pypi.org/pypi']\nupip.install('micropython-package-template')\n\n# install a specific version\nupip.install(\"micropython-package-template==0.12.0rc37.dev29\")\n```\n\nSee also [brainelectronics Test PyPI Server in Docker][ref-brainelectronics-test-pypiserver]\nfor a test PyPi server running on Docker.\n\n### Manually\n\nSee [Install required tools](#install-required-tools) section on how to install the tools used onwards.\n\n#### Upload files to board\n\nCopy the module to the MicroPython board and import them as shown below\nusing [mpremote][ref-mpremote] or [Remote MicroPython shell][ref-remote-upy-shell].\n\n##### mpremote\n\n`mpremote` will auto-detect the MicroPython device. Check the [mpremote][ref-mpremote] documentation for further details.\n\n```bash\nmpremote fs mkdir :/lib\nmpremote fs cp -rf be_upy_blink/*.py :/lib/\nmpremote fs cp -f examples/boot.py examples/main.py :\nmpremote fs ls :\n```\n\nOr use the latest package files as defined in the `package.json` or `package_mpy.json` file from remote or as part of this repo\n\n```bash\n# install files as defined in (default) package.json\nmpremote mip install package.json\n\n# install *.mpy files as defined in \"package_mpy.json\" on tag \"0.15.0-rc5.dev37\"\nmpremote mip install github:brainelectronics/micropython-package-template/package_mpy.json@0.15.0-rc5.dev37\n```\n\n##### rshell\n\nOpen the remote shell with the following command. Additionally use `-b 115200`\nin case no `CP210x` USB to UART bridge is used but a `CH34x`.\n\n```bash\nrshell --port /dev/tty.SLAB_USBtoUART --editor nano\n```\n\nPerform the following command inside the `rshell` to copy all files and\nfolders to the device\n\n```bash\nmkdir /pyboard/lib\nmkdir /pyboard/lib/be_upy_blink\n\ncp be_upy_blink/* /pyboard/lib/be_upy_blink\n\ncp examples/main.py /pyboard\ncp examples/boot.py /pyboard\n```\n\n## Usage\n\nThis is just a very lightweight MicroPython package template with a minimal functional library.\n\n```python\nfrom be_upy_blink import flash_led\nfrom machine import Pin\ntry:\n    from os import uname\nexcept ImportError:\n    from uos import uname\n\nos_info = uname()\n\nif 'pyboard' in os_info:\n\tled_pin = Pin(1, Pin.OUT)\nelif 'esp8266' in os_info:\n\tled_pin = Pin(2, Pin.OUT)\nelif 'esp32' in os_info:\n\tled_pin = Pin(2, Pin.OUT)\nelif 'rp2' in os_info:\n\t# RP2 has the LED on pin 25, Pico W on a custom pin routed to \"LED\"\n\tled_pin = Pin(\"LED\", Pin.OUT)\nelse:\n\traise Exception(\"Unknown board, manually set pin here\")\n\nflash_led(pin=led_pin, amount=3)\n# flash_led(pin=led_pin, amount=3, on_time=1, off_time=3)\n```\n\n## Create a PyPI (micropython) package\n\n### Setup\n\nInstall the required python package with the following command in a virtual\nenvironment to avoid any conflicts with other packages installed on your local\nsystem.\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\n\npip install twine\n```\n\n### Create a distribution\n\nThis module overrides distutils (also compatible with setuptools) `sdist`\ncommand to perform pre- and post-processing as required for MicroPython's\nupip package manager. This script is taken from\n[pfalcon's picoweb][ref-pfalcon-picoweb-sdist-upip] and updated to be PEP8\nconform.\n\n```bash\npython setup.py sdist\n```\n\nA new folder `dist` will be created. The [`sdist_upip`](sdist_upip.py) will be\nused to create everything necessary.\n\nThe `dist/*.orig` file is the non stripped version of the created package.\nIt contains further files which are necessary for a Python package but not\nrequired by MicroPython board and would use unnecessary flash on the device.\n\n### Upload to PyPI\n\n**Be aware: [pypi.org][ref-pypi] and [test.pypi.org][ref-test-pypi] are different**\n\nYou can **NOT** login to [test.pypi.org][ref-test-pypi] with the\n[pypi.org][ref-pypi] account unless you created the same on the other. See\n[invalid auth help page of **test** pypi][ref-invalid-auth-test-pypi]\n\nFor testing purposes add `--repository testpypi` to\nupload it to [test.pypi.org][ref-test-pypi]\n\n```bash\ntwine check dist/*.tar.gz\ntwine upload dist/micropython-package-template-*.tar.gz -u PYPI_USERNAME -p PYPI_PASSWORD\n```\n\n## Contributing\n\n### Unittests\n\nRun the unittests locally with the following command after installing this\npackage in a virtual environment\n\n```bash\n# create a report directory where all generated report files are placed\npython create_report_dirs.py\n```\n\n```bash\n# run all tests\nnose2 --config tests/unittest.cfg\n\n# run only one specific tests\nnose2 tests.test_blink.TestBlink.test_flash_led\n```\n\nGenerate the coverage files with\n\n```bash\ncoverage html\n```\n\nThe coverage report is placed at `reports/coverage/html/index.html`\n\n## Steps after using this template\n\nIn order to use this template for a new MicroPython package to following steps\nshould be done and changes to these file being made\n\n| File | Changes | More details |\n| ---- | ------- | -------------|\n| `.coveragerc` | Path to `version.py` file | Omit version file from coverage |\n| `.coveragerc` | Path to `include` folder | Include the package folder for coverage |\n| `.github/workflows/release.yml` | Path to `version.py` file | Use package version file to set changelog based version |\n| `.github/workflows/test-release.yml` | Path to `version.py` file | Use package version file to set changelog based version |\n| `.github/workflows/test.yml` | Path to `version.py` file | Use package version file to set changelog based version |\n| `.pre-commit-config.yaml` | Path to `version.py` file | Use package version file for validation against latest changelog based version |\n| `LICENSE.txt` | Year and/or type of license | |\n| `README.md` | Links in header section and installation instructions | |\n| `changelog.md` | Cleanup changelog from informations of template | Keep usage of SemVer |\n| `docs/DOCUMENTATION.md` | Kink to ReadTheDocs | |\n| `docs/conf.py` | List to modules to be mocked, package import, path to `version.py` file, update `author`, `project` and `linkcheck_ignore` | |\n| `docs/index.rst` | Header name and included modules | Replace `be_upy_blink` with new `.rst` file of new package |\n| `docs/NEW_MODULE_NAME.rst` | Create a new `.rst` file  named as the package | Use `docs/be_upy_blink.rst` as template |\n| `package.json` | Files and paths to new package and repo | Used by `mip` |\n| `setup.py` | Path to `version.py` file, `name`, `description`, `url`, `author`, `author_email`, `keywords`, `project_urls`, `packages`, `install_requires` | Used to create the package and its informations published at e.g. PyPI |\n\n## Credits\n\nBased on the [PyPa sample project][ref-pypa-sample].\n\n<!-- Links -->\n[ref-rtd-micropython-package-template]: https://micropython-package-template.readthedocs.io/en/latest/\n[ref-mpremote]: https://docs.micropython.org/en/v1.28.0/reference/mpremote.html\n[ref-remote-upy-shell]: https://github.com/dhylands/rshell\n[ref-brainelectronics-test-pypiserver]: https://github.com/brainelectronics/test-pypiserver\n[ref-pypa-sample]: https://github.com/pypa/sampleproject\n[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py\n[ref-test-pypi]: https://test.pypi.org/\n[ref-pypi]: https://pypi.org/\n[ref-invalid-auth-test-pypi]: https://test.pypi.org/help/#invalid-auth\n"
}