Skip to main content

The WIS2 Downloader

The backend tool for subscribing to the latest data on the WIS2 network

License Badge Super-Linter Unit-Tests

The WIS2 Downloader is a Flask-based Python application that allows you to connect to a WIS2 Global Broker, manage subscriptions to topic hierarchies, and configure their associated download directories.

Features

  • Dynamic Subscription Management: Quickly add or remove subscriptions ad hoc without needing to restart the service or change configuration files.
  • Monitor Download Statistics: Access the Prometheus metrics through the /metrics endpoint, ideal for Grafana visualization.
  • Multi-Threading Support: Configure the number of download workers for more efficient data downloading.

Getting Started

1. Installation

python -m pip install wis2downloader

2. Configuration

Create a file config.json in your local directory that conforms with the following schema:

schema:
  type: object
  properties:
    base_url:
      type: string
      description:
        Base URL for the wis2downloader service.
      example: http://localhost:5050
    broker_hostname:
      type: string
      description: The hostname of the global broker to subscribe to.
      example: globalbroker.meteo.fr
    broker_password:
      type: string
      description: The password to use when connecting to the specified global broker.
      example: everyone
    broker_port:
      type: number
      description: The port the global broker is using for the specified protocol.
      example: 443
    broker_protocol:
      type: string
      description: The protocol (websockets or tcp) to use when connecting to the global broker.
      example: websockets
    broker_username:
      type: string
      description: The username to use when connecting to the global broker.
      example: everyone
    download_workers:
      type: number
      description: The number of download worker threads to spawn.
      example: 1
    download_dir:
      type: string
      description: The path to download data to on the server/computer running the wis2downloader.
      example: ./downloads
    flask_host:
      type: string
      description: Network interface on which flask should listen when run in dev mode.
      example: 0.0.0.0
    flask_port:
      type: number
      description: The port on which flask should listen when run in dev mode.
      example: 5050
    log_level:
      type: string
      description: Log level to use
      example: DEBUG
    log_path:
      type: string
      description: Path to write log files to.
      example: ./logs
    min_free_space:
      type: number
      description:
        Minimum free space (GB) to leave on download volume / disk after download.
        Files exceeding limit will not be saved.
      example: 10
    save_logs:
      type: boolean
      description: Write log files to disk (true) or stdout (false)
      example: false
    mqtt_session_info:
      type: string
      description:
        File to save session information (active subscriptions and MQTT client id) to.
        Used to persist subscriptions on restart.
      example: mqtt_session.json
    validate_topics:
      type: boolean
      description: Whether to validate the specified topic against the published WIS2 topic hierarchy.
      example: true

An example is given below:

{
    "base_url": "http://localhost:5050",
    "broker_hostname": "globalbroker.meteo.fr",
    "broker_password": "everyone",
    "broker_port": 443,
    "broker_protocol": "websockets",
    "broker_username": "everyone",
    "download_workers": 1,
    "download_dir": "downloads",
    "flask_host": "0.0.0.0",
    "flask_port": 5050,
    "log_level": "DEBUG",
    "log_path": "logs",
    "min_free_space": 10,
    "mqtt_session_info" : "mqtt_session.json",
    "save_logs": false,
    "validate_topics": true
}

3. Running

  1. Set an environment variable specifying the path to the config.json file.

Linux (bash)

export WIS2DOWNLOADER_CONFIG=<path_to_your_config_file>

Windows (Command Prompt)

set WIS2DOWNLOADER_CONFIG=<path_to_your_config_file>

Windows (PowersShell)

$env:WIS2DOWNLOADER_CONFIG = <path_to_your_config_file>
  1. Start the downloader

Dev mode (Windows and Linux)

wis2downloader

Using gunicorn (Linux only)

gunicorn --bind 0.0.0.0:5050 -w 1 wis2downloader.app:app

Note: Only one worker is supported due to the downloader spawning additional threads and persistence of MQTT connections.

The Flask application should now be running. If you need to stop the application, you can do so in the terminal with Ctrl+C.

Maintaining and Monitoring Subscriptions

The API defintion of the downloader can be found at the /swagger endpoint, when run locally see [http://localhost:5050/swagger]. this includes the ability to try out the different endpoints.

Adding subscriptions

Subscriptions can be added via a POST request to the /subscriptions endpoint. The request body should be JSON-encoded and adhere to the following schema:

schema:
  type: object
  properties:
    topic:
      type: string
      description: The WIS2 topic to subscribe to
      example: cache/a/wis2/+/data/core/weather/surface-based-observations/#
    target:
      type: string
      description: Sub directory to save data to
      example: surface-obs
  required:
    - topic

In this example all notifications published to the surface-based-observations topic from any WIS2 centre will be subscribed to, with the downloaded data written to the surface-obs subdirectory of the download_dir.

Notes:

  1. If the target is not specified it will default to the topic the data are published on.
  2. The + wildcard is used to specify any match at a single level, matching as WIS2 centre in the above example.
  3. The # wildcard matches any topic at or below the level it occurs. In the above example any topic published below cache/a/wis2/+/data/core/weather/surface-based-observations will be matched.

Example CURL command to add subscription

curl -X 'POST' \
  'http://127.0.0.1:5050/subscriptions' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
      "topic": "cache/a/wis2/+/data/core/weather/surface-based-observations/#",
      "target": "surface-obs"
  }'

Deleting subscriptions

Subscriptions are deleted via a DELETE request to the /subscriptions/{topic} endpoint where {topic} is the topic to unsubscribe from.

Example CURL command to delete subscription

curl -X DELETE http://localhost:5050/subscriptions/cache/a/wis2/%2B/data/core/weather/%23

This cancels the cache/a/wis2/+/data/core/weather/# subscription. Note the need to URL encode the + (%2B) and # (%23) symbols.

Listing subscriptions

Current subscriptions can listed via a GET request to /subscriptions endpoint.

Example CURL command to list subscriptions

curl http://localhost:5050/subscriptions

The list of active subscriptions should be returned as a JSON object.

Viewing download metrics

Prometheus metrics for the downloader are found via a GET request to the /metrics endpoint.

Example CURL command to view download metrics

curl http://localhost:5050/metrics

Bugs and Issues

All bugs, enhancements and issues are managed on GitHub.

Contact

Metadata

Release files for wis2downloader 0.3.2

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

Source distribution (sdist)

Source distribution for wis2downloader 0.3.2
File Size Uploaded
wis2downloader-0.3.2.tar.gz 28.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wis2downloader 0.3.2
File Interpreter ABI Platform
wis2downloader-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 57.3 kB

Release files / wis2downloader-0.3.2.tar.gz

Download URL wis2downloader-0.3.2.tar.gz
Size 28.3 kB
Tags Source
SHA-256 checksum
How to use checksums
482f58f17a95ef9412bf9331ec57c7999f7f4ca777e7e317d73e1c1141644812
BLAKE2b-256 checksum
How to use checksums
8d45c9cdb85fa6ddb83fedf53f37f882db7987fc02e5b7f447dc4ac8d184060d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / wis2downloader-0.3.2-py3-none-any.whl

Download URL wis2downloader-0.3.2-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f222e662e69815429799c7dd148d541d5ff9aed315816ebfa50c5a6d02e6d60
BLAKE2b-256 checksum
How to use checksums
4d8627226eb55b2d122a642df8d234a19c026ede21d2ab4565427c3c9654f657
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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