GTO (Git Tag Ops)

1.9.0 · active · verified Sat Apr 11

GTO (Git Tag Ops) is an open-source Python library designed to transform your Git repository into an Artifact Registry, particularly suited for Machine Learning models. It facilitates tracking new artifact versions, managing their lifecycle through defined stages, and automating integrations with CI/CD systems using a Git-native approach. The library is currently at version 1.9.0 and maintains a steady release cadence with frequent minor and patch updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `gto.api` to register an artifact and assign it to a stage within a Git repository. It simulates a basic Git workflow, registers 'my-model' from a 'model.pkl' file, and then promotes it to a 'dev' stage, finally showing the registry's state. Note that in a real scenario, `git push --tags` would be necessary to synchronize the GTO-managed tags with a remote repository.

import os
from pathlib import Path
import tempfile
import shutil
from gto import api

# Create a temporary directory for a mock Git repo
original_cwd = os.getcwd()
temp_dir = Path(tempfile.mkdtemp())
os.chdir(temp_dir)

try:
    # Initialize a Git repository
    os.system('git init -b main')
    os.system('git config user.email "test@example.com"')
    os.system('git config user.name "Test User"')
    
    # Create a dummy artifact file
    (temp_dir / "model.pkl").write_text("dummy_model_content")
    os.system('git add .')
    os.system('git commit -m "Initial commit with model.pkl"')

    # Register a new version of an artifact
    print("\n--- Registering artifact 'my-model' ---")
    api.register("my-model", "model.pkl", type="model", description="My first model")
    print("Artifact registered successfully.\n")

    # Show the current state of the artifact registry
    print("\n--- Showing artifact registry state ---")
    registry_state = api.show(name="my-model", json=True)
    print(registry_state)

    # Promote the artifact to a 'dev' stage
    print("\n--- Promoting 'my-model' to 'dev' stage ---")
    api.assign("my-model", stage="dev", version="my-model@v0.0.1")
    print("Artifact promoted to 'dev' stage successfully.\n")

    # Show the updated state
    print("\n--- Showing updated registry state ---")
    updated_registry_state = api.show(name="my-model", json=True)
    print(updated_registry_state)

    # Important: Push the Git tags for changes to be reflected remotely
    # In a real scenario: os.system('git push origin --tags')

finally:
    os.chdir(original_cwd)
    shutil.rmtree(temp_dir)

view raw JSON →