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

Install the package using pip:

pip install xenocanto-api

API Key Setup

Starting October 10, 2025 users need a Xeno-canto API key to download recordings from the Xeno-canto API:

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

Usage (with examples)

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)

API key setup

Option 1: Use an environmental variable

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 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 France:

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

Download grasshopper recordings while filtering by recordist, altitude and year:

xcapi --grp grasshoppers --rec "Baudewijn Odé" --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


# Add 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 recordings
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_only(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"
  • 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 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.2.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.2.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xenocanto_api-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 0dd1100eeb7d006c421d5f7209d8167561ae24b51712781997fe75ce27d4e95e
MD5 33acd90cf744bf0b796c3aea07c16c28
BLAKE2b-256 c47a4eda76ebe2be65c08e4144db3304071d430020d4a62f5133a00487dc27d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xenocanto_api-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06b350e95131f01112bb261540e5f48ddc37eae1dc89b97dcd847d46424a79aa
MD5 32853772765ef8f4d086a0420a17a918
BLAKE2b-256 00929d5b6225f909f68bddec85e862d8f71b0896c54fee24eb5f6c734294a84a

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