IoT Storage Client Library for Python
Project description
iot-storage-client
This package is a wrapper around the azure-storage-blob SDK.
Table of Contents
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
-
Install via pip:
pip install iot-storage-client
-
Import and say hello:
from iot.storage.client import __version__ print(f"hello world from iot-storage-client version: {__version__}")
-
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()
API Documentation
IoTStorageClient Class
A wrapper client to interact with the Azure Blob Service at the account level.
This client provides operations to list, create and delete storage containers and blobs within the account.
IoTStorageClient(credential_type, location_type, account_name, credential, host=None, port=None)
Parameters
-
credential_type
strThe type of credential that will be used for authentication. One of "ACCOUNT_KEY" or "CONNECTION_STRING".
-
location_type
strThe location of the Azure storage account. This allows for communicating with storage accounts that live on IoT Edge devices. One of "CLOUD_BASED" or "EDGE_BASED".
-
account_name
strThe name of the Azure storage account.
-
credential
strThe credential (account key or connection string), that is being used for authentication.
-
host
Optional[str]The DNS or IP address of the Azure storage account when it lives on an IoT Edge device.
-
port
Optional[str]The open port of the Azure storage account when it lives on an IoT Edge device.
Container Exists Method
Check if a container exists.
storage_client.container_exists(container_name)
Parameters
-
container_name
strThe name of the container within the Azure storage account to check for existence.
Returns
Returns a boolean - true if the container exists, false if it doesn't exist.
File Exists Method
Check if a file exists.
storage_client.file_exists(container_name, file_name)
Parameters
-
container_name
strThe name of the container within the Azure storage account that the file is in.
-
file_name
strThe name of the file/path to the file within the Azure storage account to check for existence.
Returns
Returns a boolean - true if the file exists, false if it doesn't exist.
Download File Method
Download a file to a path on the local filesystem.
storage_client.download_file(container_name, source, dest)
Parameters
-
container_name
strThe name of the container within the Azure storage account that the file is in.
-
source
strThe name of the file/path to the file within the Azure storage account to download.
-
dest
strThe name of the file/path to the file on the local filesystem to download to.
Returns
Returns a boolean - true if the file was downloaded, false if it was not.
Upload File Method
Upload a file to a path inside the container.
storage_client.upload_file(container_name, source, dest, content_type="application/octet/stream", overwrite=True)
Parameters
-
container_name
strThe name of the container within the Azure storage account that the file will be uploaded to.
-
source
strThe name of the file/path to the file on the local filesystem to use for uploading.
-
dest
strThe name of the file/path to the file within the Azure storage account to upload to/create.
Returns
Returns a boolean - true if the file was uploaded, false if it was not.
Delete File Method
Delete a file from a path inside the container.
storage_client.delete_file(container_name, path)
Parameters
-
container_name
strThe name of the container within the Azure storage account that the file is located in.
-
path
strThe path to the file within the Azure storage account to delete.
Returns
Returns a boolean - true if the file was deleted, false if it was not.
Contributing
Contributions and suggestions are welcomed. However, there is a level of responsibility placed on the contributor to follow best-practices, provide thorough testing, follow the branching strategy, use the pull request template, and maintain a positive and coachable attitude when receiving feedback or questions on your code.
Versioning
This repository adheres to Semantic Versioning. It will be maintained through the CHANGELOG.md
- as is standard with PyPI packages 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.
Deployment Process
-
Linting, testing and building occurs when a pull request is made from a
features/*
branch to themaster
branch. -
Deployments to PyPI occur when an approved user triggers the GitHub Action. If the version has not been updated, this deployment will fail.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for iot_storage_client-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33c2504c54d75693ae4e09113a06f18945e3b6a9dcde43f3bb3eec57bbe552cc |
|
MD5 | 5f21bae5ae10eedacf40f8c1d7ff498e |
|
BLAKE2b-256 | a755e6852ff1fe7cedf4afd59b2711230b582f28fcbe1fc371d44c224220a569 |