Skip to main content

xcapi: Xeno-canto API

A Python package for downloading animal sound recordings from the Xeno-canto API. Works with birds, grasshoppers, bats, frogs, and more.

No programming knowledge required — xcapi can be used entirely from the command line.

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 (e.g. 10-20) across supported fields.
  • Smart incremental downloads: xcapi remembers what you have already downloaded and only fetches new recordings on repeat runs — no duplicate downloads, no wasted bandwidth.
  • Preview before downloading: Use --metadata_only to see what a query would return and how many new recordings would be added, without downloading any audio.
  • Two easy ways to use it: Run searches directly from the command line (CLI) without writing any code, or use it inside Python scripts with a simple, chainable query builder.

Installation

pip install xenocanto-api

API Key Setup

Starting October 10, 2025, a Xeno-canto API key is required to download recordings:

  1. Register at https://xeno-canto.org
  2. Verify your email
  3. Get your key from https://xeno-canto.org/account

Output Files

xcapi creates and manages the following files inside your --output_dir:

File Description
metadata.csv Metadata for all downloaded recordings. Grows with each download run. Never overwritten unless --redownload is used.
xcapi_runs.json Internal log of downloaded recording IDs, organised by timestamp. Used to skip already-downloaded recordings on future runs. As IDs are stored by download date, this file also serves as a download history that can be useful for tracking dataset growth over time or for reproducibility purposes.
metadata_only.csv Created by --metadata_only runs. Contains only recordings not yet downloaded — a preview of what a real download would add. Overwritten fresh on each --metadata_only run.

Audio files are saved into per-species subfolders inside output_dir, e.g. output_dir/Turdus_merula/.

Note: metadata.csv and xcapi_runs.json are only updated by real download runs. Running --metadata_only never modifies them.

Usage

Command Line (CLI)

API key setup

Option 1: Environment variable (recommended)

export XENO_CANTO_API_KEY="your-api-key"

Option 2: Pass it directly each time

xcapi --api_key "your-api-key" --grp birds --cnt Spain

Show all available options:

xcapi --help

Downloading recordings

Download all grasshopper recordings from Europe:

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

Download high-quality bird songs from France:

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

Download grasshopper recordings filtered by recordist, altitude, and year:

xcapi --grp grasshoppers --rec "Baudewijn Odé" --alt 1000-2000 --year ">2023" --output_dir ./data

Download frog sounds filtered by sample rate and quality:

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

Re-run the same command — xcapi will automatically skip recordings already downloaded and only fetch new ones. Note that skipping only works when you point to the same --output_dir as a previous download, and that directory contains either xcapi_runs.json or metadata.csv:

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

Previewing before downloading

Use --metadata_only to check what a query returns and how many recordings you don't have yet, without downloading any audio. Results are saved to metadata_only.csv:

xcapi --grp birds --cnt France --output_dir ./data --metadata_only

This is useful for estimating download size or checking for new additions before committing to a full download.


Re-downloading everything from scratch

Use --redownload to ignore previous download records and start completely fresh. This re-downloads all recordings and overwrites metadata.csv and xcapi_runs.json:

xcapi --grp birds --cnt France --output_dir ./data --redownload

Python API

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

# Set up client with your API key
client = XenoCantoClient(api_key="your-api-key")

# Alternatively, use a .env file to avoid passing the key each time:
# Create a file called .env in your working directory and add:
# XENO_CANTO_API_KEY=your-api-key
# Then simply run:
client = XenoCantoClient()

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

# Fetch recording metadata from Xeno-canto
recordings = client.search(query)

# Download recordings
# xcapi will skip recordings already downloaded and only fetch new ones
downloader = Downloader(output_dir="./data")
downloader.download_recordings(recordings)

# Preview what's new without downloading audio
# Writes metadata_only.csv with recordings not yet downloaded
downloader.save_metadata_only(recordings)

# Re-download everything from scratch
downloader.download_recordings(recordings, redownload=True)

Available query filters

You can chain multiple filters when building a query:

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"
  • 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. "Raziya Qadri"
  • 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)
  • xc_number(value) – e.g. "76967", "88888-88890", ">76967"
  • 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 for more detail on search tags.

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.4.0.tar.gz (30.2 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.4.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xenocanto_api-0.4.0.tar.gz
Algorithm Hash digest
SHA256 28f11655e9a78d1812afef2cca4d45d7946b044d242711ae4b3f9a42e4acd5a4
MD5 c21e1b1b388f6b37969fac6c2f20e06a
BLAKE2b-256 1aead69be4a3ca6e78cd9a634e06c6f2316ac0141f556e4d158b92af7c8a29a0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for xenocanto_api-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78a7a4419580e0fac72d180a369ff04db859efbb2b4297e84336fe06e2c1a58b
MD5 10b238e79e68f9c054ae524a90657b66
BLAKE2b-256 a468a82072c51ac1e27b9713b994de8b97948f60f1e11e06fc6192cf433a8a98

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page