Skip to main content

CLI tool for managing machine learning models in GitLab's Model Registry

Project description

GitLab ML CLI

A command-line interface tool for managing machine learning models in GitLab's Model Registry. This tool provides a seamless experience for ML teams to version, track, and deploy their models using GitLab's infrastructure.

Features

  • Model Registry Management:
    • Create, delete, and list models
    • Manage model metadata and tags
    • Track model lineage and dependencies
  • Model Versioning:
    • Upload new model versions with semantic versioning
    • Download specific versions for deployment
  • Access Control:
    • GitLab authentication and authorization

Installation

Using pip

pip install gitlab-ml

Using Poetry

poetry add gitlab-ml

From Source

git clone https://gitlab.com/ahmetoner/gitlab-ml.git
cd gitlab-ml
poetry install

Configuration

Configuration File

Create a configuration file at ~/.config/gitlab-ml/config.yml:

gitlab:
  # GitLab instance URL
  url: "https://gitlab.com"
  
  # Personal access token with api scope
  token: "your-personal-access-token"
  
  # Default project for model registry
  default_project: "group/project"

Environment Variables

Alternative to config file, you can use environment variables:

# Required settings
export GITLAB_ML_TOKEN="your-personal-access-token"
export GITLAB_ML_URL="https://gitlab.com"
export GITLAB_ML_PROJECT="group/project"

Usage

Model Management

# List all models with different output formats
gitlab-ml models list
gitlab-ml models list --format json
gitlab-ml models list --format yaml

# Create a new model with tags
gitlab-ml models create my-model \
    --description "My ML model" \
    --tag "production" \
    --tag "tensorflow"

# Delete a model (with confirmation)
gitlab-ml models delete my-model

# Force delete without confirmation
gitlab-ml models delete my-model --force

Version Management

# Upload a new model version
gitlab-ml models upload my-model ./model.pkl \
    --version "1.0.0"

# Upload a directory of model artifacts
gitlab-ml models upload my-model ./model_dir \
    --version "1.1.0"

# Download a specific version
gitlab-ml models download my-model \
    --version "1.0.0" \
    --output ./models/

Development

  1. Clone the repository:

    git clone https://gitlab.com/ahmetoner/gitlab-ml.git
    cd gitlab-ml
    
  2. Install development dependencies:

    poetry install --with dev
    
  3. Activate virtual environment:

    poetry shell
    
  4. Run tests:

    # Run all tests
    poetry run pytest
    
    # Run with coverage
    poetry run pytest --cov=gitlab_ml
    
    # Run specific test file
    poetry run pytest tests/test_models.py
    
  5. Code formatting and linting:

    # Format code
    poetry run black .
    poetry run isort .
    
    # Run linters
    poetry run mypy .
    poetry run ruff .
    

Troubleshooting

Common Issues

  1. Authentication Errors

    Error: GitLab authentication failed
    
    • Verify your token has the correct permissions (api scope)
    • Check if token is expired
    • Ensure GitLab URL is correct
  2. Project Access

    Error: Project not found or no access
    
    • Verify project path is correct
    • Check if you have sufficient permissions
    • Ensure project exists and is accessible
  3. Upload Failures

    Error: Failed to upload model version
    
    • Check file permissions
    • Verify disk space
    • Ensure version follows semver format

API Documentation

Python API

from gitlab_ml.api.client import get_gitlab_client
from gitlab_ml.api.models import ModelRegistry

# Initialize client
client = get_gitlab_client()
registry = ModelRegistry(client)

# List models
models = registry.list_models()

# Upload model
registry.upload_version(
    model_name="my-model",
    version="1.0.0",
    path="./model.pkl"
)

REST API Integration

The CLI integrates with GitLab's REST and GraphQL APIs. For custom integrations, refer to:

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a merge request

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

gitlab_ml-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

gitlab_ml-0.1.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file gitlab_ml-0.1.0.tar.gz.

File metadata

  • Download URL: gitlab_ml-0.1.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.21 Linux/6.8.0-1021-azure

File hashes

Hashes for gitlab_ml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d8a6f7ee17aef317b1902914710afb8942c00d18fcd26f30bbc6b8169189408
MD5 47dd3a6cf6fa0360437214ce569a53c6
BLAKE2b-256 46d68d9d44bb033289163a7080de09b511ef9c8de036031d0a830123c51c36f6

See more details on using hashes here.

File details

Details for the file gitlab_ml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gitlab_ml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.21 Linux/6.8.0-1021-azure

File hashes

Hashes for gitlab_ml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35fb281e253d0734bd660de7398501d19dfc0c94111c0c9cd026a4766c578c63
MD5 6deb014eb8fed1ac82b2ef166be50408
BLAKE2b-256 e4a9eb90fcb165d5ae41f918ab06f42d6446b5d1e6e79727916620d15dad2418

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