Skip to main content

IoT Storage Client Library for Python

Project description

iot-storage-client

python version pre-commit Keep a Changelog CI_CD GitHub_Actions package PyPI azure-storage-blob

This package is a wrapper around the azure-storage-blob SDK to provide an asynchronous and synchronous client for interacting with Azure storage accounts in the cloud and on the edge.

Official Documentation (async version) | Source code | Package PyPI

Table of Contents

Versioning

This repository adheres to Semantic Versioning. It will be maintained through the CHANGELOG.md and in GitHub Releases. It's important to note that you must maintain the version with your releases in iot/storage/client/_version.py, otherwise a new package version will fail to get published.

Getting Started

This section provides basic examples with the iot-storage-client.

Prerequisites

  • Python 3.7 or later is required to use this package.

  • You must have an Azure subscription and Azure storage account to use this package.

Basic Examples

  1. Install via pip:

    pip install iot-storage-client
    
  2. Import and say hello:

    from iot.storage.client import __version__
    
    
    print(f"hello world from iot-storage-client version: {__version__}")
    
  3. Basic usage:

    import tempfile
    
    from iot.storage.client import CredentialType, LocationType, IoTStorageClient
    
    # instantiate client
    storage_client = IoTStorageClient(
        credential_type=CredentialType.ACCOUNT_KEY,
        location_type=LocationType.CLOUD_BASED,
        account_name="myAzBlobStorageAcctName",
        credential="myBlobPrimaryKey***"
    )
    
    # print info w/ repr
    print(f"{storage_client.__repr__()}")
    
    # download blob to tempfile
    temp_file = tempfile.NamedTemporaryFile()
    download_result = storage_client.download_file(
        container_name="myAzBlobContainerName",
        source="path/to/blob.txt",
        dest=temp_file.name,
    )
    if not download_result:
        print("unable to download file")
        temp_file.close()
        raise
    
    # upload tempfile to blob
    upload_result = storage_client.upload_file(
        container_name="myAzBlobContainerName",
        source=temp_file.name,
        dest="path/to/new/blob.txt",
    )
    if not upload_result:
        print("unable to upload file")
        temp_file.close()
        raise
    
    # clean-up local memory
    temp_file.close()
    
  4. Basic async usage:

    import tempfile
    
    from iot.storage.client import CredentialType, LocationType, IoTStorageClientAsync
    
    # instantiate client
    storage_client = IoTStorageClientAsync(
        credential_type=CredentialType.ACCOUNT_KEY,
        location_type=LocationType.CLOUD_BASED,
        account_name="myAzBlobStorageAcctName",
        credential="myBlobPrimaryKey***"
    )
    
    # print info w/ repr
    print(f"{storage_client.__repr__()}")
    
    # download blob to tempfile
    temp_file = tempfile.NamedTemporaryFile()
    download_result = await storage_client.download_file(
        container_name="myAzBlobContainerName",
        source="path/to/blob.txt",
        dest=temp_file.name,
    )
    if not download_result:
        print("unable to download file")
        temp_file.close()
        raise
    
    # upload tempfile to blob
    upload_result = await storage_client.upload_file(
        container_name="myAzBlobContainerName",
        source=temp_file.name,
        dest="path/to/new/blob.txt",
    )
    if not upload_result:
        print("unable to upload file")
        temp_file.close()
        raise
    
    # clean-up local memory
    temp_file.close()
    

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

iot-storage-client-1.1.5.tar.gz (9.5 kB view hashes)

Uploaded source

Built Distribution

iot_storage_client-1.1.5-py3-none-any.whl (10.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page