Package: hop-client
Hop ClientDocs:https://hop-client.readthedocs.io/en/stable/hop-clientis a pub-sub client library for Multimessenger Astrophysics.InstallationYou can install hop either via pip, conda, or from source.To install with pip:pip install -U hop-clientTo install with conda:conda install -c conda-forge hop-clientTo install from source:tar -xzf hop-client-x.y.z.tar.gz
cd hop-client-x.y.z
python setup.py installQuickstartBy default, authentication is enabled, reading in configuration settings
fromconfig.toml. The path to this configuration can be found by runninghop auth locate. One can initialize this configuration with default
settings by runninghop auth setup. To disable authentication in the CLI
client, one can run--no-auth.Command Line InterfacePublish a message:hop publish kafka://hostname:port/gcn -f CIRCULAR example.gcn3Example messages are provided intests/dataincluding:A GCN circular (example.gcn3)A VOEvent (example_voevent.xml)Consume messages:hop subscribe kafka://hostname:port/gcn -s EARLIESTThis will read messages from the gcn topic from the earliest offset
and read messages until an end of stream (EOS) is received.Python APIPublish messages:Using the python API, we can publish various types of messages, including
structured messages such as GCN Circulars and VOEvents:fromhopimportstreamfromhop.modelsimportGCNCircular# read in a GCN circularwithopen("path/to/circular.gcn3","r")asf:circular=GCNCircular.load(f)withstream.open("kafka://hostname:port/topic","w")ass:s.write(circular)In addition, we can also publish unstructured messages as long as they are
JSON serializable:fromhopimportstreamwithstream.open("kafka://hostname:port/topic","w")ass:s.write({"my":"message"})By default, authentication is enabled for the Hop broker, reading in configuration
settings fromconfig.toml. In order to modify various authentication options, one
can configure aStreaminstance and pass in anAuthinstance with credentials:fromhopimportStreamfromhop.authimportAuthauth=Auth("my-username","my-password")stream=Stream(auth=auth)withstream.open("kafka://hostname:port/topic","w")ass:s.write({"my":"message"})To explicitly disable authentication one can setauthtoFalse.Consume messages:fromhopimportstreamwithstream.open("kafka://hostname:port/topic","r")ass:formessageins: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.
Thestart_atoption 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:fromhopimportStreamfromhop.ioimportStartPositionstream=Stream(start_at=StartPosition.EARLIEST)withstream.open("kafka://hostname:port/topic","r")ass:formessageins:print(message)DevelopmentA Makefile is provided to ease in testing, deployment and generating documentation.A list of commands can be listed withmake 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 packagingdocs: dependencies required for building documentationAssuming 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]ReleasesTo create a new release, first make a Github Issue for the specific release using therelease template. Complete the steps in thePre-releasesection; once that section is finished, complete theReleasesection. Ensure that the new version release string follows thesemverconventions, e.g.,v0.0.1.These steps will result in a new Github release, as well as a new package version uploaded toPyPIandconda-forgevia Github Actions.