Skip to main content

open-source-repository-sampler

Reproducible, seeded, stratified sampling of open-source GitHub repositories for empirical software engineering and mining software repositories studies. Every sampled repository is pinned to the commit that met the sampling criteria.

It exists so that experiments do their study and leave choosing the repositories to one independent, auditable tool. Choosing the repositories separately from the analysis is the honest defence against selection bias: no experiment can pick or drop a repository on its result.

Two phases

  1. Sample (sample): draw candidates and check each against the criteria. Each candidate is cloned at its pinned commit, inspected, given its CSV row, then deleted. The result is the CSV and its derivation.
  2. Run (run, optional): read the CSV and, for each usable repository, clone it again at exactly that commit (shallow or deep), hand it to the experiment's hook, then delete it. The experiment only processes repositories; the sampler does all the plumbing.

Phase 2 can be run many times, by many experiments, against the same CSV.

What it produces

Two files with fixed names, so they can go straight into a paper's ancillary data and be recognised on sight:

File What it is
open-source-repository-sample.csv One row per candidate drawn: where it is (url), the exact code (commit), its detected language, the criteria measures, status (usable / excluded by the criteria / error, could not be inspected) with the reason, and the sampler_commit that produced it
open-source-repository-sample.derivation.json Opens with about: what the files are, and links to this repository, its documentation and source at the exact commit used, and the PyPI release, so a reader who finds the files in a paper's ancillary data can trace them here. Then how the sample was derived: the command as typed and fully resolved, every parameter, the sampler's version and commit, tool versions, the method in words, every GitHub query with its match count, the frozen candidate frame, and the CSV's sha256

Excluded candidates stay in the CSV, so it shows that nothing was hand-picked. Experiments use the usable rows. A candidate whose clone failed is error, not excluded: loss to infrastructure is kept apart from exclusion by the criteria, because it can fall unevenly (a clone timeout falls hardest on the largest projects), and the derivation reports its rate.

--label java-v2 gives open-source-repository-sample.java-v2.csv (and its derivation), so several samples can sit side by side.

Install

From PyPI (a released version, pinned):

pip install open-source-repository-sampler==0.3.1

From git, for experiments not written in Python (the command runs on its own):

git clone --branch v0.2.1 https://github.com/officefloor/open-source-repository-sampler.git
python3 -m venv .venv && .venv/bin/pip install ./open-source-repository-sampler

It needs git, and the GitHub CLI gh authenticated (gh auth login) for drawing a sample. Using an existing sample needs only git.

Draw a sample

