Skip to main content

A library for classifying GitHub repositories

Project description

Repository Classifier

A Python library for classifying GitHub repositories using both heuristic keyword-based and AI-powered methods.

Installation

pip install repo-classifier

Or install from source:

git clone https://github.com/YichaoXu/repo_classifier.git
cd repo_classifier
pip install -e .

Features

  • Classify repositories using keyword-based heuristic method
  • Classify repositories using AI services (OpenAI GPT, DeepSeek, etc.)
  • Built-in classifiers for PHP, Python, and JavaScript
  • Extensible system for custom classifiers
  • Multiple ways to define and load classifiers

Project Structure

repo_classifier/
├── classifier/
│   ├── __init__.py           # Exports public API
│   ├── core.py               # Core interfaces
│   ├── utils.py              # Utility functions
│   ├── registry.py           # Classifier configuration registry
│   ├── readme/               # README processing module
│   │   ├── __init__.py
│   │   ├── fetcher.py        # README fetching functionality
│   │   ├── heuristic.py      # Heuristic classification logic
│   │   └── ai_classifier.py  # AI classification logic
│   └── predefine/            # Built-in classifiers
│       ├── __init__.py
│       ├── php.py
│       ├── python.py
│       └── javascript.py
├── examples/                 # Example scripts
├── tests/                    # Test directory
├── setup.py                  # Installation configuration
├── requirements.txt          # Dependencies
└── README.md                 # This file

Usage

Basic Usage

from classifier import classify_repository_heuristic, CLASSIFIER_NAMES

# Use built-in PHP classifier
results = classify_repository_heuristic(
    "https://github.com/user/repo",
    classifier=CLASSIFIER_NAMES.PHP
)
print(results)  # {"Web App": 0.85, "Framework": 0.45, "Library": 0.30}

# Use built-in Python classifier
results = classify_repository_heuristic(
    "https://github.com/user/repo",
    classifier=CLASSIFIER_NAMES.PYTHON
)
print(results)  # {"Web Framework": 0.92, "Library/Package": 0.45}

# Use built-in JavaScript classifier
results = classify_repository_heuristic(
    "https://github.com/user/repo",
    classifier=CLASSIFIER_NAMES.JAVASCRIPT
)
print(results)  # {"Frontend Framework": 0.88, "JavaScript Library": 0.40}

Using AI Classification

from classifier import classify_repository_ai, CLASSIFIER_NAMES

# Use AI classification with built-in PHP project types
results = classify_repository_ai(
    "https://github.com/user/repo",
    api_key="your_api_key",
    classifier=CLASSIFIER_NAMES.PHP,
    model_name="gpt-3.5-turbo"
)
print(results)

Using CLASSIFIER_NAMES

The CLASSIFIER_NAMES object provides a convenient way to access the built-in classifier names:

from classifier import CLASSIFIER_NAMES

# Access individual classifier names
php_classifier = CLASSIFIER_NAMES.PHP       # "php"
python_classifier = CLASSIFIER_NAMES.PYTHON # "python"
js_classifier = CLASSIFIER_NAMES.JAVASCRIPT # "javascript"

# Get a list of all classifier names
all_classifiers = CLASSIFIER_NAMES.all()    # ["php", "python", "javascript"]

# Get a list of available classifier names
available = CLASSIFIER_NAMES.available()    # ["php", "python", "javascript"]

Custom Classifier Definition

from classifier import classify_repository_heuristic, register_classifier

# Define custom classifier
custom_config = {
    "Web Framework": {
        "mvc": 10,
        "web framework": 10,
        "router": 8,
        "controller": 8
    },
    "API Service": {
        "api": 10,
        "rest": 10,
        "json": 8,
        "http": 8
    }
}

# Register custom classifier
register_classifier("custom", custom_config)

# Use registered classifier
results = classify_repository_heuristic(
    "https://github.com/user/repo",
    classifier="custom"
)
print(results)

Loading Classifiers from Python Modules

from classifier import load_classifier_from_module, classify_repository_heuristic

# Import classifiers from a module
load_classifier_from_module("path/to/my_classifiers.py")

# Use imported classifier
results = classify_repository_heuristic(
    "https://github.com/user/repo",
    classifier="data_science"
)
print(results)

Creating Classifiers from Text Files

from classifier import create_classifier_from_file, register_classifier

# Create classifier from text file
game_dev_config = create_classifier_from_file("path/to/game_dev.txt")

# Register classifier
register_classifier("game_dev", game_dev_config)

# Use registered classifier
results = classify_repository_heuristic(
    "https://github.com/user/repo",
    classifier="game_dev"
)
print(results)

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run all tests
pytest

# Run tests with coverage
pytest --cov=classifier

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-0.1.1.tar.gz (21.6 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-0.1.1-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: repo_classifier-0.1.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for repo_classifier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eecfa8fce172ffe9094b63c7df42a7e7904fdbaed7c4fa9e7baed1c2a4762ad1
MD5 b8790e6a091afdc2af771f2b03cae456
BLAKE2b-256 db64e2953f2da6c221ad0af615ede496c7f953cdb61b3181676bf8e4ce2b40c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for repo_classifier-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec39cc62581c5d951269de7a52940cbb950523836a26a34537c5cc40c83c164a
MD5 b4d5a9cb2a9b75634f1184f168146a0c
BLAKE2b-256 ddeabe6e446b3532947b24e1cff4582c9c6201d34e837091b5fe94ddfd2d331c

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