Wraps Azure SDK to keep common operations short and consistent.
Project description
kleiven-azure-storage
Small helpers around Azure Table Storage and Blob Storage clients. The package wraps the Azure SDK to keep common operations short and consistent.
pip install kleiven-azure-storage
Requirements
- Python 3.10+
azure-data-tablesazure-storage-blobpython-dotenv
Configuration
The package loads environment variables via python-dotenv.
Define your Azure connection string in .env or the shell:
AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=...;
You can also pass a custom env var name to the helpers.
Quick start
Tables
from kleiven.azure.storage import get_table_storage
users = get_table_storage(table_name="users", env_variable_name = "AZURE_STORAGE_CONNECTION_STRING")
# Get an entity
entity = users.get_entity(
partition_key = 'users',
row_key = "123",
select = 'Name') # None if it partition_key, row_key does not exist in table
if entity is not None:
print(entity.get("Name", None))
# Upsert entity (replace by default)
entity = {
"PartitionKey": "users",
"RowKey": "123",
"name": "Ada",
}
# Upsert entity (replace by default)
table.upsert_entity(entity)
# Upsert entity: Merge
from azure.data.tables import UpdateMode
storage.upsert_entity(
entity=entity,
mode=UpdateMode.MERGE,
create_table_if_not_exist = True
)
# Create table if not already exist
storage.upsert_entity(
entity=entity,
create_table_if_not_exist = True
)
Blobs
from kleiven.azure.storage import get_blob_service
service = get_blob_service()
blob = service.create_and_upload_blob(
data={"hello": "world"},
container="my-container",
blob_name="example.json",
tags={"source": "demo"},
overwrite=True,
)
if blob is not None:
print(blob.container, blob.blob)
print(blob.metadata)
API overview
Helper functions
get_table_service(env_variable_name="AZURE_STORAGE_CONNECTION_STRING")get_table_storage(table_name, env_variable_name="AZURE_STORAGE_CONNECTION_STRING")get_blob_service(env_variable_name="AZURE_STORAGE_CONNECTION_STRING")get_blob_storage(container, blob, env_variable_name="AZURE_STORAGE_CONNECTION_STRING")
TableStorage
TableStorage wraps azure.data.tables.TableClient:
upsert_entity(entity, mode=UpdateMode.REPLACE, create_table_if_not_exist=False)get_entity(partition_key, row_key, select=None, silent=True, create_table_if_not_exist=False)query_entities(query_filter, select=None)get_entities(entities, select=None)batch_save(entities, update_mode=UpdateMode.MERGE, create_table_if_not_exist=False)batch_delete(entities)
BlobService and BlobStorage
BlobService wraps azure.storage.blob.BlobServiceClient:
get_blob_storage(container, blob)create_and_upload_blob(data, container, blob_name, tags=None, overwrite=False)
BlobStorage exposes convenience properties:
containerblobmetadata
Notes
create_and_upload_blobreturnsNonewhenoverwrite=Falseand the blob already exists.create_table_if_not_exist=Truecurrently depends on awolfbrain.storagehelper. If you do not have that dependency, keep the flag set toFalse.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kleiven_azure_storage-0.0.4.tar.gz.
File metadata
- Download URL: kleiven_azure_storage-0.0.4.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed9dbefda939e49365621efc0c5ca8fc4b0206cf0e6b67313b79a9d677c3ca10
|
|
| MD5 |
4b30339f7b7af9bae735ce4770f0e2a5
|
|
| BLAKE2b-256 |
ec593ca94fd8d326904bd1a9cce2a23dcb70a0c1b61808e583790f3961defba2
|
Provenance
The following attestation bundles were made for kleiven_azure_storage-0.0.4.tar.gz:
Publisher:
publish-to-pypi.yml on kleiven/kleiven-azure-storage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kleiven_azure_storage-0.0.4.tar.gz -
Subject digest:
ed9dbefda939e49365621efc0c5ca8fc4b0206cf0e6b67313b79a9d677c3ca10 - Sigstore transparency entry: 852708886
- Sigstore integration time:
-
Permalink:
kleiven/kleiven-azure-storage@b8cf918b5e26537a20b81a0a35e33112fc6e4dfd -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/kleiven
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@b8cf918b5e26537a20b81a0a35e33112fc6e4dfd -
Trigger Event:
push
-
Statement type:
File details
Details for the file kleiven_azure_storage-0.0.4-py3-none-any.whl.
File metadata
- Download URL: kleiven_azure_storage-0.0.4-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5f8a781e87271e7876c7d738cd817cb90c232ab7a9fd1a46fe0adca8d456dd0
|
|
| MD5 |
e1cebeaa284f854a9d6a49860160e55a
|
|
| BLAKE2b-256 |
9720652baa57503e54bef40d157214f177455cb07c1e4521c32e4148ed4fca4f
|
Provenance
The following attestation bundles were made for kleiven_azure_storage-0.0.4-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on kleiven/kleiven-azure-storage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kleiven_azure_storage-0.0.4-py3-none-any.whl -
Subject digest:
e5f8a781e87271e7876c7d738cd817cb90c232ab7a9fd1a46fe0adca8d456dd0 - Sigstore transparency entry: 852708945
- Sigstore integration time:
-
Permalink:
kleiven/kleiven-azure-storage@b8cf918b5e26537a20b81a0a35e33112fc6e4dfd -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/kleiven
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@b8cf918b5e26537a20b81a0a35e33112fc6e4dfd -
Trigger Event:
push
-
Statement type: