Client Architecture
All API clients inherit fromNotifyAdminAPIClient, which extends the notifications-python-client base class.
Base Client
File:app/notify_client/__init__.py
- Automatic authentication header generation
- Request tracing for debugging
- User ID tracking for audit logs
- Shared configuration across all clients
Request Caching
File:app/notify_client/__init__.py
@cache.set(key_pattern)- Cache GET responses@cache.delete(key_pattern)- Invalidate on updates- Automatic key formatting with parameters
API Clients
The application includes 30 API client modules:Service API Client
File:app/notify_client/service_api_client.py
Manages service operations.
create_service()- Create new serviceget_service()- Fetch service (cached)update_service()- Update service settingsget_service_statistics()- Get usage statsfind_services_by_name()- Search servicesupdate_status()- Change service active status
User API Client
File:app/notify_client/user_api_client.py
Manages user operations.
Organisation API Client
File:app/notify_client/organisations_api_client.py
Manages organisation operations:
get_organisation(org_id)get_organisation_by_domain(domain)get_service_organisation(service_id)create_organisation()update_organisation()archive_organisation()
Notification API Client
File:app/notify_client/notification_api_client.py
Handles notification queries and operations:
get_notification(service_id, notification_id)get_notifications_for_service()send_notification()- Send single notificationupdate_notification_to_cancelled()
Job API Client
File:app/notify_client/job_api_client.py
Manages batch jobs:
get_job(service_id, job_id)get_jobs(service_id)create_job()cancel_job()cancel_letter_job()
Template Clients
Template Folder API Client
File:app/notify_client/template_folder_api_client.py
create_template_folder()get_template_folders()update_template_folder()delete_template_folder()move_to_folder()
Template Statistics Client
File:app/notify_client/template_statistics_api_client.py
get_template_statistics_for_service()get_monthly_template_usage()
Template Email File Client
File:app/notify_client/template_email_file_client.py
upload_email_attachment()get_email_attachment()
Branding Clients
Email Branding Client
File:app/notify_client/email_branding_client.py
get_email_branding()get_all_email_branding()create_email_branding()update_email_branding()
Letter Branding Client
File:app/notify_client/letter_branding_client.py
get_letter_branding()get_all_letter_branding()create_letter_branding()update_letter_branding()
API Key Client
File:app/notify_client/api_key_api_client.py
get_api_keys(service_id)create_api_key()revoke_api_key()
Invite Clients
Invite API Client
File:app/notify_client/invite_api_client.py
create_invite()get_invites_for_service()check_token()accept_invite()cancel_invited_user()
Org Invite API Client
File:app/notify_client/org_invite_api_client.py
create_invite()get_invites_for_organisation()check_token()accept_invite()
Other Specialized Clients
- Billing API Client (
billing_api_client.py) - Billing operations - Complaint API Client (
complaint_api_client.py) - Email complaints - Contact List API Client (
contact_list_api_client.py) - Saved contact lists - Events API Client (
events_api_client.py) - Audit events - Inbound Number Client (
inbound_number_client.py) - SMS receive numbers - Letter Attachment Client (
letter_attachment_client.py) - Letter attachments - Letter Jobs Client (
letter_jobs_client.py) - Letter job operations - Letter Rate API Client (
letter_rate_api_client.py) - Postage rates - Performance Dashboard Client (
performance_dashboard_api_client.py) - Platform metrics - Platform Admin API Client (
platform_admin_api_client.py) - Admin operations - Protected Sender ID Client (
protected_sender_id_api_client.py) - SMS sender IDs - Provider Client (
provider_client.py) - SMS/email provider management - Report Request Client (
report_request_api_client.py) - Data exports - SMS Rate Client (
sms_rate_client.py) - SMS pricing - Status API Client (
status_api_client.py) - API health checks - Unsubscribe API Client (
unsubscribe_api_client.py) - Unsubscribe requests - Upload API Client (
upload_api_client.py) - File uploads
Client Registration
All clients are initialized and imported inapp/__init__.py:
Usage Patterns
In Models
Models use clients to fetch data:In Views
Views can use clients directly:Audit Trail
The_attach_current_user helper automatically adds the current user to create/update operations:
Error Handling
Clients raiseHTTPError exceptions that are caught by global error handlers:
app/__init__.py:register_errorhandlers():
Caching Strategy
Cache Keys
Cache keys use parameter formatting:Cache Invalidation
Updates invalidate related caches:Template Preview Client
File:app/template_previews.py
Special client for the template preview service (separate from main API):
Next Steps
- Models - Learn how models use API clients
- Flask Blueprints - See clients used in views
- Application Structure - Understand overall architecture