npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

source-survey

v0.1.0

Published

Discover Python import cycles, check boundaries, and query source and Git evidence in SQLite.

Downloads

350

Readme

Source Survey

Source Survey analyzes committed Python packages on one workstation and stores source and Git evidence in SQLite. Use sourcesurvey scan for a boundary you already know, or sourcesurvey cycles to discover dependencies worth investigating. A successful analysis exits 0 even when it finds candidates.

Install

Source Survey requires Git and Python 3.11 or newer. The distribution name is source-survey, the executable is sourcesurvey, and the Python module is source_survey.

For a Python installation, run pipx install source-survey or python -m pip install source-survey in a virtual environment. Start with sourcesurvey --help.

For npm, run npx source-survey --help. The launcher uses uv to run the Python implementation bundled in the npm package. Install uv on your PATH first.

To work from a source checkout, activate a virtual environment and install the project in editable mode.

python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e .
sourcesurvey --help

Scan a boundary

This example checks whether pytest's marker definitions import its exception-matching module. Run it with a fresh output catalog. The source root is the directory containing the package at the pinned revision. Omitting --rev uses HEAD.

git clone https://github.com/pytest-dev/pytest.git ../pytest
sourcesurvey scan --repo ../pytest \
  --rev 6665a79fb9a6553ce4e1be5574c21a9e3b769eec --source-root src \
  --package _pytest --source _pytest.mark.structures --forbidden _pytest.raises \
  --db analysis.sqlite3

Each finding records the repository-relative path and first source line at the scanned commit. Run this query against analysis.sqlite3.

SELECT s.revision, f.path, f.line, f.statement, s.rule_ref
FROM findings AS f JOIN scans AS s USING (scan_id)
WHERE s.scan_id = 1
ORDER BY f.path, f.line, f.imported;

All three commands use source-survey.sqlite3 by default. If that file is absent and the working directory contains a legacy foreman.sqlite3, the commands reuse the existing catalog. Supply --db to select a file explicitly.

The scans table also records completed scans with zero findings. Repeating a scan with the same checkout, commit, boundary, rule reference and tool versions reuses its scan ID. A new commit or rule gets a separate record.

Add Git change history

Use sourcesurvey history on an existing scan. It resolves both modules to their exact paths at the scanned commit. The database retains one measurement per distinct importing/imported module pair, however many import statements produced the finding.

sourcesurvey history --db analysis.sqlite3 --scan-id 1 --days 90 --max-files 30
SELECT h.days, p.importer, p.imported, p.status, p.both_commits, p.either_commits,
       CASE WHEN p.status = 'measured'
            THEN round(100.0 * p.both_commits / nullif(p.either_commits, 0), 1)
       END AS percent_together
FROM history_runs AS h JOIN module_coupling AS p USING (history_id)
WHERE h.scan_id = 1
ORDER BY h.days, p.importer, p.imported;

SELECT oid, subject FROM joint_commits
WHERE history_id = 1 AND importer = '_pytest.mark.structures' AND imported = '_pytest.raises'
ORDER BY timestamp DESC, oid;
  • The denominator counts eligible commits that edited either file. The numerator counts those that edited both. The window uses committer time and ends at the scanned commit. Root commits and merges are excluded. A commit touching more than the specified number of paths anywhere in the repository is excluded. Only modifications to existing regular-file contents count.
  • The subject filter recognizes conventional style, formatting and lint prefixes. It can miss mechanical edits, so inspect commit diffs before proposing a change. There is no automatic refactoring score.
  • path_changed flags observed additions, deletions or type changes to either path in the window. Exact-path counts are retained for inspection and continuity is uncertain. external_target and same_file have no two-file measurement. no_edits has no denominator. A scan with zero findings produces zero pairs.
  • Mining requires complete Git history. Supply --repo /path/to/checkout if the catalog came from another workstation. A completed window replays from SQLite even when the checkout is offline. The first history write extends an existing version-1 catalog transactionally and preserves earlier scans.

Discover import cycles

sourcesurvey cycles takes a package and a full Git checkout. This command reproduces the pytest experiment against its pinned revision. Set --days 365 for the longer window. Source Survey prints the five leading cycles by history and any component-splitting edges whose local uses appear confined to a type-checking block.

sourcesurvey cycles --repo ../pytest \
  --rev 6665a79fb9a6553ce4e1be5574c21a9e3b769eec --source-root src --package _pytest \
  --days 90 --max-files 30 --db analysis.sqlite3
-- History-ranked examples of circular paths through the import graph.
SELECT rank, witness, min_joint, round(min_jaccard, 3) AS min_jaccard, status
FROM cycle_candidates WHERE run_id = 1 ORDER BY rank LIMIT 5;

-- Find small changes for review without specifying an importer or target.
SELECT e.source_path, s.line, s.statement, e.guarded_use_lines,
       e.released_modules, e.both_commits, e.either_commits
FROM cycle_edges e JOIN cycle_sites s USING (run_id, importer, imported)
WHERE e.run_id = 1 AND e.released_modules > 0 AND e.guarded_uses_only = 1
ORDER BY e.released_modules DESC, e.source_path, s.line;
  • The graph contains explicit, non-self imports between committed modules in the selected package. Function-local imports count. Grimp excludes imports under recognized TYPE_CHECKING guards. Dynamic imports, implicit package initialization and paths through other packages are outside this graph.
  • Within each strongly connected component, every cyclic edge gets a shortest directed return path, with lexical tie-breaking. Source Survey deduplicates rotations. This covers every cyclic edge without enumerating every possible cycle. Several witnesses can describe the same underlying dependency.
  • One Git history pass covers the participating paths. A witness ranks by its lowest edge-level joint edit count, then lowest edge-level fraction of edits in common, then shortest length and lexical module order. Minima can come from different edges. An absent denominator ranks as zero. Inspect the status, raw counts and commit subjects in cycle_edges and cycle_joint_commits before interpreting the score.
  • Source Survey simulates removing individual edges and records how many modules leave all cycles and the largest component left within the original one. It checks only edges in a forward or reverse spanning tree of the component. Every edge capable of splitting it lies in that union.
  • The guarded-use hint looks for a simple eager from import whose bare-name reads all occur in a positive module-level if TYPE_CHECKING body. The hint is deliberately narrow. Runtime reflection and access by downstream consumers require review. Use cycle_steps to connect an edge to its ranked witnesses and cycle_sites to inspect every source location.

Scan coverage

  • Source Survey reads regular committed .py blobs under one top-level package with an __init__.py. It stages them in a private temporary directory and analyzes them without importing the target. Uncommitted edits, tests outside the package, and stubs are outside the scan.
  • The source and internal forbidden name each select a module and its descendants. A forbidden top-level standard-library name also works. External submodules are grouped under that top-level name.
  • Grimp supplies static direct import sites, including imports under TYPE_CHECKING. The boundary allows indirect imports through a public facade. Runtime loading and third-party dependency resolution are outside this MVP.
  • Missing internal scopes, incomplete module coverage, unsupported symlinks/submodules, or Git paths the host cannot represent stop publication. The optional rule reference records the policy rationale supplied by the caller.

The source checkout includes the experiment reports, trial patches, and original SQLite catalogs under pilot/. Start with pilot/pytest-cycles.md for the origin of the guarded-use check and pilot/django-cycles.md for its application to 909 modules. To run the integration suite from a source checkout, use python -m unittest discover -s tests -v in the activated virtual environment.