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:
- Register at https://xeno-canto.org
- Verify email
- 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)
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
Geographic filters
Quality and type filters
|
Temporal filters
Other and metadata filters
|
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xenocanto_api-0.1.1.tar.gz.
File metadata
- Download URL: xenocanto_api-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d420b6b621943f5334bb878aa2ff75291b40eb8ded2dc94724c97cd79bbd2f3c
|
|
| MD5 |
2d88d94a86604b99786e37a6490279dd
|
|
| BLAKE2b-256 |
3821faebef5e003685ad4545679a9e0550c7651b8cbb6fcc30fd7ff32a65a04f
|
File details
Details for the file xenocanto_api-0.1.1-py3-none-any.whl.
File metadata
- Download URL: xenocanto_api-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2802db14e19964505e109b9e6df67448736547a3a2be4bdb0a990d4595b86686
|
|
| MD5 |
84d4886171eedf94f17580cb5f8ef20f
|
|
| BLAKE2b-256 |
50b2363d7ea4918c18e92abecd7c4106b663c5cb4fb8a0cd1fce860a3eb0868c
|