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-18.0.1.tar.gz (30.7 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-18.0.1-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: warpzone_sdk-18.0.1.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.14.0-1017-azure

File hashes

Hashes for warpzone_sdk-18.0.1.tar.gz
Algorithm Hash digest
SHA256 c5c0747587dd5996ba20414cc947a32c2449ccf5b8be593c467c5dfc6941ef2a
MD5 97e1b6ecef0f8529a491bf3e0955fc43
BLAKE2b-256 49ffd052a83a37ce3538b49d3862f9269fd1dc7e28181ea89998f0976ccf9a76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: warpzone_sdk-18.0.1-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.20 Linux/6.14.0-1017-azure

File hashes

Hashes for warpzone_sdk-18.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5803d7f7223f9ba67fffcaec058db97594e1de513cd5e06f11071286e0457288
MD5 7294ac082ac0e0891d33dd600d012350
BLAKE2b-256 d413b971107acdcd0c6ca2573c11bdf013f65fb80822f811ef1927989087c2df

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