Skip to main content

Blob mapping utility for easy translation between azure urls and local paths

Project description

Blob mapping utility

When your code needs to access many mapped blobs as a mounted folder, the utility to make translation between blob urls and filepaths easier was made. It can be configured using the configuration json file.

You can also use this utility to download and uploads the blobs to/from the local file system without having to worry about the filepaths.

Configuration file example:

{
  "blob_mounting_configurations": [
    {
      "storage_account_name": "examplestagingstrgacc",
      "storage_account_url": "https://examplestagingstrgacc.blob.core.windows.net/",
      "container_name": "example-container-raw",
      "mount_point": "/mnt/example-container-raw"
    }
  ]
}

How to use

from blob_mounting_helper_utility import BlobMappingUtility
json_config_file = "blob_mapping_config.json"

# read the file into a dictionary
with open(json_config_file) as json_file:
    config = json.load(json_file)["blob_mounting_configurations"]

# create the utility object
blob_mapping_utility = BlobMappingUtility(config)

filepath1 = "/mnt/example-container-raw/cool_picture.png
blob_url = blob_mapping_utility.get_url_from_mounted_filepath(filepath1) # -> https://examplestagingstrgacc.blob.core.windows.net/example-container-raw/cool_picture.png

filepath2 = get_mounted_filepath_from_url(blob_url) # -> /mnt/example-container-raw/cool_picture.png

Also, if you were to pass the azure storage account key you can download and upload the blob to a local file path:

from blob_mounting_helper_utility import BlobMappingUtility
json_config_file = "blob_mapping_config.json"

# read the file into a dictionary
with open(json_config_file) as json_file:
    config = json.load(json_file)["blob_mounting_configurations"]

azure_storage_account_key = "example_key"
# create the utility object
blob_mapping_utility = BlobMappingUtility(config, azure_storage_account_key)
url = "https://examplestagingstrgacc.blob.core.windows.net/example-container-raw/cool_picture.png"
blob_mapping_utility.download_blob(url) # -> Downloads the blob to the local file path "/mnt/example-container-raw/cool_picture.png"
local_filepath = "/mnt/example-container-raw/cool_picture.png"
do_something_to_file(local_filepath)
blob_mapping_utility.upload_blob(local_filepath) # -> Uploads the file to the blob url
blob_mapping_utility.cleanup_files() # cleans both downloaded and uploaded files from the local file system

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blob_mounting_helper_utility-1.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file blob_mounting_helper_utility-1.1.1.tar.gz.

File metadata

File hashes

Hashes for blob_mounting_helper_utility-1.1.1.tar.gz
Algorithm Hash digest
SHA256 45c18448bf1e76d9c9e060e17224d5eaee600a7f4daab29d37b7d27dda8e7f2d
MD5 76041e84dcacdaf2c1f3bfdfdb0fb047
BLAKE2b-256 df729ba1fb1cc32e39e0c950938c7afd47526746d13d8f3351c5160ba6f8524a

See more details on using hashes here.

File details

Details for the file blob_mounting_helper_utility-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for blob_mounting_helper_utility-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5cea4644bedb2b39f79b2c7a24876175192ad8fce25e7937e40fe192bcc45c0c
MD5 c13f9936603ddd628ee63b515aa3f9bd
BLAKE2b-256 c3239db8757370810863217bd33c6af3a951306b7d15d709cc2ffd3cde148879

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page