Skip to main content

A library for classifying GitHub repositories

Project description

Repository Classifier

Python library that 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 (keyword + file-type cascade)
results = classify_repository_heuristic(
    "https://github.com/laravel/laravel",
    classifier=CLASSIFIERS.php,  # or "php" or CLASSIFIER_NAMES.PHP
    top_n=3,
)
# {"Framework": 0.95, ...}

# LLM (same cascade, LLM fallback; requires api_key and model_name)
# model_name must be the full identifier: provider/model (e.g., openai/gpt-4o, deepseek/deepseek-chat). 
# Please also ensure the model parameters are configured correctly. For example, GPT-5.0+ requires temperature = 1, as specified by LiteLLM. 
results = classify_repository_aimodel(
    "https://github.com/django/django",
    classifier=CLASSIFIERS.python,
    model_name="openai/gpt-4o",
    api_key="sk-...",
)

Advanced usage

Custom classifier (inline config) — 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 — load from a text file or Python module and use by name.

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")  # registers all exports

LLM with custom type list — pass a list of project types instead of a built-in classifier; 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 evaluation — load repo→type mapping from JSON, evaluate a classifier and get accuracy/F1.

from repo_classifier import load_ground_truth, evaluate_classifier

truth = load_ground_truth("path/to/ground_truth.json")  # {"https://github.com/...": "Framework", ...}
metrics = evaluate_classifier("php", truth)  # {"accuracy": 0.92, "f1": 0.88, ...}

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.0.tar.gz (314.1 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.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: repo_classifier-1.0.0.tar.gz
  • Upload date:
  • Size: 314.1 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.0.tar.gz
Algorithm Hash digest
SHA256 648543be874a82ef009c7b83914b151c0731952454febf5cbef2af84ff7a44cd
MD5 bc75db73e8a2917bcb6512056755684b
BLAKE2b-256 c3336da483bd6d38331fa3132130e2d11d1d2a359995c2d53a3784bd042184ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for repo_classifier-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53e476b7121aa85605e3ef82ebf420ac44c841dff0d36ef439200f9d209c4e39
MD5 c65c2a0be50473ec55dd9b580b514e20
BLAKE2b-256 fef1cf0d6a5b5df98e8d9bd3e0d38ae653270ff20efc91c0800df1abe53d6e0e

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