Open Archive

Contents

Open Archive#

Open a file/object archive into a target directory

Parameters#

  • context: mlrun.MLClientCtx - function execution context

  • archive_url: str - url of archive file

  • subdir: str - path within artifact store where extracted files are stored

  • key: str - key of archive contents in artifact store

  • target_path: str - file system path to store extracted files

Usage#

import mlrun
import os

# Specify path
path = "/tmp/examples_ci.env"
env_dict = None

if os.path.exists(path):
    env_dict = mlrun.set_env_from_file(path, return_dict=True)

project_name = "function-marketplace"
project = mlrun.get_or_create_project(project_name, context="./", user_project=False)
> 2022-12-04 09:01:10,922 [info] loaded project function-marketplace from MLRun DB
# Declaring our zip target url
ARCHIVE_URL = "https://s3.wasabisys.com/iguazio/data/cats-vs-dogs/cats-vs-dogs-labeling-demo.zip"

# Import, mount & run
fn = mlrun.code_to_function(name='open_archive', filename='open_archive.py', kind='job', image='mlrun/mlrun', handler='open_archive')
# Use at your project with  fn = mlrun.import_function("hub://open_archive")

# Mounting
if not env_dict:
    fn.apply(mlrun.auto_mount())
    if os.getenv('MLRUN_CE','False')=='true':
        fn.spec.disable_auto_mount=False
    
run = fn.run(inputs={'archive_url': ARCHIVE_URL},
             params={'key': 'test_archive'})
> 2022-12-04 09:01:10,989 [info] starting run open-archive-open_archive uid=1ffd3a675a434e36b1f7b42260585a3d DB=http://mlrun-api:8080
> 2022-12-04 09:01:11,187 [info] Job is running in the background, pod: open-archive-open-archive-tc99d
> 2022-12-04 09:01:18,686 [info] downloading https://s3.wasabisys.com/iguazio/data/cats-vs-dogs/cats-vs-dogs-labeling-demo.zip to local temp file
> 2022-12-04 09:01:30,892 [info] Using v3io scheme, extracting to /v3io/projects/function-marketplace/artifacts/content/
> 2022-12-04 09:01:38,397 [info] run executed, status=completed
final state: completed
project uid iter start state name labels inputs parameters results artifacts
function-marketplace 0 Dec 04 09:01:18 completed open-archive-open_archive
v3io_user=dani
kind=job
owner=dani
mlrun/client_version=1.2.0-rc22
host=open-archive-open-archive-tc99d
archive_url
key=test_archive
test_archive

> to track results use the .show() or .logs() methods or click here to open in UI
> 2022-12-04 09:01:39,810 [info] run executed, status=completed