File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
docs/book/how-to/snapshots
tests/integration/functional/cli Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,20 @@ Learn how to get a bearer token for the curl commands:
197197- For Pro management API (` cloudapi.zenml.io ` ): use [ Pro API tokens] ( https://docs.zenml.io/api-reference/pro-api/getting-started#programmatic-access-with-api-tokens ) .
198198{% endhint %}
199199
200+ ## Deleting Pipeline Snapshots
201+
202+ You can delete a snapshot using the CLI:
203+ ``` bash
204+ zenml pipeline snapshot delete < SNAPSHOT-NAME-OR-ID>
205+ ```
206+
207+ You can also delete a snapshot using the Python SDK:
208+ ``` python
209+ from zenml.client import Client
210+
211+ Client().delete_snapshot(name_id_or_prefix = < SNAPSHOT - NAME - OR - ID > )
212+ ```
213+
200214## Advanced Usage: Running Snapshots from Other Pipelines
201215
202216You can run snapshots from within other pipelines, enabling complex workflows. There are two ways to do this:
Original file line number Diff line number Diff line change @@ -1276,3 +1276,36 @@ def list_pipeline_snapshots(**kwargs: Any) -> None:
12761276 "code_path" ,
12771277 ],
12781278 )
1279+
1280+
1281+ @snapshot .command ("delete" , help = "Delete a pipeline snapshot." )
1282+ @click .argument ("snapshot_name_or_id" , type = str , required = True )
1283+ @click .option (
1284+ "--yes" ,
1285+ "-y" ,
1286+ is_flag = True ,
1287+ help = "Don't ask for confirmation." ,
1288+ )
1289+ def delete_pipeline_snapshot (
1290+ snapshot_name_or_id : str , yes : bool = False
1291+ ) -> None :
1292+ """Delete a pipeline snapshot.
1293+
1294+ Args:
1295+ snapshot_name_or_id: The name or ID of the snapshot to delete.
1296+ yes: If set, don't ask for confirmation.
1297+ """
1298+ if not yes :
1299+ confirmation = cli_utils .confirmation (
1300+ f"Are you sure you want to delete snapshot `{ snapshot_name_or_id } `?"
1301+ )
1302+ if not confirmation :
1303+ cli_utils .declare ("Snapshot deletion canceled." )
1304+ return
1305+
1306+ try :
1307+ Client ().delete_snapshot (name_id_or_prefix = snapshot_name_or_id )
1308+ except KeyError as e :
1309+ cli_utils .exception (e )
1310+ else :
1311+ cli_utils .declare (f"Deleted snapshot '{ snapshot_name_or_id } '." )
Original file line number Diff line number Diff line change @@ -482,3 +482,16 @@ def test_pipeline_build_delete(clean_client: "Client"):
482482
483483 # this now fails because the build doesn't exist anymore
484484 assert runner .invoke (delete_command , [str (build_id ), "-y" ]).exit_code == 1
485+
486+
487+ def test_pipeline_snapshot_delete (clean_client : "Client" ):
488+ """Test that `zenml pipeline snapshots delete` works as expected."""
489+ snapshot_id = pipeline_instance .create_snapshot (name = "test_snapshot" ).id
490+ runner = CliRunner ()
491+ delete_command = (
492+ cli .commands ["pipeline" ].commands ["snapshot" ].commands ["delete" ]
493+ )
494+ result = runner .invoke (delete_command , [str (snapshot_id ), "-y" ])
495+ assert result .exit_code == 0
496+ with pytest .raises (KeyError ):
497+ clean_client .get_snapshot (str (snapshot_id ))
You can’t perform that action at this time.
0 commit comments