Skip to main content

A Python library for querying and downloading recordings from the Xeno-canto API.

Project description

xcapi: Xeno-canto API

A Python package for downloading animal sounds from the Xeno-canto API.

Features

  • Comprehensive search: Support for all Xeno-canto API v3 search tags:
    • Taxonomic: genus, species, subspecies, family, group, English name
    • Geographic: country, location, area, bounding box, latitude, longitude, altitude
    • Quality: rating, sound type, sex, life stage, recording method
    • Temporal: year, month, upload date, time of day
    • Metadata: recordist, length, license, equipment (device, microphone), sample rate, temperature, and more
  • Operator and range support: Use comparisons like <, >, and ranges (10-20) across supported fields.
  • Two easy ways to use it: You can run searches directly from the command line (CLI) without writing any code, or use it inside your Python scripts (API) with a simple, chainable query builder.

Installation

Step 1: Clone the repository

git clone https://github.com/bghani/xcapi.git
cd xcapi

Step 2: Install the package

pip install -e .

Usage (with examples)

You need a Xeno-canto API key to use this package. Register at xeno-canto.org and verify your email to get your key from your account page.

The package can be used either as a CLI (Command Line Interface) for quick terminal-based commands, or as a Python API for programmatic access through the QueryBuilder, XenoCantoClient, and Downloader classes.

Command Line (CLI)

Set your API key as an environment variable:

export XENO_CANTO_API_KEY="your-api-key"

Show all the available command-line options:

xcapi --help

Download all Grasshopper recordings and metadata from Europe:

xcapi --grp grasshoppers --area europe --output_dir ./data

Download high-quality bird songs and metadata from Spain:

xcapi --grp birds --cnt Spain --type song --q A --output_dir ./data

Download bird recordings while filtering by altitude and year:

xcapi --grp birds --alt 1000-2000 --year ">2023" --output_dir ./data

Download frog sounds while filtering by sample rate and recording quality:

xcapi --grp frogs --smp ">44100" --q "<C" --output_dir ./data

Download just the metadata:

xcapi --grp frogs --smp ">44100" --q "<C" --output_dir ./data --metadata_only

Python API

from xcapi.query import QueryBuilder
from xcapi.client import XenoCantoClient
from xcapi.downloader import Downloader

# Build a query
query = QueryBuilder().group("birds").country("Spain").quality("A").build()

# Fetch recordings
client = XenoCantoClient(api_key="your-api-key")
recordings = client.search(query)

# Download recordings and metadata
downloader = Downloader(output_dir="./data")
downloader.download_recordings(recordings)

# Download just the metadata
downloader = Downloader(output_dir="./data")
downloader._save_metadata(recordings)

In this way, you can chain multiple filters when building a query. Here is a list of all filters that can be used:

Taxonomic filters

  • genus(genus_name)
  • species(species_name)
  • subspecies(subspecies_name)
  • family(family_name)
  • group(group_name) – e.g. "birds", "grasshoppers", "bats", "land mammals", "frogs"
  • english_name(name)

Geographic filters

  • country(country_name)
  • location(location_name)
  • area(region_name) – e.g. "Europe", "Asia", "Africa"
  • bounding_box(lat_min, lon_min, lat_max, lon_max)
  • latitude(range_or_operator) – e.g. "40-45", ">50"
  • longitude(range_or_operator) – e.g. "-10-0", "<-100"
  • altitude(range_or_operator) – e.g. "100-500", "<1000"

Quality and type filters

  • quality(rating) – one of "A", "B", "C", "D", "E", or operators like ">B", "<C"
  • sound_type(type) – e.g. "song", "call", "drumming"
  • sex(sex) – e.g. "male", "female", "uncertain"
  • life_stage(stage) – e.g. "adult", "juvenile"
  • method(method) – e.g. "field recording"

Temporal filters

  • year(year_or_range) – e.g. "2020", "2015-2020", ">2018"
  • month(month_or_range) – e.g. "6", "1-3"
  • since(days) – recordings uploaded in the last N days – e.g. "2", "5" or since a date – e.g. "2012-11-09".
  • time_of_day(time_or_range) – e.g. "06:00", "06:00-12:00"

Other and metadata filters

  • recordist(name) – e.g. "John Doe"
  • length(length_or_range) – e.g. "10-20", "<30", ">60"
  • license(license_type) – e.g. "cc-by", "cc0"
  • also(species) – background species
  • animal_seen(True/False)
  • playback_used(True/False)
  • number_in_group(value) – e.g. "1", "2-5", ">10"
  • catalogue_number(number) – e.g. "12345", ">100000"
  • temperature(value) – e.g. "20-30", "<10"
  • registration_number(value)
  • automatic_recording("yes"|"no"|"unknown")
  • device(device_name)
  • microphone(microphone_name)
  • sample_rate(rate) – e.g. "44100", ">48000", "44100-96000"
  • remarks(text)

Visit this page to get more detailed information on different search tags.

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

xenocanto_api-0.1.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

xenocanto_api-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xenocanto_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aba1e7f6f08e5b1c0a5a92c5592b0cc53653d99e1a4c008966e95c0fa266eabc
MD5 877df162f15d8b720dca7f57a14ddeb4
BLAKE2b-256 0d32bc47827130bf09e7ea9d93960e22269fc6c11a13e2cf7a82ce16750d344d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xenocanto_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for xenocanto_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe80d74f5a396c5ed34780fcd90e6a1b479edb9e130e21f961a197d61dc50cc0
MD5 a20ebbc98d717ac6572c90dc686e7d56
BLAKE2b-256 390e0150c9a69632a8a8e4fe43bce56aec09a78ff1987d2337f107d6d30565c9

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