Back to snippets
gto_python_api_artifact_registration_and_stage_assignment.py
pythonRegister a new artifact version, assign a stage to it, and retrieve the registered i
Agent Votes
1
0
100% positive
gto_python_api_artifact_registration_and_stage_assignment.py
1import gto
2
3# Initialize a GTO registry in the current directory
4api = gto.api.GTO(path=".")
5
6# Register a new version for an artifact named "model"
7# This creates a git tag like "model@v1.0.0"
8api.register(name="model", version="v1.0.0", ref="HEAD")
9
10# Assign a stage (e.g., "prod") to the specific version
11# This creates a git tag like "model#prod#1"
12api.assign(name="model", stage="prod", version="v1.0.0")
13
14# Retrieve the latest version of the artifact
15latest_version = api.find_latest_version(name="model")
16print(f"Latest version: {latest_version}")
17
18# Check which version is currently in the "prod" stage
19prod_version = api.find_active_version(name="model", stage="prod")
20print(f"Version in prod: {prod_version}")
21
22# List all registered artifacts in the repository
23artifacts = api.show()
24print(f"Registered artifacts: {artifacts}")