Skip to main content

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.

storage


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.

eventclient

--

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:

  1. Data is uploaded
  2. Event containing the blob location is send
  3. Event is received
  4. Data is downloaded using the blob location contained in the event

dataclient

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:

  1. The function is triggered by a trigger object (e.g. a timer or a message being received)
  2. Possible dependency objects are initialized (potentially using information from the trigger). These are used to integrate with external systems (e.g. a database client).
  3. Using the trigger and dependencies as inputs, the function outputs and an output object (e.g. a message being sent).

function

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:

  1. Azure trigger binding is converted to trigger object
  2. 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)
  3. All logs and traces are sent to App Insights automatically.

function-wrap

--

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

warpzone_sdk-19.0.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

warpzone_sdk-19.0.1-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file warpzone_sdk-19.0.1.tar.gz.

File metadata

  • Download URL: warpzone_sdk-19.0.1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.10.20 Linux/6.17.0-1010-azure

File hashes

Hashes for warpzone_sdk-19.0.1.tar.gz
Algorithm Hash digest
SHA256 a29a8010bc77ba8e2995ca5c6aa1134d2c0619bdbd6c38bfc6bc0965e201b610
MD5 1bf91e92e77521c507644582b63a1ac0
BLAKE2b-256 046874f2353716e0bb40f5d9c0ee7eb29699b5b5cf92ba38859e79703bb8715f

See more details on using hashes here.

File details

Details for the file warpzone_sdk-19.0.1-py3-none-any.whl.

File metadata

  • Download URL: warpzone_sdk-19.0.1-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.10.20 Linux/6.17.0-1010-azure

File hashes

Hashes for warpzone_sdk-19.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55643b63dd27315b32d531d9a4a9d224085f6c76dc84e18ef9cf6151b07ebf8b
MD5 921012b7c27a644902d76b7f4ae65197
BLAKE2b-256 40f39c93b842d4d5051dd7c688c774e8326cf75d0741b6cc800efbc8eeca14e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page