open-source-repository-sampler sample \
    --langs java --tiers high,mid,low --target 30 --seed 1 \
    --min-functions 50 --min-commits 500 \
    --exclude-owners my-org,my-user \
    --out-dir sample
  • Strata. A stratum is a language × popularity tier: high (>5000 stars), mid (1000–5000), low (200–999). Stars measure attention, not quality; the tiers are there so a sample spans the range of attention rather than only its top.
  • The frame is the whole stratum. GitHub search returns at most 1000 results per query, so each tier is split into star bands (then creation-date bands) until every band matches at most 1000 repositories, and every band is fetched whole. The frame is the complete population of the stratum as GitHub search lists it, every repository has the same chance of being drawn, and the seeded shuffle is a simple random sample within the stratum. The derivation lists every band, its query and match count, and every repository enumerated. A search that fails stops the run rather than leaving a gap; a band that cannot be split below the cap is reported as truncated. Enumerating costs about one request per 100 repositories; a popular language's low tier takes minutes.
  • Growth. Each language draws one candidate per tier per round until it has --target usable repositories exactly, or its strata run out. That outcome is reported in the derivation, not hidden.
  • Allocation is disproportionate. Tiers are drawn equally regardless of population, so the pooled sample over-represents high-star repositories, and the usable split across tiers follows each tier's exclusion rate. Comparisons between tiers need no weights. Estimates about the population do: weight each stratum by population / usable, both in the derivation's summary.per_stratum.
  • As of a date (--as-of 2020-12-01). For a study of code written before a date, such as before AI coding assistants. Only repositories created before the date enter the frame; each is pinned to the newest commit on its default branch's first-parent history whose committer date is before the date, and the criteria and the language are judged on that commit. Its history is fetched without trees or contents (--filter=tree:0), so finding the commit is cheap, and only that commit's tree is checked out. The CSV gains head_commit, the default branch's commit when drawn, beside the pin; a repository with no commit before the date is excluded, and verify --fetch derives each as-of commit again. What it cannot correct, and the derivation says so: the stars, the tiers and the frame are GitHub's today, so a repository deleted since is missing and a tier is its popularity now; committer dates can be misstated by rebased history. Without --as-of the sample is exactly as before.
  • Fix the seed first. The seed is the one value that chooses the sample. Record it (in the experiment's step script, or a pre-registration) before the first draw, and use the first sample drawn. Re-drawing with new seeds until a sample looks right is selection by another name, and the derivation cannot detect it.
  • Pinned commit. Each candidate is cloned at its default branch as it is when drawn. That commit is recorded, and every measure and criterion describes the code at that commit. The clone is deleted once its row is written.
  • Only as much clone as the criteria need. The clone is shallow (depth 1) unless a history criterion (--min-commits, --min-contributors, --min-agent-commits) is set. Only then is the full history fetched, blobless (every commit, but file contents only at the pinned commit), so the history counts are exact. Without a history criterion, n_commits, n_contributors and first_commit_date are left empty rather than guessed. Sampling starts by saying which clone it will use and why, before any download, so the cost is known up front. The derivation records it under sampling_clone: the mode (shallow or full-history), the exact git clone flags, and the criteria that required it.
  • Language detection. The language is detected from the project's own source code (tests, vendored and generated files excluded; build-output directories excluded at the repository root only, since deeper down build and target are ordinary package names). .h headers are measured but do not vote between C and C++; the unambiguous files decide. A repository counts toward its detected language, so a C++ project labelled C on GitHub counts as C++. Both labels are in the CSV (language, stratum_language), as is whether GitHub lists the repository as a mirror of one hosted elsewhere.
  • Criteria. The criteria are generic and fixed before any study looks at a repository: --min-functions, --min-files-with-functions, --min-source-files, --min-nloc, --min-commits, --min-contributors, --min-agent-commits, --min-language-share. Function counts come from lizard, which counts different constructs in different languages (and cannot exclude Rust's inline test modules), so one --min-functions bound is a different threshold per language; compare across languages with that in mind. Files lizard could not parse are counted in n_unparsed_files.
  • Declared agent commits (--min-agent-commits 30). For a study of code an AI coding agent says it wrote. A commit is a declared agent commit when its author or committer is an agent's account, or its message carries an agent's Co-authored-by trailer or the line the agent adds to what it generates. The signatures are built in (agents.py: Claude Code, GitHub Copilot's coding agent, Cursor, Devin, Codex, Jules, aider, OpenHands), each marked documented (from the agent's own documentation) or observed (the identity its commits carry), fixed per release, and written into the derivation (sampling_clone.agent_signatures), so a sample states exactly what it counted. Whenever the history is read (any history criterion), the CSV gains n_agent_commits, first_agent_commit_date and agents (claude:412;copilot:9). It counts what commits say, not who wrote the code: assisted code committed under a person's name with no marker is not counted, and a trailer can be added or removed by hand. So the count is a lower bound, a repository below the bound is not thereby free of AI-written code, and the commits around a declared one are of unknown origin. Combine it with --as-of for the opposite case: code from before the assistants existed.
  • Resume. An interrupted run resumes from its checkpoint (from the same frozen frame) when you re-run the same command.
  • Safety. A sample is never silently replaced; pass --overwrite to replace one. A sampler with uncommitted changes refuses to run, because its commit would not describe the code that ran. --allow-dirty runs anyway and records that it was dirty.

open-source-repository-sampler sample --help lists every option and its default.

Use a sample

An experiment never has to clone anything itself. The sampler gets each usable repository exactly as it was sampled, with nothing after the pinned commit:

  • shallow (default): only the pinned commit's code.
  • deep (--deep): every commit up to and including the pinned commit, and none after it. For history studies.

Both fetch by commit straight from the URL, with no tags and no remote configured, so later commits are not in the clone and cannot be fetched into it by accident.

The history up to a pinned commit cannot change. A commit's id is a hash over its content and its parents, so if a project later rewrites its history, the pinned commit is either still served, with exactly the sampled history, or no longer served, and the clone fails loudly. It never silently gives different code. A deep clone's commit count is also checked against the n_commits recorded at sampling (when the sample was drawn with a history criterion), which catches an incomplete clone.

Run an experiment on every repository

run is the loop. For each usable repository it clones it (shallow or deep), runs your command on it, then deletes the clone, so disk use stays at one repository at a time. Every clone can be made again from the sample.

open-source-repository-sampler run sample/open-source-repository-sample.csv --deep \
    --run-log results/run-log.jsonl \
    -- my-experiment --repo {path} --out results/{full_name}
  • Placeholders. {path}, {url}, {commit}, {full_name}, {language} and {deep} are replaced in the command. The same values are in the environment as SAMPLED_REPOSITORY_PATH, SAMPLED_REPOSITORY_URL, SAMPLED_REPOSITORY_COMMIT, SAMPLED_REPOSITORY_FULL_NAME, SAMPLED_REPOSITORY_LANGUAGE and SAMPLED_REPOSITORY_DEEP. This works for an experiment written in any language.
  • Failures. A non-zero exit is recorded as a failure, and the loop moves on (--fail-fast stops at the first failure). It exits non-zero if any repository failed.
  • Resume. With --run-log, every outcome is appended to that file, and a re-run skips repositories already done, so an interrupted run resumes and a failed repository is retried.
  • Options. --langs java limits the run to a subset; --work-dir chooses where clones go; --keep keeps them.
  • Only the files you read. --only .java,pom.xml downloads just the files with those extensions (any case) or names, at any depth; images, jars and the rest are never fetched, which is most of the download for many repositories. The commit's trees come without file contents (a partial clone), a sparse checkout holds only the matching files, and only their contents are downloaded. Each file is byte-identical to a full clone's; the commit and, with --deep, its history are unchanged. A glob or path is refused, so a typo cannot silently leave an empty clone. List every file the experiment reads.

From Python, the same loop:

from open_source_repository_sampler import for_each

def experiment(repo):
    # repo.path, repo.commit, repo.full_name, repo.language, repo.deep, repo.row (the CSV row),
    # repo.only (the extensions and names the clone holds, None for all)
    ...

for_each("sample/open-source-repository-sample.csv", experiment, deep=True,
         run_log="results/run-log.jsonl", only=[".java", "pom.xml"])

Other commands

open-source-repository-sampler checkout sample --dest repos [--deep] [--only .java]  # keep them
open-source-repository-sampler verify sample --fetch  # CSV matches its derivation; commits fetchable

read_sample(path) returns the usable rows from Python. From any other language, the CSV is the interface: filter on status == usable.

In an experiment

The intended flow for a study, using numbered step scripts (templates in examples/):

Step Script What it does
1 step1_setup.sh Installs the experiment and a pinned version of this sampler
2 step2_sample.sh Draws the sample into sample/
3 step3_run.sh Runs the experiment on every repository in sample/open-source-repository-sample.csv with open-source-repository-sampler run

Skip step 2 by supplying an existing sample: copy another study's two sample files into sample/, or point step 3 at them. Experiments that run on the same files study exactly the same code. A new seed gives a completely different set of repositories.

Reproducibility

  • The same code. The CSV pins every repository to a commit. run and checkout get exactly that code, and with --deep exactly that history, at any later date, as long as the host still serves it. If it no longer does (the project was deleted, or rewrote its history and the old commits were removed), the clone fails rather than returning different code. verify --fetch checks this for the whole sample.
  • The same method. reproduce.the_method in the derivation is a ready-to-run script: it checks out this sampler at the commit that drew the sample and runs the fully resolved command. GitHub changes over time (stars move, repositories come and go), so re-running reproduces how the sample was drawn, not necessarily the identical list. The CSV is the record of what was drawn.
  • The same sampler. Each row and the derivation carry the sampler's commit. For an installed (not cloned) sampler, the commit is stamped in at build time by setuptools-scm.
  • Unchanged files. The derivation holds the CSV's sha256, so an edited CSV is detected by verify.

To cite a sample: open-source-repository-sample.csv (sha256 …), drawn by open-source-repository-sampler 0.1.0 @ <commit>, seed 1, on <date>.

Releasing

Push a v* tag. The publish workflow builds the release, stamping the tag's commit into the package, and publishes it to PyPI by Trusted Publishing (set up once, as described in .github/workflows/publish.yml).

Tests

pip install -e '.[test]' && pytest

They run offline: GitHub search is stubbed, and local git repositories stand in for candidates.

Licence

Apache-2.0.

Metadata

Release files for open-source-repository-sampler 0.4.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 open-source-repository-sampler 0.4.0
File Size Uploaded Provenance Actions
open_source_repository_sampler-0.4.0.tar.gz 69.7 kB With provenance Details for open_source_repository_sampler-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for open-source-repository-sampler 0.4.0
File Interpreter ABI Platform Actions
open_source_repository_sampler-0.4.0-py3-none-any.whl Python 3 none any Details for open_source_repository_sampler-0.4.0-py3-none-any.whl

Total release size: 118.5 kB

Release files / open_source_repository_sampler-0.4.0.tar.gz

Download URL open_source_repository_sampler-0.4.0.tar.gz
Size 69.7 kB
Tags Source
SHA-256 checksum
How to use checksums
771f5fd42aaea5ce5d39fa12c0e1e5a072f793d2fba51a7f283cc4d9c47b419b
BLAKE2b-256 checksum
How to use checksums
11915db464dac63d115a79345e39d9abd30e58e51a28ca53fcc5383df71cb782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / open_source_repository_sampler-0.4.0-py3-none-any.whl

Download URL open_source_repository_sampler-0.4.0-py3-none-any.whl
Size 48.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a49f944fee4e80ce1572a1c159fc127d9647cd0745f9d5453cb1e41bb825a553
BLAKE2b-256 checksum
How to use checksums
d183b5551d7a55dddcec722df90809acc11f3dbe8c7c7e7f966a78f5d7aecd0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for open-source-repository-sampler 0.4.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for open_source_repository_sampler-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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