1+ import http
2+ import typing
3+ import pydantic
4+ import json
5+
16from simvue .api .objects .artifact .base import ArtifactBase
7+ from simvue .api .objects .base import Sort
28from .file import FileArtifact
39from simvue .api .objects .artifact .object import ObjectArtifact
410from simvue .api .request import get_json_from_response , get as sv_get
511from simvue .api .url import URL
612from simvue .exception import ObjectNotFoundError
713
8- import http
9- import typing
10- import pydantic
1114
1215__all__ = ["Artifact" ]
1316
1417
18+ class ArtifactSort (Sort ):
19+ @pydantic .field_validator ("column" )
20+ @classmethod
21+ def check_column (cls , column : str ) -> str :
22+ if column and (
23+ column not in ("name" , "created" ) and not column .startswith ("metadata." )
24+ ):
25+ raise ValueError (f"Invalid sort column for artifacts '{ column } '" )
26+ return column
27+
28+
1529class Artifact :
1630 """Generic Simvue artifact retrieval class"""
1731
@@ -146,6 +160,7 @@ def get(
146160 cls ,
147161 count : int | None = None ,
148162 offset : int | None = None ,
163+ sorting : list [ArtifactSort ] | None = None ,
149164 ** kwargs ,
150165 ) -> typing .Generator [tuple [str , FileArtifact | ObjectArtifact ], None , None ]:
151166 """Returns artifacts associated with the current user.
@@ -156,6 +171,8 @@ def get(
156171 limit the number of results, default of None returns all.
157172 offset : int, optional
158173 start index for returned results, default of None starts at 0.
174+ sorting : list[dict] | None, optional
175+ list of sorting definitions in the form {'column': str, 'descending': bool}
159176
160177 Yields
161178 ------
@@ -166,10 +183,15 @@ def get(
166183
167184 _class_instance = ArtifactBase (_local = True , _read_only = True )
168185 _url = f"{ _class_instance ._base_url } "
186+ _params = {"start" : offset , "count" : count }
187+
188+ if sorting :
189+ _params ["sorting" ] = json .dumps ([sort .to_params () for sort in sorting ])
190+
169191 _response = sv_get (
170192 _url ,
171193 headers = _class_instance ._headers ,
172- params = { "start" : offset , "count" : count } | kwargs ,
194+ params = _params | kwargs ,
173195 )
174196 _label : str = _class_instance .__class__ .__name__ .lower ()
175197 _label = _label .replace ("base" , "" )
0 commit comments