Skip to main content

Hop Client

codecov

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

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

Internally, this library contains its own copy of bson BSON codec library, used under a BSD License, which it turn includes the ObjectId implementation from the PyMongo project, licensed under the Version 2.0 Apache License.

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:

conda install -c conda-forge hop-client

To install from source:

tar -xzf hop-client-x.y.z.tar.gz
cd hop-client-x.y.z
pip 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 hop client that installs the required test and documentation libraries:

  • dev: dependencies required for testing, linting and packaging
  • docs: dependencies required for building documentation

Assuming you've cloned the repository and are in the project's root directory, you can install hop-client alongside all the required development dependencies by running:

pip install .[dev,docs]

Releases

To create a new release, first make a Github Issue for the specific release using the release template. Complete the steps in the Pre-release section; once that section is finished, complete the Release section. Ensure that the new version release string follows the semver conventions, e.g., v0.0.1.

These steps will result in a new Github release, as well as a new package version uploaded to PyPI and conda-forge via Github Actions.

Release files for hop-client 0.12.1

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

Source distribution (sdist)

Source distribution for hop-client 0.12.1
File Size Uploaded
hop_client-0.12.1.tar.gz 150.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hop-client 0.12.1
File Interpreter ABI Platform
hop_client-0.12.1-py3-none-any.whl Python 3 none any Details

Total release size: 225.9 kB

Release files / hop_client-0.12.1.tar.gz

Download URL hop_client-0.12.1.tar.gz
Size 150.7 kB
Tags Source
SHA-256 checksum
How to use checksums
75c8d3c1d5c3bd38b66a938758c0017e32eb8b18b09b42b51a60e9ad3b0b8819
BLAKE2b-256 checksum
How to use checksums
cb970083ec8d382b341dfbac49f1506cb118adecea077c0c7a53cfff673abf12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / hop_client-0.12.1-py3-none-any.whl

Download URL hop_client-0.12.1-py3-none-any.whl
Size 75.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43c3bdb5de6e493ce464e2ec1d6715ab813226586b8f446469d858f8f1dbfaa2
BLAKE2b-256 checksum
How to use checksums
8a32872168ba7e9fb0f4d6e3ed032601e0b71f66c0f64e04b46aa1752c4d227f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.12.1 This release

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2

2 release files

0.1

2 release files

0.0.5

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