Skip to main content

An intuitive, type-safe Python wrapper for the Xeno-Canto API

Project description

Xeno Canto API Client for Python

Python Version Pydantic License: MIT

An intuitive, type-safe Python wrapper for the Xeno-Canto API.
Streamline your bioacoustics and machine learning workflows by searching, filtering, and processing wildlife recordings with full validation and IDE autocompletion.

Project Sponsors

asp-lab-logo tel-hai-logo

Disclaimer

This project is a free and open-source tool intended for educational purposes only;
This project is provided AS IS without any warranty - use at your own risk;
This project is not associated with, maintained by, or endorsed by the Xeno-Canto Foundation;
Users are responsible for adhering to the Xeno-Canto Terms of Use and respecting the licensing of individual recordings.

Quickstart

pip install xc-api-py
pdm add xc-api-py

Basic Usage

from xc_api import Client, SearchQuery, tags
from datetime import timedelta

# Instanciate a client with your Xeno Canto API key
client = Client('Your API key')

# Create a query
query = SearchQuery(
  animal_genus='acrocephalus',
  animal_sex='male',
  recording_length=tags.Length.at_least(timedelta(seconds=10)),
  recording_country=tags.Country('germany'),
)

# Search the API, optionally pass a limit argument
recordings = client.find(query, limit=10)

# Get a specific recording
recording = client.get_by_id('129150')

Advanced Usage

Pandas

from xc_api import SearchQuery, RecordingAudio
import pandas as pd

query = SearchQuery(...)
recordings = client.find(query)
df = pd.DataFrame.from_records([r.model_dump() for r in recordings])

SoundDevice

from xc_api import SearchQuery, RecordingAudio
import sounddevice as sd

recording = client.get_by_id(...)

audio = RecordingAudio.from_recording(recording)

with audio.load() as a:
  sd.play(a.to_numpy(), a.sample_rate)
  sd.wait()

# Optional: save original file locally
audio.save()

BirdNET

from xc_api import SearchQuery, RecordingAudio
from birdnetlib import RecordingBuffer
from birdnetlib.analyzer import Analyzer
from datetime import timedelta

analyzer = Analyzer()

query = SearchQuery(
  animal_group='birds',
  recording_sample_rate=tags.SampleRate(48000), # IMPORTANT: BirdNET analyzer expects 48000Khz
)

recording = client.find_one(query, limit=1)

audio = RecordingAudio.from_recording(recording)

with audio.load() as a:
  arr = a.to_birdnet(length=timedelta(seconds=3.0)) # Optional: Segment the audio

buffer = RecordingBuffer(analyzer, arr)
buffer.analyze()

for detection in buffer.detections:
  ...

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

xc_api_py-0.1.11.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

xc_api_py-0.1.11-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file xc_api_py-0.1.11.tar.gz.

File metadata

  • Download URL: xc_api_py-0.1.11.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xc_api_py-0.1.11.tar.gz
Algorithm Hash digest
SHA256 6c164ee9ecbb7a03efa746a2a542d11871d4b939e5dd68366c4615d8c084b514
MD5 791618523da331346484fcb173e07eea
BLAKE2b-256 5ff805ecf478747e7148a19db56c04eb73e42dc6449b1a0ae7b040d0b9d49c37

See more details on using hashes here.

Provenance

The following attestation bundles were made for xc_api_py-0.1.11.tar.gz:

Publisher: pypi-publish.yml on yuvalrot479/xc-api-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xc_api_py-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: xc_api_py-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xc_api_py-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 cf7bf053e790b951385cb602ae30e8ec000fcb678384dfb6884fd7ae87783f63
MD5 4bfbb3838ed9c50a90e8bc5f9f234c02
BLAKE2b-256 c995bb5aa2618f7c4a9b7d2f08db5318aeca11a95a713dfe3cef1c24bda92c82

See more details on using hashes here.

Provenance

The following attestation bundles were made for xc_api_py-0.1.11-py3-none-any.whl:

Publisher: pypi-publish.yml on yuvalrot479/xc-api-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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