Usage#

As a library#

Look up the installed distribution version:

examples/version_lookup.py#
"""Look up the version of the installed distribution."""

from importlib.metadata import version

from hwid.__metadata__ import PROJECT_NAME


def version_lookup() -> str:
    """Return the installed distribution version for this project.

    Returns:
        str: The installed distribution version.
    """
    return version(PROJECT_NAME)

For short interactive snippets embedded in prose, the docs-doctest task executes >>> blocks too:

>>> from hwid.__metadata__ import PROJECT_NAME
>>> PROJECT_NAME
'hwid'

print(hwid.get_hwid())

As a command-line tool#

Run it without installing, straight from PyPI:

uvx hwid

Or, once installed, invoke the console script. The bare command prints the machine’s hardware ID:

hwid

The version and info subcommands report the package version and environment:

hwid version
hwid info

Or invoke it programmatically from Python:

examples/cli_usage.py#
"""CLI argument parsing."""

from __future__ import annotations

from typing import TYPE_CHECKING

from hwid.cli.app import build_parser

if TYPE_CHECKING:
    import argparse


def parse_args(argv: list[str]) -> argparse.Namespace:
    """Parse CLI arguments without executing a command.

    Args:
        argv: Argument vector to parse.

    Returns:
        argparse.Namespace: The parsed arguments.
    """
    return build_parser().parse_args(argv)