Examples
Real-world examples of using the IDTAP API for common tasks.
Code Examples
All examples are available in the examples/ directory of the GitHub repository.
Common Patterns
Authentication and Setup
Every script starts with authentication:
from idtap import login_google, SwaraClient
# One-time authentication (opens browser)
login_google()
# Create client for API calls
client = SwaraClient()
Data Processing Workflow
Typical workflow for analyzing transcriptions:
from idtap import Piece
# 1. Get available transcriptions
transcriptions = client.get_transcriptions()
# 2. Load specific transcription
piece_id = transcriptions[0]['_id']
piece_data = client.get_transcription(piece_id)
# 3. Convert to rich data model
piece = Piece.from_json(piece_data)
# 4. Analyze musical content
for phrase in piece.phrases:
# Your analysis code here
pass
Error Handling Pattern
Robust error handling for API calls:
import requests
from idtap import SwaraClient
client = SwaraClient()
try:
transcriptions = client.get_transcriptions()
except requests.exceptions.ConnectionError:
print("Cannot connect to IDTAP server")
except requests.exceptions.HTTPError as e:
print(f"HTTP error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Next Steps
Browse the detailed examples in the sections above
Check the API Reference for complete API reference
Visit the GitHub repository for more examples