Listening with nebra
Install nebra
(Python 3.11 or newer):
pip install nebra
This prints every new alert as it is posted, with the event's position:
import nebra
ASTRO_COLIBRI = "did:plc:v7yqjnko6psoy25novsrlrh6"
def on_alert(message):
# Only new records from the Astro-COLIBRI account. Anyone can write
# records under these collection names, and the stream also carries
# notices that are not records.
if message.get("did") != ASTRO_COLIBRI or message.get("operation") != "create":
return
record = message["record"]
event = record["data"] # nebra has already turned the floats back into numbers
print(
record["createdAt"],
record["alertType"],
record["astroColibriID"],
event.get("source_name"),
event.get("ra"),
event.get("dec"),
)
nebra.stream(
collections=["science.astro-colibri.alert.ac"],
dids=[ASTRO_COLIBRI],
message_handler=on_alert,
)
record["data"] is the full alert, with the same fields as the
astrocolibri.important.JSON Kafka topic and the REST API, so
code written for those works on it unchanged. For the VOEvent version,
subscribe to science.astro-colibri.alert.vo2, or to both with
science.astro-colibri.alert.*; message["collection"]
then tells them apart and message["rkey"] pairs them.
nebra.stream starts at the live edge. To catch up after a
break, pass cursor= a Unix time in microseconds: the public
stream replays from that moment, as far back as it keeps recent events (a
limited window). For anything older, read the account directly, see
Past alerts.
From the command line, without writing code (with
uv installed,
nothing needs to be installed at all), every message is printed as it
arrives:
uvx nebra stream --collections=science.astro-colibri.alert.ac --handles=astro-colibri.science