Skip to main content

A pub-sub client library for Multi-messenger Astrophysics

Project description

Hop Client

codecov

Docs: https://hop-client.readthedocs.io/en/stable/

hop-client is a pub-sub client library for Multimessenger Astrophysics.

Installation

You can install hop either via pip, conda, or from source.

To install with pip:

pip install -U hop-client

To install with conda, you must use the channel from the SCiMMA Anaconda organization:

conda install --channel scimma hop-client

To install from source:

tar -xzf hop-client-x.y.z.tar.gz
cd hop-client-x.y.z
python setup.py install

Quickstart

By default, authentication is enabled, reading in configuration settings from config.toml. The path to this configuration can be found by running hop auth locate. One can initialize this configuration with default settings by running hop auth setup. To disable authentication in the CLI client, one can run --no-auth.

Command Line Interface

Publish a message:

hop publish kafka://hostname:port/gcn -f CIRCULAR example.gcn3

Example messages are provided in tests/data including:

  • A GCN circular (example.gcn3)
  • A VOEvent (example_voevent.xml)

Consume messages:

hop subscribe kafka://hostname:port/gcn -s EARLIEST

This will read messages from the gcn topic from the earliest offset and read messages until an end of stream (EOS) is received.

Python API

Publish messages:

Using the python API, we can publish various types of messages, including structured messages such as GCN Circulars and VOEvents:

from hop import stream
from hop.models import GCNCircular

# read in a GCN circular
with open("path/to/circular.gcn3", "r") as f:
    circular = GCNCircular.load(f)

with stream.open("kafka://hostname:port/topic", "w") as s:
    s.write(circular)

In addition, we can also publish unstructured messages as long as they are JSON serializable:

from hop import stream

with stream.open("kafka://hostname:port/topic", "w") as s:
    s.write({"my": "message"})

By default, authentication is enabled for the Hop broker, reading in configuration settings from config.toml. In order to modify various authentication options, one can configure a Stream instance and pass in an Auth instance with credentials:

from hop import Stream
from hop.auth import Auth

auth = Auth("my-username", "my-password")
stream = Stream(auth=auth)

with stream.open("kafka://hostname:port/topic", "w") as s:
    s.write({"my": "message"})

To explicitly disable authentication one can set auth to False.

Consume messages:

from hop import stream

with stream.open("kafka://hostname:port/topic", "r") as s:
    for message in s:
         print(message)

This will listen to the Hop broker, listening to new messages and printing them to stdout as they arrive until there are no more messages in the stream. By default, this will only process new messages since the connection was opened. The start_at option lets you control where in the stream you can start listening from. For example, if you'd like to listen to all messages stored in a topic, you can do:

from hop import Stream
from hop.io import StartPosition

stream = Stream(start_at=StartPosition.EARLIEST)

with stream.open("kafka://hostname:port/topic", "r") as s:
    for message in s:
         print(message)

Development

A Makefile is provided to ease in testing, deployment and generating documentation.

A list of commands can be listed with make help.

In addition, two extras are provided when installing the scimma client that installs the required test and documentation libraries:

pip install -U hop-client[dev,docs]

To mark a new version, use Github tags to mark your commit with a semver version:

git tag v0.0.1

To release a new version and upload to package repositories, push your tag after pushing your commit:

git push --tags

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hop-client-0.3.0.tar.gz (48.6 kB view details)

Uploaded Source

Built Distribution

hop_client-0.3.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file hop-client-0.3.0.tar.gz.

File metadata

  • Download URL: hop-client-0.3.0.tar.gz
  • Upload date:
  • Size: 48.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.13

File hashes

Hashes for hop-client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f59123c21d51dbf18bd5537f8945bf93e9851a52e86634431ba716629d2ee607
MD5 a5647dc90e230b4661fcf6146441f6dc
BLAKE2b-256 cd2f459360d0e45d72f1eefe0767050b388a1b0ad6e4859bdff41950c212e565

See more details on using hashes here.

File details

Details for the file hop_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hop_client-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.13

File hashes

Hashes for hop_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff151109e7c131ee20a081419db979299ab4685ec851a6259a04adf1f88bfbbe
MD5 763166547b298d8e00efc14bb4f6204f
BLAKE2b-256 18809efa1b5a1734c3285df81a1c736c36e46a28f7529469a5d85a5856938400

See more details on using hashes here.

Supported by

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