File download (Experimental)¶
In this tutorial we will describe a way to retrieve files produced by patterns.
This function provides a way to download files produced by patterns during execution. All you need is to call QiskitServerless.download
function and pass tar
file name to start downloading the file. Or you can list all available file to you by calling QiskitServerless.files
.
Limitations:
only
tar
files are supportedtar
file should be saved in/data
directory during your pattern execution to be visible by.files()
method callonly
/data
directory is supported,/data/other_folder
will not be visible
⚠ This interface is experimental, therefore it is subjected to breaking changes.
⚠ This provider is set up with default credentials to a test cluster intended to run on your machine. For information on setting up infrastructure on your local machine, check out the guide on local infrastructure setup.
[1]:
import os
from qiskit_serverless import ServerlessClient, QiskitFunction
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
)
serverless
[1]:
<ServerlessProvider: gateway-provider>
Let’s create a pattern to write tar
file into /data
folder
[2]:
function = QiskitFunction(
title="file-producer", entrypoint="produce_files.py", working_dir="./source_files/"
)
serverless.upload(function)
[2]:
'file-producer'
[3]:
job = serverless.run("file-producer")
job
[3]:
<Job | 6ecf9f6f-a7d4-48ef-a541-db12368319b6>
[4]:
job.result()
[4]:
{'Message': 'my_file.txt archived into my_file.tar'}
Now we can look at files available using files
method
[ ]:
available_files = serverless.files()
available_files
And download them if needed using download
method
[6]:
if len(available_files) > 0:
serverless.file_download(available_files[0])