Skip to main content

Python interface for ka9q-radio control and monitoring

Project description

ka9q-python

PyPI version License: MIT

General-purpose Python library for controlling ka9q-radio

Control radiod channels for any application: AM/FM/SSB radio, WSPR monitoring, SuperDARN radar, CODAR oceanography, HF fax, satellite downlinks, and more.

Note: Package name is ka9q-python out of respect for KA9Q (Phil Karn's callsign). Import as import ka9q.

Table of Contents

Features

Zero assumptions - Works for any SDR application
Complete API - All 85+ radiod parameters exposed
Channel control - Create, configure, discover channels
RTP recording - Generic recorder with timing support and state machine
Precise timing - GPS_TIME/RTP_TIMESNAP for accurate timestamps
Multi-homed support - Works on systems with multiple network interfaces
Pure Python - No compiled dependencies
Well tested - Comprehensive test coverage
Documented - Comprehensive examples and API reference included

Installation

pip install ka9q-python

Or install from source:

git clone https://github.com/mijahauan/ka9q-python.git
cd ka9q-python
pip install -e .

Quick Start

Listen to AM Broadcast

from ka9q import RadiodControl

# Connect to radiod
control = RadiodControl("radiod.local")

# Create AM channel on 10 MHz WWV
control.create_channel(
    ssrc=10000000,
    frequency_hz=10.0e6,
    preset="am",
    sample_rate=12000
)

# RTP stream now available with SSRC 10000000

### Request Specific Output Encoding

```python
from ka9q import RadiodControl, Encoding

control = RadiodControl("radiod.local")

# Create a channel with 32-bit float output (highest quality)
control.ensure_channel(
    frequency_hz=14.074e6,
    preset="usb",
    sample_rate=12000,
    encoding=Encoding.F32
)

### Monitor WSPR Bands

```python
from ka9q import RadiodControl

control = RadiodControl("radiod.local")

wspr_bands = [
    (1.8366e6, "160m"),
    (3.5686e6, "80m"),
    (7.0386e6, "40m"),
    (10.1387e6, "30m"),
    (14.0956e6, "20m"),
]

for freq, band in wspr_bands:
    control.create_channel(
        ssrc=int(freq),
        frequency_hz=freq,
        preset="usb",
        sample_rate=12000
    )
    print(f"{band} WSPR channel created")

Discover Existing Channels

from ka9q import discover_channels

channels = discover_channels("radiod.local")
for ssrc, info in channels.items():
    print(f"{ssrc}: {info.frequency/1e6:.3f} MHz, {info.preset}, {info.sample_rate} Hz")

Record RTP Stream with Precise Timing

from ka9q import discover_channels, RTPRecorder
import time

# Get channel with timing info
channels = discover_channels("radiod.local")
channel = channels[14074000]

# Define packet handler
def handle_packet(header, payload, wallclock):
    print(f"Packet at {wallclock}: {len(payload)} bytes")

# Create and start recorder
recorder = RTPRecorder(channel=channel, on_packet=handle_packet)
recorder.start()
recorder.start_recording()
time.sleep(60)  # Record for 60 seconds
recorder.stop_recording()
recorder.stop()

Multi-Homed Systems

For systems with multiple network interfaces, specify which interface to use:

from ka9q import RadiodControl, discover_channels

# Specify your interface IP address
my_interface = "192.168.1.100"

# Create control with specific interface
control = RadiodControl("radiod.local", interface=my_interface)

# Discovery on specific interface
channels = discover_channels("radiod.local", interface=my_interface)

Automatic Channel Recovery

ensure your channels survive radiod restarts:

from ka9q import RadiodControl, ChannelMonitor

control = RadiodControl("radiod.local")
monitor = ChannelMonitor(control)
monitor.start()

# This channel will be automatically re-created if it disappears
monitor.monitor_channel(
    frequency_hz=14.074e6,
    preset="usb",
    sample_rate=12000
)

Documentation

For detailed information, please refer to the documentation in the docs/ directory:

Examples

See the examples/ directory for complete applications:

  • High-Level API: ensure_channel() handles the complexity of checking existing channels, creating new ones only when necessary, and verifying configurations.
  • Destination-Aware Channels: Support for unique per-application multicast destinations and deterministic IP generation.
  • Stream Sharing: Deterministic SSRC allocation allows multiple independent applications to share radiod streams efficiently.
  • discover_example.py - Channel discovery methods (native Python and control utility)
  • tune.py - Interactive channel tuning utility (Python implementation of ka9q-radio's tune)
  • tune_example.py - Programmatic examples of using the tune() method
  • rtp_recorder_example.py - Complete RTP recorder with timing and state machine
  • test_timing_fields.py - Verify GPS_TIME/RTP_TIMESNAP timing fields
  • simple_am_radio.py - Minimal AM broadcast listener
  • superdarn_recorder.py - Ionospheric radar monitoring
  • codar_oceanography.py - Ocean current radar
  • hf_band_scanner.py - Dynamic frequency scanner
  • wspr_monitor.py - Weak signal propagation reporter

Use Cases

AM/FM/SSB Radio

  • Broadcast monitoring
  • Ham radio operation
  • Shortwave listening

Scientific Research

  • WSPR propagation studies
  • SuperDARN ionospheric radar
  • CODAR ocean current mapping
  • Meteor scatter
  • EME (moonbounce)

Digital Modes

  • FT8/FT4 monitoring
  • RTTY/PSK decoding
  • DRM digital radio
  • HF fax reception

Satellite Operations

  • Downlink reception
  • Doppler tracking
  • Multi-frequency monitoring

Custom Applications

No assumptions! Use for anything SDR-related.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

ka9q_python-3.2.7.tar.gz (116.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ka9q_python-3.2.7-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file ka9q_python-3.2.7.tar.gz.

File metadata

  • Download URL: ka9q_python-3.2.7.tar.gz
  • Upload date:
  • Size: 116.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ka9q_python-3.2.7.tar.gz
Algorithm Hash digest
SHA256 1d59e2f57fe179b25f95019c68cac370aa3d5fad49207e3dcf9021d911420608
MD5 1e9d2a7d5411cd8aaa810f65a7d941f4
BLAKE2b-256 b27a577af56e890cbda537623a7b1531fe7cebd89b33fbb8c37c428601424119

See more details on using hashes here.

File details

Details for the file ka9q_python-3.2.7-py3-none-any.whl.

File metadata

  • Download URL: ka9q_python-3.2.7-py3-none-any.whl
  • Upload date:
  • Size: 55.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ka9q_python-3.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8b465c76ba5280197a6163968f9212756357a7a331e26d562a033778e924deb5
MD5 510c4bca1ec861c5bc471ecd20926976
BLAKE2b-256 0c82ea85d79571d13fd8ba5178750fd8cb1b37148fc54b1314332eb1aef335cc

See more details on using hashes here.

Supported by

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