Skip to content

http

Implementation of HTTP artifact store.

HttpArtifactStore

Bases: ArtifactStore

A HTTP implementation of the MLTE artifact store.

Source code in mlte/store/artifact/underlying/http.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class HttpArtifactStore(ArtifactStore):
    """A HTTP implementation of the MLTE artifact store."""

    def __init__(
        self, *, uri: StoreURI, client: Optional[OAuthHttpClient] = None
    ) -> None:
        super().__init__(uri=uri)

        self.storage = HttpStorage(
            uri=uri, resource_type=ResourceType.MODEL, client=client
        )
        """HTTP storage."""

    def session(self) -> HttpArtifactStoreSession:
        """
        Return a session handle for the store instance.
        :return: The session handle
        """
        return HttpArtifactStoreSession(storage=self.storage)

storage = HttpStorage(uri=uri, resource_type=ResourceType.MODEL, client=client) instance-attribute

HTTP storage.

session()

Return a session handle for the store instance.

Returns:

Type Description
HttpArtifactStoreSession

The session handle

Source code in mlte/store/artifact/underlying/http.py
41
42
43
44
45
46
def session(self) -> HttpArtifactStoreSession:
    """
    Return a session handle for the store instance.
    :return: The session handle
    """
    return HttpArtifactStoreSession(storage=self.storage)

HttpArtifactStoreSession

Bases: ArtifactStoreSession

An HTTP implementation of the MLTE artifact store session.

Source code in mlte/store/artifact/underlying/http.py
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
class HttpArtifactStoreSession(ArtifactStoreSession):
    """An HTTP implementation of the MLTE artifact store session."""

    def __init__(self, *, storage: HttpStorage) -> None:
        self.storage = storage
        """HTTP Storage."""

        self.storage.start_session()

    def close(self):
        # No closing needed.
        pass

    # -------------------------------------------------------------------------
    # Model
    # -------------------------------------------------------------------------

    def create_model(self, model: Model) -> Model:
        response = self.storage.post(json=model.to_json())
        return Model(**response)

    def read_model(self, model_id: str) -> Model:
        response = self.storage.get(id=model_id)
        return Model(**response)

    def list_models(self) -> List[str]:
        response = self.storage.get()
        return typing.cast(List[str], response)

    def delete_model(self, model_id: str) -> Model:
        response = self.storage.delete(id=model_id)
        return Model(**response)

    # -------------------------------------------------------------------------
    # Version
    # -------------------------------------------------------------------------

    def create_version(self, model_id: str, version: Version) -> Version:
        response = self.storage.post(
            json=version.to_json(), groups=_version_group(model_id)
        )
        return Version(**response)

    def read_version(self, model_id: str, version_id: str) -> Version:
        response = self.storage.get(
            id=version_id, groups=_version_group(model_id)
        )
        return Version(**response)

    def list_versions(self, model_id: str) -> List[str]:
        response = self.storage.get(groups=_version_group(model_id))
        return typing.cast(List[str], response)

    def delete_version(self, model_id: str, version_id: str) -> Version:
        response = self.storage.delete(
            id=version_id, groups=_version_group(model_id)
        )
        return Version(**response)

    # -------------------------------------------------------------------------
    # Artifacts
    # -------------------------------------------------------------------------

    def write_artifact(
        self,
        model_id: str,
        version_id: str,
        artifact: ArtifactModel,
        *,
        force: bool = False,
        parents: bool = False,
    ) -> ArtifactModel:
        response = self.storage.post(
            groups=_artifact_groups(model_id, version_id),
            json=WriteArtifactRequest(
                artifact=artifact, force=force, parents=parents
            ).to_json(),
        )
        return ArtifactModel(**(response["artifact"]))

    def read_artifact(
        self,
        model_id: str,
        version_id: str,
        artifact_id: str,
    ) -> ArtifactModel:
        response = self.storage.get(
            id=artifact_id,
            groups=_artifact_groups(model_id, version_id),
        )
        return ArtifactModel(**response)

    def read_artifacts(
        self,
        model_id: str,
        version_id: str,
        limit: int = 100,
        offset: int = 0,
    ) -> List[ArtifactModel]:
        response = self.storage.get(
            groups=_artifact_groups(model_id, version_id),
            query_args={"limit": f"{limit}", "offset": f"{offset}"},
        )
        return [ArtifactModel(**object) for object in response]

    def search_artifacts(
        self,
        model_id: str,
        version_id: str,
        query: Query = Query(),
    ) -> List[ArtifactModel]:
        # NOTE(Kyle): This operation always uses the "advanced search" functionality
        response = self.storage.send_command(
            MethodType.POST,
            id="search",
            json=query.to_json(),
            groups=_artifact_groups(model_id, version_id),
        )
        return [ArtifactModel(**object) for object in response]

    def delete_artifact(
        self,
        model_id: str,
        version_id: str,
        artifact_id: str,
    ) -> ArtifactModel:
        response = self.storage.delete(
            id=artifact_id, groups=_artifact_groups(model_id, version_id)
        )
        return ArtifactModel(**response)

storage = storage instance-attribute

HTTP Storage.