Metadata-Version: 2.4
Name: pip-search-fix
Version: 1.0.1
Summary: Search PyPI packages from the command-line by scraping the web interface
Author-email: "@readwithai" <talwrii@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/ManiacBoy777/pip-search
Project-URL: Repository, https://github.com/ManiacBoy777/pip-search
Project-URL: Issues, https://github.com/ManiacBoy777/pip-search/issues
Keywords: pip,pypi,search,packages,command-line
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: license-file

# pip-search

**`pip search`, restored.** pip removed its built-in search command years ago; this project brings it back as a small, single-dependency Python tool — `pip-search-fix` — that searches PyPI from the command line with colorized, hyperlinked, ranked results, plus optional shell functions that make plain `pip search …` work again in Fish, Bash, and Zsh.

![Python](https://img.shields.io/badge/python-%3E%3D3.8-3776ab)
![Version](https://img.shields.io/badge/version-1.0.1-555555)
![PyPI](https://img.shields.io/badge/PyPI-pip--search--fix-3775a9)
![License](https://img.shields.io/badge/license-MIT-green)
![Branch](https://img.shields.io/badge/branch-master-555555)
![Visibility](https://img.shields.io/badge/repo-public-brightgreen)
![Status](https://img.shields.io/badge/status-Beta-orange)

> **Just want `pip search` back?** Install the package (`pip install pip-search-fix`), then add the one-file shell function for your shell — see [Shell Integration](#shell-integration). From then on, `pip search requests` works the way it used to, and every other `pip` command passes through untouched.

---

## Table of Contents

- [Overview](#overview)
- [How It Works](#how-it-works)
- [Repository Layout](#repository-layout)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [Shell Integration](#shell-integration)
- [Ranking and Search Behaviour](#ranking-and-search-behaviour)
- [Configuration Reference](#configuration-reference)
- [Requirements and Compatibility](#requirements-and-compatibility)
- [Known Limitations](#known-limitations)
- [Troubleshooting](#troubleshooting)
- [Development](#development)
- [Releasing and Maintenance](#releasing-and-maintenance)
- [Credits](#credits)
- [License](#license)

---

## Overview

| Area | Detail |
| --- | --- |
| **Package** | `pip-search-fix` 1.0.1 — on [PyPI](https://pypi.org/project/pip-search-fix/) and installable from this repository |
| **Commands** | `pip-search-fix` and the short alias `psf` (identical entry point) |
| **What it does** | Searches PyPI package names, ranks the matches using package summaries, and prints the latest version and a short description for each result |
| **Data sources** | The PyPI simple index (`https://pypi.org/simple/`) and the PyPI JSON API (`https://pypi.org/pypi/<package>/json`) — no API key, no account |
| **Runtime dependency** | One: `requests >= 2.25.0` |
| **Python** | `>= 3.8` (classifiers list 3.8, 3.9, and 3.10; OS-independent) |
| **Output** | ANSI color, OSC 8 terminal hyperlinks to each package's PyPI page, and a yellow `*` marker on an exact name match |
| **Shell integration** | Optional `pip` wrapper functions for Fish, Bash, and Zsh that intercept only the `search` subcommand |

### Design principles

1. **Restore the habit, not just the command.** The shell functions exist so the muscle memory — `pip search <term>` — works again, while every other `pip` invocation is forwarded to the real `pip` unchanged.
2. **One runtime dependency.** The tool itself needs only `requests`; everything else is the Python standard library (`argparse`, `re`, `concurrent.futures`).
3. **Ranking you can read.** Relevance is a small, explicit scoring function in `pip_search_fix/main.py` (see [Ranking and Search Behaviour](#ranking-and-search-behaviour)) — no opaque algorithm, no personalization, no tracking.
4. **Live data only.** Results, versions, and summaries are fetched from PyPI on every run; nothing is cached or bundled, so a result is never stale.

---

## How It Works

```text
  pip search requests          pip-search-fix requests           psf requests
        │                              │                               │
        └──────────────┬───────────────┴───────────────┬───────────────┘
                       │   (shell function intercepts   │
                       │    only the `search` verb)     ▼
                       │                    pip_search_fix.main:main()
                       ▼                               │
              any other pip verb ──► real pip          │
                                                       ▼
                              1. GET https://pypi.org/simple/  (10 s timeout)
                                 extract every package name
                              2. Keep names containing any search word
                                 (pre-sort: exact → contains → shortest)
                              3. Take up to max(count × 3, 100) candidates and
                                 fetch each summary + version concurrently
                                 GET https://pypi.org/pypi/<name>/json  (3 s timeout)
                                 ThreadPoolExecutor, 10 workers
                              4. Score and rank (name match ≫ word match ≫
                                 description match, shorter names win ties)
                              5. Print the top N (default 10):
                                 bold blue hyperlinked name, green version,
                                 summary truncated to 100 characters,
                                 yellow "*" prefix on an exact match
```

Two details worth knowing:

- **Multi-word queries** (`pip-search-fix machine learning`) are joined into one phrase, then split into words: a package matches if *any* word appears in its name, and the ranking rewards packages matching more of the phrase.
- **Descriptions influence ranking, not discovery.** Summaries are fetched only for packages whose *names* already matched, so a term that appears only in a package's description will not discover that package. See [Known Limitations](#known-limitations).

---

## Repository Layout

| Path | Purpose |
| --- | --- |
| `pip_search_fix/main.py` | The entire tool: index search, concurrent metadata fetch, scoring/ranking, styled output, and the `argparse` CLI |
| `pip_search_fix/__init__.py` | Package marker (`"""pip-search-fix package"""`) |
| `functions/pip.fish` | Fish `pip` wrapper — routes `search` to `pip-search-fix`, everything else to `command pip` |
| `functions/pip.bash` | Bash `pip` wrapper — same dispatch (identical file to the Zsh version) |
| `functions/pip.zsh` | Zsh `pip` wrapper — same dispatch |
| `pyproject.toml` | Packaging metadata (name, version, entry points), the single runtime dependency, dev extras, and Black / Flake8 / pytest configuration |
| `.github/workflows/publish-to-pypi.yml` | Publishes to PyPI on a published GitHub release or manual dispatch, using trusted publishing (`id-token: write`) |
| `release` | Legacy local release script (Bash): push → tag with the `pyproject.toml` version → build → Twine upload using the gitignored `token` file |
| `LICENSE` | MIT License |
| `.gitignore` | Ignores `*.pyc`, `*.egg-info`, `dist`, and the local `token` file used by `release` |

There is no `tests/` directory in the repository (pytest is configured in `pyproject.toml`, but no test suite is shipped — see [Development](#development)).

---

## Quick Start

### Option A — From PyPI (recommended)

```bash
pip install pip-search-fix
```

Version 1.0.1 is published on PyPI as a wheel and a source distribution. It is a documentation release — the code is unchanged from 1.0.0; it exists to ship this README to PyPI.

### Option B — With uv

```bash
uv pip install -U --system git+https://github.com/ManiacBoy777/pip-search
```

### Option C — From this repository with pip

```bash
pip install git+https://github.com/ManiacBoy777/pip-search
```

### Verify

```bash
pip-search-fix --help
pip-search-fix requests
psf requests            # the same command, via the short alias
```

Then, optionally, install the [shell function](#shell-integration) for your shell so `pip search requests` works directly.

---

## Usage

```text
pip-search-fix <search_terms...> [-n COUNT]
psf <search_terms...> [-n COUNT]
```

| Argument | Required | Default | Meaning |
| --- | --- | --- | --- |
| `search_terms` | Yes (one or more) | — | Search words; multiple words are joined with spaces into a single query |
| `-n`, `--count` | No | `10` | Number of results to show |
| `-h`, `--help` | No | — | Show the built-in help (with examples) and exit |

### Examples

```bash
pip-search-fix requests                  # find the requests package and near matches
pip-search-fix machine learning          # multi-word query
pip-search-fix web scraping -n 20        # show the top 20 instead of the top 10
pip search requests                      # the same, once the shell function is installed
```

### Reading the output

Each result is one line, in this format:

```text
<prefix><name> (<version>) - <summary>
```

- **Prefix** — a yellow `*` marks an exact name match for the full query; all other results get two spaces.
- **Name** — bold blue, and an OSC 8 terminal hyperlink to `https://pypi.org/project/<name>/` in terminals that support clickable links.
- **Version** — green; the package's current version from the PyPI JSON API (`unknown` if that lookup failed).
- **Summary** — the package's PyPI summary, stripped and truncated to 100 characters (`No description available` if PyPI returns none or the lookup failed).

If no package name matches at all, the tool prints `No packages found matching names.` in yellow and exits.

---

## Shell Integration

The wrappers define a shell function named `pip`. It checks the first argument only:

| First argument | Behaviour |
| --- | --- |
| `search` | Drops the word `search` and runs `pip-search-fix` with the remaining arguments |
| Anything else | Forwards everything to the real pip via `command pip <args>` |

### Fish

```bash
# curl
curl -fsSL https://raw.githubusercontent.com/ManiacBoy777/pip-search/master/functions/pip.fish -o ~/.config/fish/functions/pip.fish

# or wget
wget https://raw.githubusercontent.com/ManiacBoy777/pip-search/master/functions/pip.fish -O ~/.config/fish/functions/pip.fish
```

Fish loads functions from that directory automatically; open a new shell and `pip search …` works.

### Bash

```bash
# curl
curl -fsSL https://raw.githubusercontent.com/ManiacBoy777/pip-search/master/functions/pip.bash -o ~/.bash_functions

# or wget
wget https://raw.githubusercontent.com/ManiacBoy777/pip-search/master/functions/pip.bash -O ~/.bash_functions
```

Then add this to `~/.bashrc` (once):

```bash
if [ -f ~/.bash_functions ]; then
    source ~/.bash_functions
fi
```

### Zsh

```bash
# curl
curl -fsSL https://raw.githubusercontent.com/ManiacBoy777/pip-search/master/functions/pip.zsh -o ~/.zsh_functions

# or wget
wget https://raw.githubusercontent.com/ManiacBoy777/pip-search/master/functions/pip.zsh -O ~/.zsh_functions
```

Then add this to `~/.zshrc` (once):

```bash
if [ -f ~/.zsh_functions ]; then
    source ~/.zsh_functions
fi
```

### Removing the integration

Delete the downloaded function file (and, for Bash/Zsh, the `source` block if you added one for this file alone), then open a new shell. The `pip-search-fix` package itself is removed with `pip uninstall pip-search-fix`.

---

## Ranking and Search Behaviour

All behaviour below is taken directly from `pip_search_fix/main.py`.

**Candidate selection**

1. The full simple index is downloaded on every search (`GET https://pypi.org/simple/`, 10-second timeout) and package names are extracted from its links.
2. A package becomes a candidate if any search word appears in its (lowercased) name.
3. Candidates are pre-sorted — exact name match first, then names containing the full query, then shortest name — and the first `max(count × 3, 100)` are kept for metadata lookup.

**Metadata lookup**

- Summaries and versions come from `GET https://pypi.org/pypi/<name>/json` (3-second timeout per package), fetched concurrently with a `ThreadPoolExecutor` capped at 10 workers.
- A failed lookup never fails the search: the package falls back to version `unknown` and `No description available`.

**Scoring** (higher is shown first; applied per package)

| Signal | Points |
| --- | --- |
| Package name equals the full query | +5000 |
| A search word equals the package name | +2000 per word |
| A search word appears in the package name | +500 per word |
| A search word appears in the summary | +100 per word |
| Length penalty | −1 per character of the package name |

The top `count` packages by score are printed (default 10).

---

## Configuration Reference

There is **no configuration file, no environment variable, and no settings store** for the tool itself — the only controls are the positional query and `-n/--count`. All configuration in this repository is packaging and tooling configuration in `pyproject.toml`:

| Key | Value | Meaning |
| --- | --- | --- |
| `project.name` | `pip-search-fix` | Distribution name on PyPI |
| `project.version` | `1.0.1` | Current release; the `release` script tags this value |
| `project.requires-python` | `>=3.8` | Minimum Python |
| `project.dependencies` | `requests>=2.25.0` | The only runtime dependency |
| `project.scripts` | `pip-search-fix`, `psf` → `pip_search_fix.main:main` | The two installed commands |
| `project.optional-dependencies.dev` | `black`, `flake8`, `pytest`, `pytest-cov` | Development-only extras |
| `build-system` | `setuptools>=61.0` + `wheel`, `setuptools.build_meta` | Build backend |
| `tool.black` | line length 88, target `py38` | Formatter settings |
| `tool.flake8` | max line length 88, ignores `E203`, `W503` | Linter settings |
| `tool.pytest.ini_options` | `testpaths = ["tests"]`, `test_*.py` / `Test*` / `test_*` | Test discovery settings (no `tests/` directory is currently shipped) |

---

## Requirements and Compatibility

- **Python ≥ 3.8** and **pip** (or **uv**) to install; the package is OS-independent.
- **Network access to `pypi.org`** on every search — the index and per-package JSON are fetched live; there is no offline mode or cache.
- **Terminal** — output always includes ANSI color codes, and names are wrapped in OSC 8 hyperlink sequences. Terminals that support OSC 8 render the names as clickable links; others simply show the styled text (see [Troubleshooting](#troubleshooting) if raw escape codes appear).
- **Shell functions** are provided for Fish, Bash, and Zsh only; the standalone `pip-search-fix` / `psf` commands work in any shell.

---

## Known Limitations

- **Every search downloads the entire PyPI simple index** before filtering locally. That keeps the tool simple and keyless, but the index is large and grows with PyPI, so searches are network-bound.
- **Discovery is by name only.** Descriptions are fetched for ranking already-matched names; a package whose name contains none of the search words is never found, however relevant its summary is.
- **Summaries are truncated to 100 characters** in both ranking and display.
- **No `--no-color` / plain-output switch.** ANSI styling and hyperlinks are emitted unconditionally, including when output is piped.
- **The index parser is a regex over the simple index's HTML links** (`<a href="/simple/<name>/">`), so a change to that page's format upstream would break candidate extraction until the pattern is updated.
- **No caching and no retry logic.** A slow or failed index fetch (10-second timeout) returns no results for that run.

---

## Troubleshooting

| Symptom | Cause | Fix |
| --- | --- | --- |
| `pip search` still errors with pip's own "search is disabled / no such command" message | The shell function is not installed, or the current shell predates it | Install the function for your shell (see [Shell Integration](#shell-integration)) and open a new shell |
| `pip-search-fix: command not found` after installing through the wrapper route | The package itself was never installed — the shell function only forwards to it | `pip install pip-search-fix`, then retry |
| `No packages found matching names.` | No package *name* contains any of the search words | Try a shorter or more name-like term (for example `pip-search-fix flask` rather than a full sentence); remember discovery is name-only |
| Results are relevant but the expected top package sits lower | Ranking is the fixed scoring table above — exact and shorter names win | Use the exact package name as the query; an exact match is marked with `*` and scored +5000 |
| Search hangs, then returns nothing | The full-index download exceeded the 10-second timeout, or PyPI is unreachable | Check the connection to `pypi.org` and retry; there is no offline mode |
| A result shows `unknown` version / `No description available` | That package's JSON lookup failed or timed out (3 s) while the rest succeeded | Re-run; per-package failures are non-fatal by design |
| Raw escape sequences (`[94m`, `]8;;…`) visible in output | The terminal or pager does not interpret ANSI / OSC 8 sequences | Use a terminal with ANSI support; there is currently no plain-output flag |
| Other `pip` commands behave oddly after installing the wrapper | The wrapper forwards non-`search` verbs to `command pip`, so normal behaviour should be unchanged | Verify the installed file matches `functions/pip.<shell>` in this repo; remove it to restore stock `pip` (see [Shell Integration](#shell-integration)) |
| `ModuleNotFoundError: requests` in a hand-run checkout | Runtime dependency not installed in that environment | `pip install requests>=2.25.0`, or install the project itself (`pip install .`) |

---

## Development

```bash
git clone https://github.com/ManiacBoy777/pip-search
cd pip-search
pip install -e ".[dev]"
```

- **Run from the checkout:** after the editable install, use `pip-search-fix` / `psf`, or run the module directly with `python -m pip_search_fix.main <terms>` (its `__main__` guard calls `main()`).
- **Style:** Black (line length 88, target `py38`) and Flake8 (max line length 88, ignoring `E203` and `W503`) are configured in `pyproject.toml` and included in the `dev` extras.
- **Tests:** pytest is configured in `pyproject.toml` (`testpaths = ["tests"]`), but the repository currently ships **no `tests/` directory and no test suite** — treat behaviour claims as code-verified, not test-verified.

---

## Releasing and Maintenance

- **Publish (current path):** `.github/workflows/publish-to-pypi.yml` runs on a **published GitHub release** or **manual dispatch** (`workflow_dispatch`). It checks out the repo on `ubuntu-latest`, sets up Python 3.11, builds with `python -m build`, and publishes via `pypa/gh-action-pypi-publish` using **trusted publishing** — the `pypi` environment with `id-token: write`, project page https://pypi.org/p/pip-search-fix. No PyPI password or token is stored in the workflow.
- **Publish (legacy script):** `./release` pushes, reads the version from `pyproject.toml` (`toml2json` + `jq`), tags the commit with it, rebuilds, and runs `twine upload` with the password read from the local `token` file — which `.gitignore` deliberately keeps out of Git.
- **Version bump:** edit `project.version` in `pyproject.toml`; both release paths take the version from there.
- **Dependency care:** the runtime surface is intentionally one package (`requests`). Keep it that way unless a change clearly earns a second dependency; update the minimum version in `pyproject.toml` rather than pinning exactly.
- **Upstream watch:** the two PyPI endpoints the tool depends on (simple index format and the JSON API) are the maintenance risk — if PyPI changes either, `pip_search_fix/main.py` is the only file that needs to change.

---

## Credits

- **Tal Wrii ([@readwithai](https://github.com/readwithai))** — original author of pip-search (initial implementation, 2025); the MIT License and `pyproject.toml` authorship remain in his name.
- **Ryan Miller ([ManiacBoy777](https://github.com/ManiacBoy777))** — the `pip-search-fix` revival: colorized and hyperlinked output, description-aware ranking (2026-05-23), the `pip-search-fix` / `psf` packaging, and the Fish, Bash, and Zsh `pip` wrapper functions.
- **[PyPI](https://pypi.org)** — the package index whose simple index and JSON API make a keyless search like this possible.

---

## License

MIT License — see [LICENSE](https://github.com/ManiacBoy777/pip-search/blob/master/LICENSE). Copyright (c) 2025 @readwithai.

---

*Public repository — personal project. Last verified end to end: 2026-11-06 (America/Phoenix) — repository audited at `master` (file tree, `pip_search_fix/main.py`, shell functions, `pyproject.toml`, and the PyPI publish workflow read in full). Release 1.0.1 is documentation-only: code unchanged from 1.0.0, published to carry this README to PyPI.*
