Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Notifier

Notifier is an application that publishes notifications to a communication system such as Matrix or, in the future, to electronic lab notebooks.

The Notifier does not produce notifications itself, but reads messages that have been published by other components of a data processing pipeline such as connectors and workers to a queue. At the moment, the actions stream of a given Asapo data source is used to store the queue of these messages. We recommend the name misc for this Asapo data source.

graph LR
  dps@{ shape: procs, label: "Data Processing Units"}
  actions_queue(["Queue of actions<br/>(Asapo stream)"])
  notifier[Notifier]
  comm_system["Communication system<br/>(e.g. Matrix)"]
  users@{ shape: procs, label: "Users"}

  actions_queue ~~~ notifier
  dps -- publish actions ---> actions_queue
  notifier -- read ---> actions_queue
  notifier -- publish notifications ---> comm_system
  comm_system -- notifies ---> users

The Notifier expects messages that describe notifications to be stored as Asapo messages metadata of the following format:

{
    "version": "0.1.0",
    "from": "<component_description>",
    "action": {"type": "alert", "message": "<message>"},
}

Getting started

To run the Notifier, you will need a device_id and access_token that correspond to a Matrix account. To create a device_id and access_token for a given account, execute the following commands:

MATRIX_USER_ID=""   # Set the corresponding user ID
MATRIX_PASSWORD=""  # Set the corresponding password

AUTH_RESPONSE="$(curl -X POST "https://matrix.org/_matrix/client/v3/login" \
     -H "Content-Type: application/json" \
     -d '{
       "type": "m.login.password",
       "identifier": {
         "type": "m.id.user",
         "user": "'$MATRIX_USER_ID'"
       },
       "password": "'$MATRIX_PASSWORD'",
       "initial_device_display_name": "bot session"
     }')"
# Result:
# {"access_token":"<token>","device_id":"<device_id>","user_id":"<MATRIX_USER_ID>"}
matrix_device_id="$(jq -r .device_id <<<"$AUTH_RESPONSE")"
matrix_access_token="$(jq -r .access_token <<<"$AUTH_RESPONSE")"
# echo "matrix_device_id='$matrix_device_id' && matrix_access_token='$matrix_access_token'"

To run the Notifier, you also need to install its dependencies:

# Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip

# Install dependencies
python3 -m pip install -e .[asapo]

You can now start the Notifier with the following commands:

# The values provided below assume using the Asapo standalone Docker container.
# Edit these values to make the notifier use a different Asapo, beamline, or beamtime.
asapo_endpoint="localhost:8400"
asapo_beamline="test"
asapo_beamtime="asapo_test"
asapo_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e\
yJleHAiOjk1NzE3MTAyMTYsImp0aSI6Ind0ZmlzdGhpcyIsInN\
1YiI6ImJ0X2FzYXBvX3Rlc3QiLCJFeHRyYUNsYWltcyI6eyJBY\
2Nlc3NUeXBlcyI6WyJ3cml0ZSIsIndyaXRlcmF3IiwicmVhZCJ\
dfX0.cz6R_kVf4yh7IJD6bJjDdgTaxPN3txudZx9DE6WaTtk"

# Start the Notifier app:
python3 -m notifier.app \
  --asapo.endpoint "$asapo_endpoint" \
  --beamline "$asapo_beamline" \
  --beamtime "$asapo_beamtime" \
  --asapo.token "$asapo_token" \
  --matrix.device_id "$matrix_device_id" \
  --matrix.access_token "$matrix_access_token" \
  --log_level "debug"

To test that the notifier works correctly, you can publish some notification messages to Asapo:

# The values provided below assume using the Asapo standalone Docker container.
# Edit these values to make the notifier use a different Asapo, beamline, or beamtime.
asapo_endpoint="localhost:8400"
asapo_beamline="test"
asapo_beamtime="asapo_test"
asapo_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e\
yJleHAiOjk1NzE3MTAyMTYsImp0aSI6Ind0ZmlzdGhpcyIsInN\
1YiI6ImJ0X2FzYXBvX3Rlc3QiLCJFeHRyYUNsYWltcyI6eyJBY\
2Nlc3NUeXBlcyI6WyJ3cml0ZSIsIndyaXRlcmF3IiwicmVhZCJ\
dfX0.cz6R_kVf4yh7IJD6bJjDdgTaxPN3txudZx9DE6WaTtk"

# Publish messages to Asapo:
python3 -m tests.notifier.publish_to_asapo \
  --asapo.endpoint "$asapo_endpoint" \
  --beamline "$asapo_beamline" \
  --beamtime "$asapo_beamtime" \
  --asapo.token "$asapo_token" \
  --messages "tests/notifier/messages.json" \
  --log_level "debug"

As a reminder, if you want to use an Asapo standalone Docker container, execute the following command:

docker run --rm --name asapo --network host \
  gitlab.desy.de:5555/asapo/asapo/asapo-standalone:26.02.0.dev01

Contributing

If you want to contribute, please read CONTRIBUTING.md first.

In addition, you can find more information on the organization of the code in the document doc/architecture.md.

Metadata

Release files for asapo-notifier 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asapo-notifier 0.1.0a2
File Size Uploaded Provenance
asapo_notifier-0.1.0a2.tar.gz 19.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for asapo-notifier 0.1.0a2
File Interpreter ABI Platform
asapo_notifier-0.1.0a2-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / asapo_notifier-0.1.0a2.tar.gz

Download URL asapo_notifier-0.1.0a2.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ddd8842089cf041dee53d5e4ca0f0e883ad4e3578eb66b5614c15dc9afb39948
BLAKE2b-256 checksum
How to use checksums
100a78015b8722721bffb5500e115e0ccaf517eaad201d24bad569d51d382eb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.9

Release files / asapo_notifier-0.1.0a2-py3-none-any.whl

Download URL asapo_notifier-0.1.0a2-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcaa16247da7fcc66c9aad5810202490181b676af35e179246819696c2dadf0d
BLAKE2b-256 checksum
How to use checksums
164c112418346ec3bd631092f36b1ed1a16fffda0bf63c62a167a274e3f3ea5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.9

Security for asapo-notifier 0.1.0a2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page