babamul
Python client for consuming ZTF/LSST astronomical transient alerts from Babamul Kafka streams.
Installation
uv add babamul
or
pip install babamul
Quick Start
Set your credentials via environment variables or a local .env, then start
consuming alerts:
export BABAMUL_KAFKA_USERNAME="your_username"
export BABAMUL_KAFKA_PASSWORD="your_password"
export BABAMUL_API_TOKEN="your_api_token"
from babamul import AlertConsumer
# Iterate over alerts (credentials loaded from env vars or .env)
with AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"]) as consumer:
for alert in consumer:
print(
f"{alert.objectId}: RA={alert.candidate.ra:.4f}, "
f"Dec={alert.candidate.dec:.4f}"
)
break
Configuration
Avoid hardcoding credentials in code. Prefer environment variables or a local
.env file that is not committed to version control. Passing
username/password in code should be limited to one-off REPL usage.
Environmental Variables
export BABAMUL_KAFKA_USERNAME="your_username"
export BABAMUL_KAFKA_PASSWORD="your_password"
export BABAMUL_API_TOKEN="your_api_token"
export BABAMUL_KAFKA_SERVER="kaboom.caltech.edu:9093" # Optional
or define these in a .env file kept out of version control and read
with the python-dotenv package.
Constructor Options
Use the constructor for runtime options like offsets and timeouts.
from babamul import AlertConsumer
with AlertConsumer(
topics=["babamul.ztf.lsst-match.hosted"], # Topic(s) to subscribe to
offset="earliest", # "latest" or "earliest"
timeout=30.0, # Seconds to wait for messages (None = forever)
group_id="my-consumer-group", # Optional, auto-generated if not set
) as consumer:
# Consume alerts here
for alert in consumer:
print(
f"{alert.objectId}: RA={alert.candidate.ra:.4f}, "
f"Dec={alert.candidate.dec:.4f}"
)
Working with Alerts
Alert Properties
from babamul import AlertConsumer
with AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"]) as consumer:
for alert in consumer:
# Basic info
print(f" Object ID: {alert.objectId}")
print(f" Candidate ID: {alert.candid}")
print(f" Position: RA={alert.candidate.ra:.6f}, Dec={alert.candidate.dec:.6f}")
print(f" Time: {alert.candidate.datetime.isoformat()} (JD={alert.candidate.jd:.5f})")
print(f" Magnitude: {alert.candidate.magpsf:.2f}±{alert.candidate.sigmapsf:.2f}")
Photometry / Light Curves
from babamul import AlertConsumer
with AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"]) as consumer:
for alert in consumer:
for phot in alert.get_photometry(): # Full light curve
if phot.magpsf is not None:
print(f" JD {phot.jd:.5f}: {phot.magpsf:.2f} mag ({phot.band})")
else:
print(f" JD {phot.jd:.5f}: non-detection, limit={phot.diffmaglim:.2f} ({phot.band})")
Cutouts
from babamul import AlertConsumer
with AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"]) as consumer:
for alert in consumer:
alert.show_cutouts() # Displays science, template, and difference images
Context Manager
For proper resource cleanup:
from babamul import AlertConsumer
with AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"]) as consumer:
for i, alert in enumerate(consumer):
# process alerts
if i >= 100:
break
# Consumer is automatically closed
Error Handling
from babamul import AlertConsumer, AuthenticationError, BabamulConnectionError
try:
with AlertConsumer(
topics=["babamul.ztf.lsst-match.hosted"],
) as consumer:
for alert in consumer:
# process alerts
pass
except AuthenticationError:
print("Invalid credentials")
except BabamulConnectionError:
print("Cannot connect to Kafka server")
Available Topics
Babamul provides several topic categories based on survey and classification:
LSST Topics
LSST-only (no ZTF counterpart):
| Topic | Description |
|---|---|
babamul.lsst.no-ztf-match.stellar |
Alerts classified as stellar |
babamul.lsst.no-ztf-match.hosted |
Alerts with a host galaxy |
babamul.lsst.no-ztf-match.hostless |
Alerts without a host galaxy |
babamul.lsst.no-ztf-match.unknown |
Unclassified alerts |
LSST with ZTF match:
| Topic | Description |
|---|---|
babamul.lsst.ztf-match.stellar |
Alerts classified as stellar |
babamul.lsst.ztf-match.hosted |
Alerts with a host galaxy |
babamul.lsst.ztf-match.hostless |
Alerts without a host galaxy |
babamul.lsst.ztf-match.unknown |
Unclassified alerts |
ZTF Topics
ZTF-only (no LSST counterpart):
| Topic | Description |
|---|---|
babamul.ztf.no-lsst-match.stellar |
Alerts classified as stellar |
babamul.ztf.no-lsst-match.hosted |
Alerts with a host galaxy |
babamul.ztf.no-lsst-match.hostless |
Alerts without a host galaxy |
babamul.ztf.no-lsst-match.unknown |
Unclassified alerts |
ZTF with LSST match:
| Topic | Description |
|---|---|
babamul.ztf.lsst-match.stellar |
Alerts classified as stellar |
babamul.ztf.lsst-match.hosted |
Alerts with a host galaxy |
babamul.ztf.lsst-match.hostless |
Alerts without a host galaxy |
babamul.ztf.lsst-match.unknown |
Unclassified alerts |
Wildcard Subscriptions
You can use wildcards to subscribe to multiple topics:
from babamul import AlertConsumer
# All LSST topics
with AlertConsumer(topics=["babamul.lsst.*"], ...) as consumer:
pass
# All ZTF topics with LSST matches
with AlertConsumer(topics=["babamul.ztf.lsst-match.*"], ...) as consumer:
pass
# All hosted alerts from both surveys
with AlertConsumer(topics=["babamul.*.*.hosted"], ...) as consumer:
pass
Privacy
This package contains no analytics or telemetry SDK, and it collects and transmits nothing about you or your machine.
At most once a day, on import, it asks PyPI for the list of babamul releases so
it can warn you when a newer version is out. Set BABAMUL_NO_VERSION_CHECK=1
to turn this off.
The one piece of client information the BOOM servers see is a standard
software-description string, sent as the User-Agent header on API requests
and as the Kafka client.id when consuming alerts. It describes the software
rather than you:
babamul-python/0.2.0 (Python/3.12.1; Linux)
That is the package version, the Python version, and the OS name — no hostname, username, machine identifier, architecture, OS version, locale, or timezone. It lets the BOOM team see which package versions are still in use, which is what tells them when an old release can be retired.
Separately, and as you would expect of any hosted service, the BOOM servers record their own API requests and Kafka consumer-group offsets. That happens server-side regardless of which client you use.
Development Setup
For development and testing, use a .env file to manage your credentials:
# 1. Copy the example file
cp tests/.env.example tests/.env
# 2. Edit tests/.env with your credentials
# Get credentials at: https://babamul.caltech.edu/signup
nano tests/.env
# 3. Load automatically when running tests
# The .env file is gitignored and will not be committed
Your tests/.env file should look like:
BABAMUL_KAFKA_USERNAME=your_username
BABAMUL_KAFKA_PASSWORD=your_password
BABAMUL_API_TOKEN=your_api_token
Most examples and tests will automatically load credentials from .env using python-dotenv.
Acknowledgments
The Babamul alerts broker and BOOM software infrastructure (du Laz et al. 2026) is co-developed by the California Institute of Technology and the University of Minnesota. This work acknowledges support from the National Science Foundation through AST Award No. 2432476 (PI Kasliwal; co-PI Coughlin) and leverages experience from the Zwicky Transient Facility (co-PIs Graham and Kasliwal).
Metadata
Release files for babamul 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| babamul-0.2.0.tar.gz | 335.6 kB | With provenance | Details for babamul-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| babamul-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for babamul-0.2.0-py3-none-any.whl |
Total release size: 373.2 kB
Release files / babamul-0.2.0.tar.gz
| Download URL | babamul-0.2.0.tar.gz |
|---|---|
| Size | 335.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c13720ff6e3e6adf0e95abdc92250e4c26240ec7f9a969a0f37d5405267fd84b
|
|
BLAKE2b-256 checksum How to use checksums |
88afde94307437a8d8bb2262e809e81fa1547246428f40a4c62434b43a1e12ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logRelease files / babamul-0.2.0-py3-none-any.whl
| Download URL | babamul-0.2.0-py3-none-any.whl |
|---|---|
| Size | 37.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ca5740c67c56f3e6c2db5770c600ee22f93526a47a8b51574c22a0d7637dc15
|
|
BLAKE2b-256 checksum How to use checksums |
319cfecedc3651d6f5a53329a3939d7f23fe6c174906e3ce2d0bead260035076
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logSecurity for babamul 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for babamul-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.