Command Line Interface

The stubber command line interface provides a comprehensive set of tools for generating and managing MicroPython {ref}`type stubs <type-stub>`.

stubber

stubber [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...

Options

--version

Show the version and exit.

-V, --verbose

-V for DEBUG, -VV for TRACE

build

Commandline interface to publish stubs.

stubber build [OPTIONS]

Options

--family <family>
Default:

'micropython'

-V, --version, --Version <versions>

MicroPython version to build, or ‘preview’ for the latest preview version

Default:

'v1.28.0'

-p, --port <ports>

multiple:

Default:

'all'

-b, --board <boards>

multiple:

Default:

'GENERIC'

--clean

clean folders after processing and publishing

--force

build package even if no changes detected

clone

Clone/fetch the micropython repos locally.

The local repos are used to generate frozen-stubs and doc-stubs.

Use –mpy-repo to specify a custom MicroPython repository (e.g., your fork). Use –mpy-lib-repo to specify a custom MicroPython-lib repository.

stubber clone [OPTIONS]

Options

-p, --path <path>
--stubs, --add-stubs, --no-stubs, --no-stubs

Also clone the micropython-stubs repo

--mpy-repo <mpy_repo>

URL for MicroPython repository (default: official repo)

--mpy-lib-repo <mpy_lib_repo>

URL for MicroPython-lib repository (default: official repo)

docs-stubs

Build stubs from documentation.

Read the Micropython library documentation files and use them to build stubs that can be used for static typechecking.

stubber docs-stubs [OPTIONS]

Options

-p, --path <path>
Default:

'repos'

--stub-path, --stub-folder <target>

Destination of the files to be generated.

Default:

'repos/micropython-stubs/stubs'

--version, --tag <version>

Version number to use. [default: Git tag]

-b, --format, --black, -nb, --no-format, --no-black

Run formatter (ruff)

Default:

True

--autoflake, --no-autoflake

Run autoflake to clean imports

Default:

True

--clean-rst, --no-clean-rst

remove .rST constructs from the docstrings

Default:

True

--enrich, --no-enrich

Enrich with type information from reference/micropython

Default:

True

enrich

Enrich the stubs in stub_folder with the docstubs in docstubs_folder.

stubber enrich [OPTIONS]

Options

-d, --dest, --destination, --stubs <dest_folder>

The destination file or folder containing the stubs stubs to be updated

Default:

'repos/micropython-stubs/stubs'

-s, --source, --docstubs <source_folder>

The source file or folder containing the docstubs to be read

Default:

'repos/micropython-stubs/stubs'

--diff

Show diff

Default:

False

--dry-run

Dry run does not write the files back

Default:

False

--copy-params, --no-copy-params

Copy the function/method parameters

Default:

True

--copy-docstr, --no-copy-docstr

Copy the docstrings

Default:

True

firmware-stubs

Run createstubs on one or more MCUs to collect firmware stubs (formerly MCU stubs).

stubber firmware-stubs [OPTIONS]

Options

--variant <variant>

Variant of createstubs to run

Default:

'DB'

Options:

Full | Mem | DB

-f, --format <format>

Python source or pre-compiled.

Default:

'mpy'

Options:

py | mpy

-s, --serial, --serial-port <SERIALPORT>

Which serial port(s) (or globs) to list.

Default:

'*'

-i, --ignore <SERIALPORT>

Serial port(s) (or globs) to ignore. Defaults to MPFLASH_IGNORE.

Default:

-b, --bluetooth, -nb, --no-bluetooth

Include bluetooth ports in the list

Default:

False

-e, --exclude <MODULE>

Module name(s) to exclude from stub generation (e.g., modules that cause board to hang).

--mount-vfs, --no-mount-vfs

Mount a host VFS during stub generation. Disable for boards where mount mode is unstable.

Default:

True

--debug, --no-debug

Debug mode.

Default:

False

Environment variables

MPFLASH_IGNORE

Provide a default for --ignore

frozen-stubs

Get the frozen stubs for MicroPython.

Get the frozen modules for the checked out version of MicroPython

stubber frozen-stubs [OPTIONS]

Options

-stubs, --stub-folder <stub_folder>
Default:

'repos/micropython-stubs/stubs'

-v, --version, --Version <version>

The version of MicroPython to get the frozen modules for. Use ‘preview’ to get the latest version from the micropython repo

Default:

''

--stubgen, --no-stubgen

Run stubgen to create .pyi files for the (new) frozen modules

Default:

True

--black, --no-black

Run black on the (new) frozen modules

Default:

True

--enrich, --no-enrich

Enrich with type information from reference/micropython

Default:

True

get-core

Download core CPython stubs from PyPi.

Get the core (CPython compat) modules for both MicroPython and Pycopy.

stubber get-core [OPTIONS]

Options

-stubs, --stub-folder <stub_folder>
Default:

'repos/micropython-stubs/stubs'

--stubgen, --no-stubgen

run stubgen to create .pyi files for the (new) frozen modules

Default:

True

--format, --black, --no-format, --no-black

Run formatter (ruff) on the (new) frozen modules

Default:

True

init

Initialize a new workspace.

This command: 1. Clones micropython-stubs into ./micropython-stubs 2. Runs clone to fetch micropython + micropython-lib into ./repos 3. Runs switch stable in ./repos

stubber init [OPTIONS]

Options

-p, --path <path>

Path where micropython-stubs should be created (default: current directory)

merge

Enrich the stubs in stub_folder with the docstubs in docstubs_folder.

stubber merge [OPTIONS]

Options

--family <family>
Default:

'micropython'

-v, --version <versions>

‘stable’, ‘latest’, ‘all’, or one or more versions

Default:

'stable'

-p, --port <ports>

multiple:

Default:

'all'

-b, --board <boards>

multiple:

Default:

'generic'

--clean, --no-clean

Clean target folders before merging.

Default:

True

publish-stubs

Commandline interface to publish stubs.

stubber publish-stubs [OPTIONS]

Options

--family <family>
Default:

'micropython'

-v, --version <versions>

multiple:

Default:

'v1.28.0'

-p, --port <ports>

multiple:

Default:

'all'

-b, --board <boards>

multiple:

Default:

'GENERIC'

--pypi, --test-pypi

publish to PYPI or Test-PYPI

Default:

False

--build

build before publish

--force

create new post release even if no changes detected

--dry-run

Do not actually publish, just show what would be done

--clean

clean folders after processing and publishing

show-config

Show the current configuration

stubber show-config [OPTIONS]

stub

Create or update .pyi type hint files.

stubber stub [OPTIONS]

Options

-s, --source <source>

switch

Switch to a specific version of the micropython repos.

TAG can be: - A version tag (e.g., v1.22.0, v1.21.0) - A branch name (e.g., master, develop) - A commit hash (e.g., abc123def456) - Special values: preview, latest, stable

The Micropython-lib repo will be checked out to a commit that corresponds in time to that version tag, in order to allow non-current versions to be stubbed correctly.

The repos must be cloned already

stubber switch [OPTIONS] [TAG]

Options

-p, --path <path>

Arguments

TAG

Optional argument

variants

Update all variants of createstubs*.py.

stubber variants [OPTIONS]

Options

-t, --target <target_folder>

Target folder for the createstubs*.py/.mpy files

-v, --version <version>

The version of mpy-cross to use

Default:

'v1.28.0'