Python Client Library¶
A production-ready Python client for the Danish Parliament API (oda.ft.dk) with comprehensive error handling, pagination support, and async capabilities.
Installation¶
Quick Start¶
from danish_parliament_api import DanishParliamentAPI
# Initialize client
api = DanishParliamentAPI()
# Get recent cases
cases = api.get_cases(top=10)
print(f"Found {len(cases['value'])} cases")
# Search for climate legislation
climate_cases = api.get_cases(filter_expr="substringof('klima', titel)")
print(f"Climate cases: {len(climate_cases['value'])}")
# Get voting records for a politician
votes = api.get_voting_records("Frank Aaen")
print(f"Found {len(votes)} votes")
Features¶
- Production-Ready: Comprehensive error handling and retry logic
- Pagination Support: Automatic handling of large datasets
- Type Hints: Full type annotations for better IDE support
- Async Support: Both sync and async clients available
- Rate Limiting: Built-in request throttling
- Caching: Optional response caching
Client Libraries¶
- Basic Client - Complete synchronous client
- Pagination - Large dataset handling
- Error Handling - Robust error patterns
- Async Client - Concurrent requests
Examples¶
Parliamentary Monitoring¶
# Monitor recent activity
recent_changes = api.get_recent_changes(hours_back=4)
for case in recent_changes['value']:
print(f"Updated: {case['titel']} at {case['opdateringsdato']}")
Voting Analysis¶
# Get all votes by party in a specific session
votes = api.get_voting_session_details(12345, expand_actors=True)
party_votes = api.analyze_party_voting(votes)
Document Tracking¶
# Find documents with file attachments
docs = api.get_documents_with_files(
filter_expr="substringof('budget', titel)"
)
Error Handling¶
The client handles all common API errors:
- HTTP 400: Invalid OData syntax - provides detailed error message
- HTTP 404: Invalid entity or ID - graceful fallback
- HTTP 501: Unsupported operations - clear error messages
- Network errors: Automatic retry with exponential backoff
- Rate limiting: Built-in throttling to respect API limits
Best Practices¶
- Use pagination for large datasets (max 100 records per request)
- Always URL encode OData parameters (
%24not$) - Handle empty results gracefully
- Use field selection (
$select) for better performance - Cache responses when appropriate