Official client libraries are available for popular programming languages. These libraries handle authentication, request formatting, and error handling automatically.
Available Libraries
Python notifications-python-client
Ruby notifications-ruby-client
Java notifications-java-client
Node.js notifications-node-client
All client libraries are open source and available on GitHub. Contributions are welcome!
Python Client
Installation
pip install notifications-python-client
Quick Start
from notifications_python_client.notifications import NotificationsAPIClient
# Initialize client with API key
client = NotificationsAPIClient( api_key = "your-api-key-here" )
# Send SMS
response = client.send_sms_notification(
phone_number = "+447900900123" ,
template_id = "f33517ff-2a88-4f6e-b855-c550268ce08a" ,
personalisation = {
"name" : "John Smith"
},
reference = "customer-1234"
)
print ( f "Notification ID: { response[ 'id' ] } " )
# Send email
response = client.send_email_notification(
email_address = "[email protected] " ,
template_id = "a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d" ,
personalisation = {
"name" : "Jane Doe" ,
"amount" : "£25.00"
}
)
# Get notification status
notification = client.get_notification_by_id(response[ 'id' ])
print ( f "Status: { notification[ 'status' ] } " )
# List notifications
notifications = client.get_all_notifications(
template_type = "email" ,
status = "delivered"
)
Repository
Python Client View on GitHub - Full documentation and examples
Ruby Client
Installation
Add to your Gemfile:
gem 'notifications-ruby-client'
Then install:
Or install directly:
gem install notifications-ruby-client
Quick Start
require 'notifications/client'
# Initialize client
client = Notifications :: Client . new ( api_key: 'your-api-key-here' )
# Send SMS
response = client. send_sms (
phone_number: '+447900900123' ,
template_id: 'f33517ff-2a88-4f6e-b855-c550268ce08a' ,
personalisation: {
name: 'John Smith'
},
reference: 'customer-1234'
)
puts "Notification ID: #{ response. id } "
# Send email
response = client. send_email (
email_address: '[email protected] ' ,
template_id: 'a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d' ,
personalisation: {
name: 'Jane Doe' ,
amount: '£25.00'
}
)
# Get notification
notification = client. get_notification (response. id )
puts "Status: #{ notification. status } "
# List notifications
notifications = client. get_notifications (
template_type: 'email' ,
status: 'delivered'
)
Repository
Ruby Client View on GitHub - Full documentation and examples
Java Client
Installation
Add to your pom.xml: < dependency >
< groupId > uk.gov.service.notify </ groupId >
< artifactId > notifications-java-client </ artifactId >
< version > 5.0.0-RELEASE </ version >
</ dependency >
Add to your build.gradle: dependencies {
implementation 'uk.gov.service.notify:notifications-java-client:5.0.0-RELEASE'
}
Quick Start
import uk.gov.service.notify.NotificationClient;
import uk.gov.service.notify.Notification;
import uk.gov.service.notify.SendSmsResponse;
import uk.gov.service.notify.SendEmailResponse;
import java.util.HashMap;
public class NotifyExample {
public static void main ( String [] args ) {
// Initialize client
NotificationClient client = new NotificationClient ( "your-api-key-here" );
try {
// Send SMS
HashMap < String , String > personalisation = new HashMap <>();
personalisation . put ( "name" , "John Smith" );
SendSmsResponse smsResponse = client . sendSms (
"f33517ff-2a88-4f6e-b855-c550268ce08a" , // template ID
"+447900900123" , // phone number
personalisation,
"customer-1234" // reference
);
System . out . println ( "Notification ID: " + smsResponse . getNotificationId ());
// Send email
SendEmailResponse emailResponse = client . sendEmail (
"a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d" , // template ID
"[email protected] " , // email address
personalisation,
"customer-5678" // reference
);
// Get notification
Notification notification = client . getNotificationById (
emailResponse . getNotificationId (). toString ()
);
System . out . println ( "Status: " + notification . getStatus ());
} catch ( Exception e ) {
System . err . println ( "Error: " + e . getMessage ());
}
}
}
Repository
Java Client View on GitHub - Full documentation and examples
Node.js Client
Installation
npm install notifications-node-client
Quick Start
const NotifyClient = require ( 'notifications-node-client' ). NotifyClient ;
// Initialize client
const notifyClient = new NotifyClient ( 'your-api-key-here' );
// Send SMS
notifyClient . sendSms (
'f33517ff-2a88-4f6e-b855-c550268ce08a' , // template ID
'+447900900123' , // phone number
{
personalisation: {
name: 'John Smith'
},
reference: 'customer-1234'
}
). then ( response => {
console . log ( 'Notification ID:' , response . data . id );
}). catch ( err => {
console . error ( 'Error:' , err );
});
// Send email
notifyClient . sendEmail (
'a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d' , // template ID
'[email protected] ' , // email address
{
personalisation: {
name: 'Jane Doe' ,
amount: '£25.00'
},
reference: 'customer-5678'
}
). then ( response => {
console . log ( 'Notification ID:' , response . data . id );
});
// Get notification (async/await)
async function checkNotification ( notificationId ) {
try {
const notification = await notifyClient . getNotificationById ( notificationId );
console . log ( 'Status:' , notification . data . status );
} catch ( err ) {
console . error ( 'Error:' , err );
}
}
// List notifications
notifyClient . getNotifications (
'email' , // template type
'delivered' , // status
'' , // reference
'' // older than
). then ( response => {
console . log ( 'Notifications:' , response . data . notifications );
});
Repository
Node.js Client View on GitHub - Full documentation and examples
Common Client Features
All official client libraries support:
Sending Notifications
Send SMS - send_sms() or equivalent
Send email - send_email() or equivalent
Send letter - send_letter() or equivalent
Send precompiled letter - send_precompiled_letter() or equivalent
Get notification by ID - Retrieve details of a sent notification
List notifications - Get all notifications with optional filtering
Get template by ID - Retrieve template details
List templates - Get all templates
Preview template - Generate template preview with personalisation
Inbound SMS
List received text messages - Retrieve inbound SMS messages
Error Handling
All clients throw/raise exceptions for API errors:
from notifications_python_client.errors import HTTPError
try :
response = client.send_sms_notification( ... )
except HTTPError as e:
print ( f "Error { e.status_code } : { e.message } " )
begin
response = client. send_sms (...)
rescue Notifications :: Client :: RequestError => e
puts "Error #{ e. code } : #{ e. message } "
end
try {
SendSmsResponse response = client . sendSms (...);
} catch ( NotificationClientException e ) {
System . err . println ( "Error " + e . getHttpResult () + ": " + e . getMessage ());
}
try {
const response = await notifyClient . sendSms ( ... );
} catch ( err ) {
console . error ( `Error ${ err . response . status } : ${ err . message } ` );
}
Authentication
All client libraries handle JWT authentication automatically:
You provide your API key when initializing the client
The client generates a JWT token for each request
The token is included in the Authorization header
Tokens are generated fresh for each request (no caching)
You don’t need to manually generate JWT tokens when using client libraries. The libraries handle this automatically.
Client Library Requirements
When developing applications with Notify client libraries:
API Key Storage
Never hardcode API keys in your source code. Use environment variables or secret management systems.
import os
from notifications_python_client.notifications import NotificationsAPIClient
# Load from environment variable
api_key = os.environ.get( 'NOTIFY_API_KEY' )
client = NotificationsAPIClient(api_key)
Clock Synchronization
Ensure your system clock is synchronized:
JWT tokens include an iat (issued at) timestamp
Server rejects tokens if clock skew > 30 seconds
Use NTP to keep system time accurate
Dependencies
Client libraries have minimal dependencies:
Python : requests, PyJWT, pydantic
Ruby : jwt, httparty
Java : org.json, commons-codec
Node.js : jsonwebtoken, axios
Contributing
All client libraries are open source and accept contributions:
Report issues - File bug reports or feature requests on GitHub
Submit PRs - Contributions welcome for bug fixes and features
Documentation - Help improve examples and documentation
Testing - Add test coverage for new features
Writing New Clients
If you want to create a client for a language not listed here:
Review the Writing Public APIs guide
Study existing client implementations
Ensure complete API coverage
Include comprehensive tests
Document all methods and parameters
Submit to alphagov GitHub organization
Support
For client library issues:
Bug reports : File issues on the respective GitHub repository
Feature requests : Open a discussion on GitHub
API questions : Contact GOV.UK Notify support
Security issues : Email [email protected]
Next Steps
Quickstart Follow the quickstart guide
API reference Explore API endpoints
Authentication Learn about API authentication
Rate limits Understand rate limits