Metadata-Version: 2.4
Name: hopeit.azure.blob-storage
Version: 0.1.0
Summary: Hopeit Engine Azure Blob Storage Toolkit
Author-email: Leo Smerling & Pablo Canto <contact@hopeit.com.ar>, Leo Smerling <contact@hopeit.com.ar>, Pablo Canto <contact@hopeit.com.ar>
License: Apache 2
Project-URL: Homepage, https://github.com/hopeit-git/hopeit.azure
Project-URL: CI: GitHub Actions, https://github.com/hopeit-git/hopeit.azure/actions?query=workflow
Project-URL: GitHub: issues, https://github.com/hopeit-git/hopeit.azure/issues
Project-URL: GitHub: repo, https://github.com/hopeit-git/hopeit.azure
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Framework :: AsyncIO
Description-Content-Type: text/markdown
Requires-Dist: azure-identity>=1.23.0
Requires-Dist: azure-storage-blob>=12.25.1
Requires-Dist: hopeit.engine>=0.27.0

# hopeit.azure.blob-storage plugin

This library is part of hopeit.engine:

> visit: https://github.com/hopeit-git/hopeit.engine

This library provides a `ObjectStorage` class to store and retrieve `@dataobjects` and files from Azure Blob Storage and compatible services as a plugin for the popular [`hopeit.engine`](https://github.com/hopeit-git/hopeit.engine) reactive microservices framework.

It supports the `prefix` setting, which is a prefix to be used for every element (object or file) stored in the Azure Blob Storage bucket. This prefix can be used to organize and categorize stored data within the bucket. Additionally, it supports the `partition_dateformat` setting, which is a date format string used to prefix file names for partitioning saved files into different subfolders based on the event timestamp (event_ts()). For example, using `%Y/%m/%d` will store each data object in a folder structure like year/month/day/, providing a way to efficiently organize and retrieve data based on date ranges. These settings can be used together to achieve more granular organization of data within the bucket.

### Installation

Python library that provides helpers to store and retrieve `@dataobjects` and files to Azure Blob Storage compatible services

```bash
pip install hopeit.azure.blob-storage
```

### Usage

```python
from hopeit.dataobjects import dataobject, dataclass
from hopeit.azure.blob_storage import ObjectStorage, ObjectStorageSettings, ConnectionConfig

# Set a connection configuration
conn_config = ConnectionConfig(
    connection_string="__AZURE_CONNECTION_STRING__",
    use_identity=False,
)

# Set settings for ObjectStorage
settings = ObjectStorageSettings(
    bucket="your-bucket-name",
    connection_config=conn_config
)

# Create an ObjectStorage instance
storage = await ObjectStorage.with_settings(settings).connect()

# hopeit.engine data object
@dataobject
@dataclass
class Something:
    key: str
    value: str

something = Something(key="my_key", value="some_value")

# Store a data object
await storage.store(key=something.key, value=something)

# Retrieve a data object
retrieved_object = await storage.get(key=something.key, datatype=Something)
print(retrieved_object)
```

## Example Usage

In the `apps/examples/azure-example/` directory, you can find a full example `hopeit.engine` app that demonstrates the usage of the `hopeit.azure.blob-storage` plugin within the `hopeit.engine` framework. This example showcases how to store and retrieve `@dataobjects` and files from Azure Blob Storage using the `ObjectStorage` class.
