detect-installer

Detect how a Python package was installed and get the correct upgrade command for that installer.

Library
PyPI
v0.1.0
0stars
0BSD

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
11/100Needs Attention
Development Activity16
Maintenance0
Community4
Maturity24
Momentum0

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture76
Code Quality74
Innovation72
Learning Curve90

detect-installer is a zero-dependency Python library that figures out how a given package was installed, whether via pip, uv (project and pip modes), uv tool, pipx, Homebrew, Conda, or Mamba, and returns the correct upgrade command for that installer.

Call detect_installer("rich") and receive an InstallerInfo with the detected Installer enum and a ready-to-run upgrade_cmd string, or None if the package is not installed. It is published under the permissive 0BSD license so the single detection module can be vendored directly into a project.

What You Get

  • A detect_installer() function returning an InstallerInfo dataclass
  • An Installer enum covering pip, uv, uv-tool, pipx, brew, conda, and mamba
  • The correct, installer-specific upgrade command as a ready-to-run string
  • Zero runtime dependencies and a py.typed marker for full type hints
  • A 0BSD license that permits copying the detection module directly into your project

Common Use Cases

  • Showing users the right upgrade command in a CLI’s update notice
  • Adapting self-update logic to pip, uv, pipx, Homebrew, or Conda
  • Warning when a package was installed by an unexpected tool
  • Vendoring a dependency-free installer-detection helper into a tool

Under The Hood

Architecture The library is a single detection module. _detect.py (~180 lines) defines the Installer enum, the frozen InstallerInfo dataclass, and the detect_installer() entry point. Detection combines two signals: the package’s importlib.metadata distribution (the INSTALLER file and direct-url metadata written at install time) and environment heuristics such as sys.prefix containing pipx/venvs or uv/tools, plus CONDA_PREFIX/MAMBA_EXE environment variables. Once the installer is identified, a per-installer branch formats the appropriate upgrade command. __init__.py re-exports the public names, and _test.py holds a small internal test helper.

Tech Stack Pure Python using only the standard library, importlib.metadata, dataclasses, enum, os, sys, and pathlib, with no third-party runtime dependencies. It targets modern Python with from __future__ import annotations and ships a py.typed marker for downstream type checking.

Code Quality The code is small, fully type-annotated, and uses a frozen dataclass and string-enum for a clear, immutable result type. Helper functions are individually documented and each detection path is isolated, making the heuristics easy to audit. The project is young with few commits, so real-world coverage across every installer edge case is still maturing.

API Design The surface is a single function returning a well-typed result: info = detect_installer("rich") yields info.installer (an Installer enum) and info.upgrade_cmd (a string), or None when the package is absent. This makes integration a two-line affair, and exposing the enum lets callers branch on the installer when they need custom behavior beyond the provided command.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search