Skip to main content

A library for classifying GitHub repositories

Project description

Repository Classifier

Classifies GitHub repositories by project type using a cascade: Ground Truth → File-type inference → Heuristic or LLM. Built-in classifiers: PHP, Python, JavaScript.

Installation

pip install repo-classifier

From source (uses uv):

git clone https://github.com/samhsu-dev/repo_classifier.git
cd repo_classifier
uv sync

Usage

from repo_classifier import classify_repository_heuristic, classify_repository_aimodel, CLASSIFIERS

# Heuristic (no API key)
results = classify_repository_heuristic(
    "https://github.com/laravel/laravel",
    classifier=CLASSIFIERS.php,  # or "php"
    top_n=3,
)
# {"Framework": 0.95, ...}

# LLM: set api_key and model_name (provider/model, e.g. openai/gpt-4o); optional: docs/.env (see docs/.env.example)
results = classify_repository_aimodel(
    "https://github.com/django/django",
    classifier=CLASSIFIERS.python,
    model_name="openai/gpt-4o",
    api_key="sk-...",
)

Advanced usage

Custom classifier — register a name → type/weight map; then pass the name to classify_repository_heuristic or classify_repository_aimodel.

from repo_classifier import register_classifier, classify_repository_heuristic

register_classifier("game", {"Game Engine": {"engine": 10, "game": 8}, "Tool": {"editor": 10}})
classify_repository_heuristic("https://github.com/...", classifier="game", top_n=2)

Classifier from file or module — File format: TYPE: TypeName then keyword: weight per line. create_classifier_from_file(path) returns a config dict; pass to classification or register_classifier. load_classifier_from_module(module_path, attribute_name=None) registers config(s) from a module.

from repo_classifier import create_classifier_from_file, register_classifier, load_classifier_from_module

config = create_classifier_from_file("path/to/types.txt")
register_classifier("my_domain", config)
# or: load_classifier_from_module("path/to/classifiers.py")

LLM with custom type list — pass a list of type names; no registration.

classify_repository_aimodel(
    "https://github.com/...",
    classifier=["Web App", "API", "Library", "CLI"],
    model_name="openai/gpt-4o-mini",
    api_key="sk-...",
)

Ground truth and evaluationload_ground_truth(path) / save_ground_truth(path, dict); add_ground_truth_entry(url, type); evaluate_classifier(name, truth_dict) returns metrics (accuracy, precision, recall, f1).

from repo_classifier import load_ground_truth, evaluate_classifier

truth = load_ground_truth("path/to/ground_truth.json")
metrics = evaluate_classifier("php", truth)

Documentation

Doc Purpose
docs/demo.ipynb End-to-end demo; configure via docs/.env (see docs/.env.example)
docs/idea.md Concepts, architecture, data flow, cascade pipeline, scenarios
docs/design.md Public/internal API, validation, errors, cascade behaviour
docs/impl.md LLM integration (litellm), prompt and response handling

Development

Uses uv. From the repo root:

uv sync
uv run pytest
uv run pytest --cov=repo_classifier

Lint/format: uv run black, uv run isort, uv run mypy, uv run pylint (see pyproject.toml).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repo_classifier-1.0.1.tar.gz (315.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repo_classifier-1.0.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file repo_classifier-1.0.1.tar.gz.

File metadata

  • Download URL: repo_classifier-1.0.1.tar.gz
  • Upload date:
  • Size: 315.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for repo_classifier-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8fcc9ff54558b132316ec252e38ceed9ef66328140ecdae41dd6b94bdc9617b2
MD5 7f8faed14c3b6e1b8d4d007c3be4166c
BLAKE2b-256 a417bdeba68d3d91555cf55c4cd1ccb64777458d30e1b5fae25392b41b528930

See more details on using hashes here.

File details

Details for the file repo_classifier-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for repo_classifier-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3f231d23ec8456fd54f0eb9c52c5d08f966486f56f2057f3f7046e83e4c130b
MD5 6e00338fa3d2589fa8b7a43364336183
BLAKE2b-256 43730a6e1b509b5332e24c55c5bf46415c0561a4721b9f843fcfdd3a2e99db6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page