Skip to main content

Synthesize eBird observation data with IUCN Red List conservation status

Project description

eBird-IUCN Synthesizer

CLI tool and Python library that synthesizes eBird observation data with IUCN Red List conservation status.

Problem

Ecologists spend hours manually cross-referencing bird sighting data when preparing conservation reports. eBird provides observation data, IUCN Red List provides threat categories — but these databases don't communicate automatically.

Solution

Query eBird for a region or coordinates, automatically enrich with IUCN threat status, and export clean JSON/CSV/Avro reports ready for analysis.

Features

  • Query by region code (e.g., RS, US-NY) or coordinates
  • IUCN Red List enrichment with local caching (90-day TTL)
  • Filter to threatened species only (VU/EN/CR)
  • Multiple output formats: JSON, CSV, Avro
  • Optional UUID resolution via BirdLife Resolution API
  • Stale-while-revalidate caching strategy
  • Cache backends: JSON files, SQLite, PostgreSQL

Installation

pip install birdlife-ebird-iucn

# With PostgreSQL support
pip install birdlife-ebird-iucn[postgres]

Quick Start

CLI

# Set up credentials
export EBIRD_API_KEY="your-key"      # https://ebird.org/api/keygen
export IUCN_API_TOKEN="your-token"   # https://api.iucnredlist.org/users/sign_up

# Query by region
python -m birdlife_ebird_iucn RS --format json

# Query by coordinates
python -m birdlife_ebird_iucn --lat 44.8 --lng 20.4 --days 7

# Threatened species only
python -m birdlife_ebird_iucn RS --threatened-only --format csv

Python API

import asyncio
from birdlife_ebird_iucn import Config, Synthesizer
from birdlife_ebird_iucn.serializers import JsonSerializer

async def main():
    config = Config()  # Reads from environment
    synth = Synthesizer.from_config(config)
    
    try:
        result = await synth.synthesize(
            region_code="RS",
            back_days=14,
            threatened_only=True,
        )
        
        print(f"Found {len(result.species)} threatened species")
        for species in result.species:
            print(f"  {species.iucn_status.value}: {species.scientific_name}")
        
        # Export to JSON
        print(JsonSerializer().serialize(result))
    finally:
        await synth.close()

asyncio.run(main())

Configuration

All settings via environment variables or .env file:

Variable Required Description
EBIRD_API_KEY Yes eBird API key
IUCN_API_TOKEN Yes IUCN Red List API token
CACHE_TYPE No json (default), sqlite, or postgres
CACHE_DIR No Cache directory (default: ./.cache)
CACHE_TTL_DAYS No Cache TTL in days (default: 90)
POSTGRES_URL If postgres PostgreSQL connection URL
RESOLUTION_API_URL No BirdLife Resolution API for canonical UUIDs
RESOLUTION_API_TOKEN No Bearer token for Resolution API

Cache Backends

JSON (default)

CACHE_TYPE=json
CACHE_DIR=./.cache

SQLite

CACHE_TYPE=sqlite
CACHE_DIR=./.cache

PostgreSQL

CACHE_TYPE=postgres
POSTGRES_URL=postgresql://user:pass@localhost:5432/birdlife

Resolution API

By default, UUIDs are generated locally. To use canonical BirdLife IDs:

RESOLUTION_API_URL=https://birdlife.tech/api/v1

Output Formats

JSON

Schema-compliant JSON following birdlife-schema.

CSV

Flattened tabular format for spreadsheet analysis.

Avro

Binary format for big data pipelines.

Examples

The examples/ directory contains ready-to-run examples:

CLI Example

cd examples
cp .env.example .env  # Add your API keys

# Query Serbia
python cli_example.py RS

# Query by coordinates (Belgrade)
python cli_example.py --lat 44.8 --lng 20.4 --days 7

# Threatened species only, CSV output
python cli_example.py RS --threatened-only --format csv

Jupyter Notebook

Interactive notebook with step-by-step examples:

cd examples
jupyter notebook notebook_example.ipynb

Region Codes

eBird uses hierarchical region codes:

  • Country: RS (Serbia), US (USA), GB (UK)
  • State/Province: US-NY (New York), CA-ON (Ontario)
  • County: US-NY-061 (New York County)

Find codes at: https://ebird.org/region/world

Development

# Clone and install
git clone https://github.com/birdlife-tools/ebird-iucn-synthesizer
cd ebird-iucn-synthesizer
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

# Run tests
pytest

# Type check
mypy src/

# Lint
ruff check src/

Architecture

synthesize() request
       │
       ▼
┌──────────────┐
│  eBird API   │ ─── recent observations
└──────────────┘
       │
       ▼
┌──────────────┐
│  IUCN Cache  │ ─── threat status (stale-while-revalidate)
└──────────────┘
       │
       ▼
┌──────────────┐
│  Resolver    │ ─── canonical UUIDs (optional)
└──────────────┘
       │
       ▼
┌──────────────┐
│  Serializer  │ ─── JSON / CSV / Avro
└──────────────┘

Community

Join the discussion:

Matrix

License

MIT — see LICENSE

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

birdlife_ebird_iucn-0.1.0.tar.gz (69.0 kB view details)

Uploaded Source

Built Distribution

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

birdlife_ebird_iucn-0.1.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for birdlife_ebird_iucn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55350c5d2074d4c7cc0b7e480d459d17467c440825c7a9d1146bbf35e91544e3
MD5 c23097b8534e985b8490703c7988dc71
BLAKE2b-256 3fd61cffa5084f98b359eee1d3b0c61efa4ce25b9321ea1d1c92932bd1aa17df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for birdlife_ebird_iucn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61376944a06ffe1642d25ae893e92239f61d55134bcc77ba55cc3c4e33b1832e
MD5 7767ceedf48ed6773853f34020be2c5b
BLAKE2b-256 5359b1749073a1f176fe1d1d1fe587ab62b762aa32d9bdcbe7642ed44791eb42

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