Skip to main content

pymanual

Given a Python module name (import name) or a distribution name (the string you'd type in pip install …), deterministically return the best available documentation URL — or a status token explaining why one isn't available.

Install

End users:

pipx install pymanual
# or
uv tool install pymanual

This puts pymanual on your PATH. It still looks modules up in the environment you're working in, not in its own isolated one — see Which Python environment.

Developing on the project itself instead:

git clone https://github.com/gkarpo/pymanual && cd pymanual
uv sync

CLI

pymanual <module> [--python PATH] [--no-network] [--no-cache] [-v]
pymanual --clear-cache

Exit code is 0 when a URL is returned, 1 when a status token is returned, and 2 for a usage error or when the chosen interpreter fails (for example, a parent package of a dotted name raises on import); the error goes to stderr and stdout stays empty.

$ pymanual json
https://docs.python.org/3/library/json.html

$ pymanual email.mime.text
https://docs.python.org/3/library/email.html

$ pymanual pytest
https://docs.pytest.org/en/latest/

$ pymanual pytest-cov       # distribution name with a dash
https://pytest-cov.readthedocs.io/

$ pymanual python-dateutil  # not installed; PyPI lookup
https://dateutil.readthedocs.io/en/stable/

$ pymanual winreg           # stdlib, but not importable on Linux
https://docs.python.org/3/library/winreg.html

$ pymanual definitely_no_such_xyz
module_not_found

If you're working inside the project source, prefix every command with uv run (e.g. uv run pymanual json).

Flags

  • --python PATH — the interpreter to locate the module with: an interpreter path, a virtual environment directory, or a command name on PATH. Defaults to auto-detection — see Which Python environment.
  • -v, --verbose — explain on stderr which interpreter was used and why, and report cache hits.
  • --no-network — skip the PyPI HTTP fallback (step 4.ii below for installed third-party modules, and the second half of step 5 for the distribution-name fallback). Resolution stays fully offline.
  • --no-cache — bypass the local cache for that one call (no read, no write).
  • --clear-cache — delete the cache file and exit.

Library

from pymanual import (
    resolve_doc_url,
    STATUS_NOT_FOUND,
    STATUS_UNRESOLVABLE_PATH,
    STATUS_LOCAL,
)

resolve_doc_url("json")                 # 'https://docs.python.org/3/library/json.html'
resolve_doc_url("pytest")               # URL from installed distribution metadata
resolve_doc_url("pytest-cov")           # distribution-name fallback
resolve_doc_url("python-dateutil")      # not installed → PyPI lookup
resolve_doc_url("nope_xyz")             # 'module_not_found'

# Same options as the CLI flags:
resolve_doc_url("pytest", network=False)     # offline-only
resolve_doc_url("json", use_cache=False)     # bypass the on-disk cache

# Where to locate the module (default None: this process's environment):
resolve_doc_url("markdown_it", python="/usr/bin/python3")
resolve_doc_url("numpy", python=".venv")     # a venv directory works too
resolve_doc_url("numpy", python="auto")      # the CLI's auto-detection

An explicit python that names no interpreter raises ValueError; one that can't answer raises RuntimeError. With "auto", a failing interpreter falls back to the calling process instead.

Which Python environment

A module can only be located in an environment where it's installed. pymanual installed with uv tool or pipx lives in its own isolated venv, so the CLI locates modules with your interpreter instead. It runs a small probe script under it, which reports what it finds as JSON; the decisions below are then made by pymanual itself.

The CLI picks the first of:

  1. --python PATH, if given. If it can't run, that's an error.
  2. $PYMANUAL_PYTHON.
  3. $VIRTUAL_ENV — the activated virtual environment (uv run sets this too).
  4. python3 (else python) on PATH.
  5. pymanual's own environment.

From step 2 onward, an interpreter that crashes, returns unreadable output or takes longer than 10 seconds is skipped in favour of pymanual's own environment; -v shows when that happens. When the chosen interpreter is pymanual's own environment, no subprocess is started.

The probe drops the working directory from sys.path, as the installed pymanual command does, so a file next to you is only found if it's on PYTHONPATH or installed. It shares the never imported guarantee, including its one exception for parent packages. Starting an interpreter also runs that environment's own site and .pth hooks, as typing python3 would.

The library defaults to python=None — locate in the calling process — so existing callers never start a subprocess they didn't ask for.

Resolution strategy

Strict order — the first step that yields a result wins. Every lookup (find_spec, sys.stdlib_module_names, the stdlib root, installed metadata) happens in the environment chosen above; only the PyPI requests run in pymanual itself.

The stdlib name check. Steps 1 and 2 both reach points where no file path is available to classify. Both then ask whether top_level is in sys.stdlib_module_names, and if so return https://docs.python.org/3/library/<top-level>.html. That list is generated at build time and covers every stdlib module unconditionally, including ones belonging to other platforms (winreg on Linux) and ones a build omitted (tkinter without Tk). It is deliberately consulted only after a path lookup has come up empty, never before: a local statistics.py shadowing a stdlib name is still your own code and must return local_module_no_external_docs.

  1. Locate the module with importlib.util.find_spec — which finds it without executing it (see Modules are never imported below).
    • On success → continue at step 2.
    • None, ImportError or ValueError, for a dotted name → retry with just the top-level name, so a missing leaf under a real package (pytest.nosuchthing) still answers from the package.
    • Still nothing → apply the stdlib name check. This is what resolves winreg on Linux, and what makes json.nosuchthing return json's page rather than reaching PyPI (which carries projects named json, email, and other short stdlib names). If it doesn't apply → try the distribution-name fallback (step 5).
  2. Take spec.origin. Builtins (sys, builtins, …) are short-circuited as stdlib before this step. If there's no usable path — None for namespace packages, the sentinel 'frozen' for the frozen bootstrap stdlib (os, io, abc, codecs, zipimport), or a source file deleted since import — apply the stdlib name check; if it doesn't apply either, return unresolvable_module_path.
  3. Classify by file path only (not sys.path):
    • inside sysconfig.get_paths()["stdlib"] → stdlib
    • inside site-packages / dist-packages / a venv directory → third_party
    • otherwise → local
  4. Resolve URL by classification:
    • stdlib → https://docs.python.org/3/library/<top-level>.html
    • third_party:
      1. importlib.metadata.metadata(...) → prefer Project-URL keys matching documentation/docs/doc, then homepage, then Home-page
      2. PyPI JSON (https://pypi.org/pypi/<name>/json) — same key precedence; skipped when network=False
      3. Heuristic last resort: https://pypi.org/project/<name>/
    • local → local_module_no_external_docs
  5. Distribution-name fallback (when find_spec located nothing and the stdlib name check didn't apply):
    • Try importlib.metadata.metadata(<input>) — catches cases like pytest-cov, PyYAML, scikit-learn whose import names don't match their distribution names. If installed → return URL from its metadata (falling back to https://pypi.org/project/<input>/).
    • Else, if network=True, query PyPI directly for <input>. If the package exists there → return its documentation URL.
    • Otherwise → module_not_found.

Import-name vs distribution-name mismatches (e.g. yaml → PyYAML) from step 4 are handled via importlib.metadata.packages_distributions().

Modules are never imported

Resolving a name does not run that module's code. pymanual locates modules with find_spec rather than importing them, so pymanual foo will not execute whatever foo.py happens to be sitting in your working directory.

One exception survives, by necessity: for a dotted name, find_spec imports the parent packages to read their __path__. pymanual email.mime.text imports email and email.mime; the leaf is never executed. Import-time errors in a parent propagate rather than being swallowed. This is why pymanual pytest is fast while pymanual pytest.something still pays for importing pytest.

Local cache

Successful URL resolutions are cached at $XDG_CACHE_HOME/pymanual/cache.json (defaults to ~/.cache/pymanual/cache.json). Subsequent lookups for the same input string return instantly without starting an interpreter or hitting find_spec, importlib.metadata, or PyPI.

  • Status tokens (module_not_found, etc.) are not cached, so installing a previously-missing module just works on the next call.
  • Cache key is the verbatim input string — pytest-cov and pytest_cov are independent entries — prefixed with the interpreter's path when resolved through another interpreter. The same name can be a package in one environment and your own module in another, so their results are kept apart. The 100-entry cap is shared.
  • LRU-bounded at 100 entries; the oldest entry is evicted when the cap is exceeded.
  • No TTL; entries live until eviction, until you run pymanual --clear-cache, or until you delete the file.
  • Override location for tests/sandboxing via the PYMANUAL_CACHE_DIR env var.

Output contract

A single string — either a URL or one of:

  • module_not_found
  • unresolvable_module_path
  • local_module_no_external_docs

Development

uv run pytest -q                  # run tests
uv run pytest --cov=pymanual      # with coverage

Metadata

Release files for pymanual 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymanual 1.2.0
File Size Uploaded Provenance Actions
pymanual-1.2.0.tar.gz 17.8 kB Without provenance Details for pymanual-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymanual 1.2.0
File Interpreter ABI Platform Actions
pymanual-1.2.0-py3-none-any.whl Python 3 none any Details for pymanual-1.2.0-py3-none-any.whl

Total release size: 39.8 kB

Release files / pymanual-1.2.0.tar.gz

Download URL pymanual-1.2.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
adbb41c5ff466cb0e601cde482b1b85cc016dc55db129fd0c6abe5355d2ed9fd
BLAKE2b-256 checksum
How to use checksums
e9651d24aa38b59c515121ce4c1716c6af8af6503885db6b5f5659e7d6996bd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pymanual-1.2.0-py3-none-any.whl

Download URL pymanual-1.2.0-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92f197f230c5278bfd7780063af8c82e09cb389f449437c056ce797233c7a73c
BLAKE2b-256 checksum
How to use checksums
97966a92bcd630b603f12a86822f1f005408e009781a2dee5fe8f715089782ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pymanual 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page