The main objective of this package is to centralize logic used to interact with Azure Functions, Azure Service Bus and Azure Table Storage
Project description
WarpZone SDK
This package contains tools used in the WarpZone project. These tool include:
Client for Storage
Blob storage
WarpzoneBlobClient client is used for uploading to and downloading from Azure Storage Blob Service.
Client for Servicebus
Due to limitations on message sizes, we use different methods for sending events and data using Azure Service Bus.
Events
We use the Service Bus for transmitting event messages. By an event, we mean a JSON formatted message, containing information about an event occuring in one part of the system, which needs to trigger another part of the system (such as an Azure Function trigger).
WarpzoneEventClient client is used for sending and receiving events.
--
Data
We do not use the Service Bus for transmitting data directly. Instead, we use a claim-check pattern, were we store the data using Storage Blob, and transmit an event about the details of this stored data.
WarpzoneDataClient client is used for sending and receiving data in this way. The following diagram shows how the process works:
- Data is uploaded
- Event containing the blob location is send
- Event is received
- Data is downloaded using the blob location contained in the event
The transmitted event has the following format:
{
"container_name": "<container-name>",
"blob_name": "<blob-name>",
"timestamp": "<%Y-%m-%dT%H:%M:%S%z>"
}
The data will be stored with
<container-name>=<topic-name><blob-name>=<subject>/year=<%Y>/month=<%m>/day=<%d>/hour=<%H>/<message-id>.<extension>
Function Wrapper
For executing logic, we use a framework built on top of Azure Functions. The following diagram shows how the framework works:
- The function is triggered by a trigger object (e.g. a timer or a message being received)
- Possible dependency objects are initialized (potentially using information from the trigger). These are used to integrate with external systems (e.g. a database client).
- Using the trigger and dependencies as inputs, the function outputs and an output object (e.g. a message being sent).
The reason we have used our own framework instead of Azure Functions directly, is that we want to use our own objects as triggers, dependencies and outputs, instead of the built-in bindings. For example, as explained above, we have created our own abstraction of a message for transmitting data (warpzone.DataMessage); so we would like to use this, instead of the built-in binding azure.function.ServiceBusMessage.
Since it is not yet possible to define custom bindings in Python, we have defined our own wrapping logic, to handle the conversion between our own objects and the built-in bindings. The following diagram shows how the wrapping logic works:
- Azure trigger binding is converted to trigger object
- Either
- (a) Output object is converted to Azure output binding.
- (b) Use custom output logic, when no suitable output binding exists (e.g. we use the Azure Service Bus SDK instead of the Service Bus output binding, since this is recommended)
- All logs and traces are sent to App Insights automatically.
--
Examples
Azure Function with data messages as trigger and output:
# function.json
{
"scriptFile": "__init__.py",
"entryPoint": "main",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"connection": "...",
"topicName": "...",
"subscriptionName": "..."
}
]
}
import warpzone as wz
def do_nothing(data_msg: wz.DataMessage) -> wz.DataMessage:
return data_msg
main = wz.functionize(
f=do_nothing,
trigger=wz.triggers.DataMessageTrigger(binding_name="msg"),
output=wz.outputs.DataMessageOutput(wz.Topic.UNIFORM)
)
Azure Function with HTTP messages as trigger and output:
# function.json
{
"scriptFile": "__init__.py",
"entryPoint": "main",
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
# __init__.py
import warpzone as wz
import azure.functions as func
def return_ok(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse("OK")
main = wz.functionize(
f=return_ok,
trigger=wz.triggers.HttpTrigger(binding_name="req"),
output=wz.outputs.HttpOutput()
)
Azure Function using dependencies:
import warpzone as wz
def do_nothing(
data_msg: wz.DataMessage,
db: wz.WarpzoneDatabaseClient,
) -> wz.DataMessage:
return data_msg
main = wz.functionize(
f=do_nothing,
trigger=wz.triggers.DataMessageTrigger(binding_name="msg"),
output=wz.outputs.DataMessageOutput(wz.Topic.UNIFORM),
dependencies=[wz.dependencies.DeltaDatabaseDependency()],
)
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
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 warpzone_sdk-19.0.0.tar.gz.
File metadata
- Download URL: warpzone_sdk-19.0.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.10.20 Linux/6.17.0-1008-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58401e16e7f629a090730de88abbe2e091eced69005ffecf1ad717de4320a74a
|
|
| MD5 |
4b017bb9d90110d7005263e5a87f1f7b
|
|
| BLAKE2b-256 |
d67020a4ed721ad1cda8c61779e85983cfb8484717d1fe5ab73d5865579b0e92
|
File details
Details for the file warpzone_sdk-19.0.0-py3-none-any.whl.
File metadata
- Download URL: warpzone_sdk-19.0.0-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.10.20 Linux/6.17.0-1008-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5f46f3e7db94e8e181734158eee8fc2393af07c811d634ecfc6ec1f60aeb259
|
|
| MD5 |
af29e97bd44bc9e3df848d20d8ae17d8
|
|
| BLAKE2b-256 |
1da375325860a65eebb125c477d2832a5b68e033343da1b36d9cbe7f35a1da0a
|