Skip to main content

Python SDK for the Terra Listens bioacoustic monitoring platform

Project description

Terra SDK

Python SDK for the Terra Listens bioacoustic monitoring platform.

Wraps the Terra Listens backend API to provide programmatic access to bird detections, station data, weather, yard lists, and more.

Installation

python -m venv .venv && source .venv/bin/activate
pip install -e .

Quick Start

from terra_sdk import TerraClient

# From .env file (USERNAME, PASSWORD)
client = TerraClient.from_env()

# Or explicit credentials
client = TerraClient("you@example.com", "your-password")

# Or reuse an existing token
client = TerraClient(token="your-token")

Usage

from terra_sdk import TerraClient

client = TerraClient.from_env()

# List your stations
devices = client.get_devices()
station = devices[0]
print(f"{station.alias} - {station.id}")

# Get latest bird detections
birds = client.get_latest_birds(count=10, min_confidence=0.5)
for bird in birds:
    print(f"{bird.common_name} ({bird.confidence:.0%}) - {bird.timestamp}")
    print(f"  Audio: {bird.audio_url}")
    print(f"  Image: {bird.image_url}")

# Station stats
stats = client.get_stats()
print(f"{stats.unique_species} species, {stats.call_count} calls")
print(f"Top bird: {stats.top_bird}")

# Weather
weather = client.get_weather()
print(f"{weather.condition}, {weather.temp_f}°F")

# Yard life-list
yard = client.get_yard_list(timeframe="all")
for entry in yard:
    print(f"{entry.common_name}: {entry.sighting_count} sightings")

# Species list with confidence thresholds
species = client.get_species_list()
for s in species:
    print(f"{s.common_name} ({s.species_code}) threshold={s.threshold:.2f}")

# Biodiversity ranking
rank = client.get_biodiversity_rank()
print(f"Rank {rank.rank} of {rank.competitors} ({rank.percentile}th percentile)")

# Streams (global public feeds)
streams = client.get_streams()
for s in streams:
    print(f"{s.title}: {s.live_stream_url}")

If you have only one Terra station, device_id is auto-selected. Otherwise pass it explicitly:

birds = client.get_latest_birds("0123FB1FA9136F95EE", count=5)

CLI

Quick test from the command line:

python -m terra_sdk

Environment Variables

Create a .env file:

USERNAME=you@example.com
PASSWORD=your-password

Or set TERRA_TOKEN directly if you already have one.

API Methods

Method Description
login() Authenticate and get token
get_devices() List your Terra stations
get_user_info() Account profile
get_latest_birds(device_id, count, min_confidence) Latest detections
get_species_list(device_id) All species detected at station
get_stats(device_id) Station statistics
get_weather(device_id) Weather at station
get_yard_list(device_id, timeframe) Yard life-list
get_biodiversity_rank(device_id) Biodiversity ranking
get_graph_stats(device_id) Call activity over time
get_streams() Public audio streams
get_notifications_list(device_id) Notification preferences
get_station_tags(device_id) Radio tags (Motus)
vote(detection_id, direction, device_id) Vote on bird ID

Models

All responses are typed Pydantic models:

  • BirdDetection — common_name, scientific_name, alpha_code, confidence, timestamp, audio_url, image_url
  • Station — id, alias, lat, lon, streaming, version
  • StationStats — unique_species, call_count, top_bird
  • Weather — temp_f, temp_c, condition, humidity, wind_mph
  • YardListEntry — common_name, species_code, sighting_count, first_seen
  • SpeciesInfo — common_name, species_code, threshold
  • Stream — title, live_stream_url, streaming
  • BioDiversityRank — rank, competitors, percentile
  • GraphStatsEntry — ts, total_calls, unique_species

Running Tests

pip install -e ".[dev]"
pytest tests/ -v

License

MIT

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

terra_listens_sdk-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

terra_listens_sdk-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file terra_listens_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: terra_listens_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.9

File hashes

Hashes for terra_listens_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c837d759ceffd9d99032c39528fd16f0b38fa11fa674d67f2257b2a23f1a39a4
MD5 9a7f2eb669f5a17c06081a0bc8467814
BLAKE2b-256 369c5677c70f32de7604095f18fd6b796cf24330d342c9273f89e0bbb0151d10

See more details on using hashes here.

File details

Details for the file terra_listens_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for terra_listens_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b668885bd3909331bcadd33cddef6f917bf84f812bb5c0550e67f99a299bc67a
MD5 9f576434e0a4b8661eb400c7daf32b88
BLAKE2b-256 63f90d19d7a6294d43e23347b2e3c3eb15dfb2c69c0c88541186184c48e7636f

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