API Reference

class ezazure.ezazure.Azure(config_fname: str = '.ezazure', *, check: bool = False)

Easy Azure interface for uploading/downloading files

Parameters
config_fname: str, optional, default=’.ezazure’

Configuration file, containing your azure connection string (which can be the actual connection string, or the name of a file that contains your connection string) and your azure container. Example:

connection_str: ~/secrets/azure
container: litmon-private

container is only the default storage container, and can be overwritten in the upload() and download() functions. If it’s not provided in this file, then you must supply container variable in upload() and download().

check: bool, optional, default=False

If config_fname cannot be read on __init__(), and check==True, then throw an error. (Otherwise, errors are only thrown on upload() and :meth`download` calls.)

By keeping check==False, then you can have code that looks like this:

from ezazure import Azure

Azure().download(fname)

and your code will succeed if:

  1. fname exists locally (regardless of whether you have Azure credentials in your config_fname file), or

  2. fname exists on your cloud and you have Azure credentials in your config_fname file.

This provides a tight cloud integration that still works even if you don’t have access to the cloud, but have the files locally.

Attributes
client: azure.storage.blob.BlobServiceClient

Client for interfacing with Azure

Methods

download(file, *[, container, regex, replace])

Download file from Azure

upload(file, *[, container, regex, replace, ...])

Upload file to Azure

download(file: str, *, container: Optional[str] = None, regex: bool = False, replace: bool = False)

Download file from Azure

Parameters
file: str

file to download

container: str, optional, default=None

if supplied, download from this container (instead of default container listed in .ezazure)

regex: bool, optional, default=False

treat file as a regex expression. download all files that match. all files will be downloaded to the same directory.

replace: bool, optional, default=False

if dest/file exists locally, then skip the download

Raises
FileNotFoundError

If file does not exist in Azure

upload(file: str, *, container: Optional[str] = None, regex: bool = False, replace: bool = True, update_listing: bool = True)

Upload file to Azure

Parameters
file: str

file to upload. This file will be uploaded as basename(file). (I.e. it will NOT be uploaded to a directory within the container, but rather to the container root level.)

container: str, optional, default=None

if supplied, download from this container (instead of default container listed in .ezazure)

regex: bool, optional, default=False

treat file as a regex expression. upload all files that match. all files must be in the same directory.

replace: bool, optional, default=True

replace existing file on server if it exists

update_listing: bool, optional, default=True

if True, and if there is public access to container, then update directory listing (with _update_listing()) after uploading

Raises
FileNotFoundError

If the file cannot be found locally