meta_package_manager.managers.winget module¶
- class meta_package_manager.managers.winget.WinGet[source]¶
Bases:
PackageManagerMicrosoft’s official Windows package manager.
mpm reads inventory from
winget list --details, whoseKey: Valueblocks carry the installed version and anAvailable Upgradessection.Note
No operation is marked
sudo, and escalating would be wrong. winget runs unelevated; a package whose installer wants administrator rights raises its own UAC prompt, which winget announces before handing over. Wrapping the call would instead decide the scope of every package: an EXE installer commonly picks user or machine by testing whether the caller is an administrator, and an MSIX registers per user and is unsupported in the system context.What that costs is a package needing elevation from a session with no interactive desktop to answer the prompt. Measured on winget
1.29.290, installing7zip.7zipfrom a medium-integrity shell reaches Installer failed with exit code: 1``and winget exits``6, where the same command succeeds elevated. Chocolatey is the opposite case and is escalated: it owns an administrator-locked tree of its own, so nothing there turns on which package is asked for.Note
installedandoutdatedread every application thewingetcatalog matches, whether winget installed it or not, like a vendor’s own MSI:winget update --allupgrades those too. An application no source matches, or onlymsstoredoes, is left out.Initialize
cli_errorslist.- operation_notes: ClassVar = {'installed': "Every application the catalog matches is reported, whether the tool installed it or not, like a vendor's own MSI.", 'outdated': "Every application the catalog matches is reported, whether the tool installed it or not, like a vendor's own MSI.", 'search': 'Store (`msstore`) entries cannot be queried for a real version, so they carry a sentinel version sorted below native ones.'}¶
Per-operation hints rendered in the Notes column of the manager page’s Operations table.
Keyed by the
Operationsmember name, each value is a single short sentence explaining why the manager lacks the operation, or what makes its implementation partial: the pointer a reader needs to judge whether the gap is one they could help close. Each sentence starts with a capital and closes with a period, and starts on a word rather than a code span, so the cell reads standalone beside its row. A blank cell stays silent: a manager documenting nothing documents no gap.The full rationale never lives here: it belongs in a comment beside the implementing method (or beside this declaration, for an operation with no method to hang it on), so the sentence on the page stays a hint and the code keeps the story. The class docstring follows the same split: it keeps only what a user needs to run the tool day to day, never how
mpmwraps it.Validated by
test_operation_notes, which also checks every key matches a real operation: a key outside the enum’s vocabulary would never reach a page.
- documentation_url: str | None = 'https://learn.microsoft.com/en-us/windows/package-manager/'¶
Entry point of the project’s own documentation, or
Nonewhen it has none.The manual, the documentation site, or the man page of the CLI
mpmdrives: whichever page a user reads to learn the commands this manager wraps. Listed betweenhomepage_urlandrepository_urlin the links of the manager’s page, so a reader reaching for the tool’s reference finds it in the box of facts rather than in the prose below it.Left unset where a link would state a fact twice or invent one: a tool documenting itself in its repository alone, whose README
repository_urlalready reaches. A page about the ecosystem rather than the tool does not qualify either.Where a project’s only site is its manual, that address belongs here and
homepage_urlstays unset: the slot names what the page is, and a reader reaching for the reference looks under the documentation link.Never inherited, like every other link: the AUR helpers extending
pacmaneach document themselves.
- repository_url: str | None = 'https://github.com/microsoft/winget-cli'¶
Repository holding the project’s code, or
Nonewhen it has no public one.Linked from the manager’s documentation page. Also what the weekly metrics sample reads:
docs/docs_update.pywrites it into the[tool.repomatic.metrics] subjectsofpyproject.tomlwhen its forge answers the sampler, through a mirror for a forge that does not.Never inherited, for the same reason as
wikipedia_url: the AUR helpers extendingpacmaneach live in a repository of their own.
- wikipedia_url: str | None = 'https://en.wikipedia.org/wiki/Windows_Package_Manager'¶
English Wikipedia article about the project, or
Nonewhen it has none.Listed last in the links of the manager’s documentation page. The article covers the project that home page names, or is a redirect Wikipedia keeps under the project’s name, landing on the part of a broader article that describes it:
Cargo_(software)opens the Cargo section of the Rust article. An article that merely mentions the project does not count, nor does one about a related subject:lazyis a Neovim plugin manager, and the Neovim article is not about it.Never inherited: the metaclass resets it to
Noneon any class not declaring its own. A subclass often wraps a distinct project, like the six AUR helpers extendingpacman, and would otherwise present pacman’s article as its own. Documentation-only, likehomepage_url.
- brewfile_entry_type: ClassVar[str | None] = 'winget'¶
Name of the Brewfile DSL entry type this manager maps to, or
Noneif the manager has no Brewfile equivalent.Set by the subset of managers Homebrew Bundle’s DSL covers, and consumed by
meta_package_manager.brewfilewhen rendering the output ofmpm dump --brewfile. Which manager maps to which entry is tabulated from these declarations in Snapshot and export, section “Brewfile”, where the export’s own quirks are documented too.
- platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='windows', name='Windows')})¶
List of platforms supported by the manager.
Allows for a mishmash of platforms and groups of platforms. Will be normalized into a
frozensetofPlatforminstances at instantiation.
- requirement: str | None = '>=1.29.280'¶
1.29.280 is the first stable release shipping the
--no-progresscommon argument thatpost_argspasses on every invocation (microsoft/winget-cli#6049), and the first whoselist --sourcedrops the packages that source does not match, whichinstalledrelies on (microsoft/winget-cli#6159).
- post_args: tuple[str, ...] = ('--accept-source-agreements', '--disable-interactivity', '--no-progress')¶
--accept-source-agreements:Used to accept the source license agreement, and avoid the following prompt:
> winget list The "msstore' source requires that you view the following agreements before using. Terms of Transaction: https://aka.ms/microsoft-store-terms-of-transaction The source requires the current machine's 2-letter geographic region to be sent to the backend service to function prope rly (ex. "US"). Do you agree to all the source agreements terms? [Y] Yes [N] No:
--disable-interactivity:Disable interactive prompts.
--no-progress:Disable progress bar rendering, keeping spinner characters out of the output
mpmcaptures.
- windows_creation_flags: int = 0¶
Detach winget from the calling process’s console.
When winget runs, the Windows COM infrastructure activates
WindowsPackageManagerServer.exeas a separate process. Installer EXEs launched bywinget upgradeorwinget installare also spawned as grandchildren. Both the COM server and any installer EXEs callGenerateConsoleCtrlEvent(0)during their own shutdown, which broadcasts aCTRL_C_EVENTto every process sharing the same console — including the Python test runner — causing it to exit with code 1 even after all tests pass.DETACHED_PROCESSbreaks the shared-console link: winget has no console, so neither the COM server nor any installer EXE can broadcast console events that reach us. Output is still captured because stdout and stderr are redirected to pipes, which are independent of console attachment.
- windows_processes_to_cleanup: tuple[str, ...] = ('WindowsPackageManagerServer.exe',)¶
Kill winget’s COM server after each call.
WindowsPackageManagerServer.exeis activated by the Windows COM infrastructure when winget runs, not as a direct child process. It therefore does not inherit our pipe handles and is not reaped bycommunicate(). Kill it by image name after each call to avoid accumulating orphan COM server processes.
- property installed: Iterator[Package]¶
Fetch installed packages.
> winget list --source winget --details --accept-source-agreements --disable-interactivity --no-progress (1/53) 7-Zip 26.03 (x64) [7zip.7zip] Version: 26.03 Publisher: Igor Pavlov Local Identifier: ARP\Machine\X64\7-Zip Product Code: 7-zip Installer Category: exe Installed Scope: Machine Installed Location: C:\Program Files\7-Zip\ (10/53) hyperfine [sharkdp.hyperfine] Version: 1.20.0 Publisher: David Peter Local Identifier: ARP\User\X64\sharkdp.hyperfine_Microsoft.Winget.Source_8wekyb3d8bbwe Product Code: sharkdp.hyperfine_microsoft.winget.source_8wekyb3d8bbwe Installer Category: portable Installed Scope: User Installed Architecture: X64 Installed Location: C:\Users\runneradmin\AppData\Local\Microsoft\WinGet\Packages\sharkdp.hyperfine_Microsoft.Winget.Source_8wekyb3d8bbwe Origin Source: winget
--source wingetlists every installed package thewingetcatalog matches, whatever installed it, and leaves out the others.
- property outdated: Iterator[Package]¶
Fetch outdated packages.
> winget list --upgrade-available --details --accept-source-agreements --disable-interactivity --no-progress (1/4) Git [Git.Git] Version: 2.37.3 Publisher: The Git Development Community Origin Source: winget Available Upgrades: winget [2.45.1] (2/4) Microsoft Edge [Microsoft.Edge] Version: 109.0.1518.70 Publisher: Microsoft Origin Source: winget Available Upgrades: winget [125.0.2535.51]
Returns every package with an upgrade from the
wingetsource, whatever installed it:winget update --allupgrades all of them. A package onlymsstoreoffers an upgrade for is left out.
- search(query, extended, exact)[source]¶
Fetch matching packages.
> winget search --query vscode --accept-source-agreements --disable-interactivity --no-progress Name Id Version Match Source --------------------------------------------------------------------------------------------------------- Microsoft Visual Studio Code Microsoft.VisualStudioCode 1.89.1 Moniker: vscode winget MrCode zokugun.MrCode 1.82.0.23253 Tag: vscode winget VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 Tag: vscode winget VSCodium VSCodium.VSCodium 1.89.1.24130 Tag: vscode winget Upgit pluveto.Upgit 0.2.18 Tag: vscode winget vscli michidk.vscli 0.3.0 Tag: vscode winget Huawei QuickApp IDE Huawei.QuickAppIde 14.0.1 Tag: vscode winget TheiaBlueprint EclipseFoundation.TheiaBlueprint 1.44.0 Tag: vscode winget Codium Alex313031.Codium 1.86.2.24053 Tag: vscode winget Cursor Editor CursorAI,Inc.Cursor latest Tag: vscode winget Microsoft Visual Studio Code CLI Microsoft.VisualStudioCode.CLI 1.89.1 Moniker: vscode-cli winget
> winget search --query vscode --exact --accept-source-agreements --disable-interactivity --no-progress Name Id Version Match Source ------------------------------------------------------------------------------------------------- Microsoft Visual Studio Code Microsoft.VisualStudioCode 1.89.1 Moniker: vscode winget MrCode zokugun.MrCode 1.82.0.23253 Tag: vscode winget VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 Tag: vscode winget VSCodium VSCodium.VSCodium 1.89.1.24130 Tag: vscode winget Upgit pluveto.Upgit 0.2.18 Tag: vscode winget vscli michidk.vscli 0.3.0 Tag: vscode winget Huawei QuickApp IDE Huawei.QuickAppIde 14.0.1 Tag: vscode winget TheiaBlueprint EclipseFoundation.TheiaBlueprint 1.44.0 Tag: vscode winget Codium Alex313031.Codium 1.86.2.24053 Tag: vscode winget Cursor Editor CursorAI,Inc.Cursor latest Tag: vscode winget
> winget search --id VSCodium.VSCodium --accept-source-agreements --disable-interactivity --no-progress Name Id Version Source ---------------------------------------------------------------- VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 winget VSCodium VSCodium.VSCodium 1.89.1.24130 winget
> winget search --name Codium --accept-source-agreements --disable-interactivity --no-progress Name Id Version Source ---------------------------------------------------------------- Codium Alex313031.Codium 1.86.2.24053 winget VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 winget VSCodium VSCodium.VSCodium 1.89.1.24130 winget
> winget search --id VSCodium.VSCodium --exact --accept-source-agreements --disable-interactivity --no-progress Name Id Version Source ---------------------------------------------- VSCodium VSCodium.VSCodium 1.89.1.24130 winget
> winget search --name Codium --exact --accept-source-agreements --disable-interactivity --no-progress Name Id Version Source -------------------------------------------- Codium Alex313031.Codium 1.86.2.24053 winget
- cli_names: tuple[str, ...] = ('winget',)¶
List of CLI names the package manager is known as.
This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.
- ..hint::
This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named
pythonorpython3.
By default, this property’s value is derived from the manager’s ID (see the
MetaPackageManager.__init__method above).
- homepage_url: str | None = None¶
Home page of the project, only used in documentation for reference.
Left unset when the home page is the project’s repository, which
repository_urlnames on its own, and when it is the project’s manual, whichdocumentation_urlnames. Never inherited, like the other links.
- id: str = 'winget'¶
Package manager’s ID.
Derived by defaults from the lower-cased class name in which underscores
_are replaced by dashes-.This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.
- install(package_id, version=None)[source]¶
Install one package.
> winget install --id Microsoft.PowerToys --accept-package-agreements --accept-source-agreements --disable-interactivity --no-progress Found Power Toys [Microsoft.PowerToys] Version 0.15.2 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Successfully verified installer hash Starting package install... ██████████████████████████████ 100% Successfully installed
- Return type:
- virtual: bool = False¶
Should we expose the package manager to the user?
Virtual package manager are just skeleton classes used to factorize code among managers of the same family.
- upgrade_all_cli()[source]¶
Generates the CLI to upgrade all outdated packages.
> winget update --all --accept-package-agreements --accept-source-agreements --disable-interactivity --no-progress Name Id Version Available Source ------------------------------------------------------------------------------------------------ Microsoft Edge Microsoft.Edge 109.0.1518.70 125.0.2535.51 winget Microsoft Edge WebView2 Runtime Microsoft.EdgeWebView2Runtime 109.0.1518.70 125.0.2535.51 winget Python Launcher Python.Launchez < 3.12.0 3.12.0 winget Microsoft Visual C++ (x86)... Microsoft.VCRedist.2015+.X86 14.34.31931.0 14.38.33135.0 winget 4 upgrades available. Installing dependencies: This package requires the following dependencies: - Packages Microsoft.UI.Xaml.2.8 [>= 8.2306.22001.0] (1/3) Found Microsoft Edge WebView2 Runtime [Microsoft.EdgeWebView2Runtime] Version 125. 0.2535.51 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/e5dd841e-17ff-43b7-a2c0-ff759f55c202/MicrosoftEdgeWebView2RuntimeInstallerARM64.exe ██████████████████████████████ 166 MB / 166 MB Successfully verified installer hash Starting package install... Successfully installed (...)
- upgrade_one_cli(package_id, version=None)[source]¶
Generates the CLI to upgrade the provided package.
> winget install --id Git.Git --accept-package-agreements --accept-source-agreements --disable-interactivity --no-progress Found Git [Git.Git] Version 2.45.1 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://github.com/git-for-windows/git/releases/download/v2.45.1.windows.1/Git-2.45.1-64-bit.exe ██████████████████████████████ 64.7 MB / 64.7 MB Successfully verified installer hash Starting package install... Successfully installed
Todo
Automatically uninstall the package if the technology is different:
> winget upgrade --id Microsoft.Edge A newer version was found, but the install technology is different from the current version installed. Please uninstall the package and install the newer version.
- remove(package_id)[source]¶
Remove one package.
> winget uninstall --id Microsoft.PowerToys --source winget --accept-source-agreements --disable-interactivity --no-progress Found PowerToys (Preview) [Microsoft.PowerToys] Starting package uninstall... ██████████████████████████████ 100% Successfully uninstalled
- Return type: