{"library":"notifications-python-client","title":"GOV.UK Notify Python Client","description":"The `notifications-python-client` is the official Python API client for GOV.UK Notify, a service that allows government departments to send emails, SMS messages, and letters to their users. It is actively maintained by the Government Digital Service (GDS), with version 10.0.1 being the latest stable release, reflecting ongoing development and adherence to GOV.UK standards.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install notifications-python-client"],"cli":null},"imports":["from notifications_python_client.notifications import NotificationsAPIClient"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom notifications_python_client.notifications import NotificationsAPIClient\n\n# Ensure these are set as environment variables or retrieve securely\n# NOTIFY_API_KEY should be your service's API key (UUID format)\napi_key = os.environ.get('NOTIFY_API_KEY')\n\nif not api_key:\n    raise ValueError(\"NOTIFY_API_KEY environment variable not set.\")\n\n# For staging/test environments, you MUST specify the base_url:\n# client = NotificationsAPIClient(api_key=api_key, base_url='https://api.staging.notifications.service.gov.uk')\n# For production (default):\nclient = NotificationsAPIClient(api_key=api_key)\n\ntry:\n    response = client.send_email_notification(\n        email_address='test@example.com',\n        template_id='YOUR_EMAIL_TEMPLATE_ID', # Replace with a valid template ID from your Notify account\n        personalisation={\n            'name': 'Test User',\n            'application_status': 'approved'\n        },\n        reference='my_app_ref_123' # Optional reference for your records\n    )\n    print(\"Email sent successfully:\")\n    print(response)\nexcept Exception as e:\n    print(f\"Error sending email: {e}\")","lang":"python","description":"Demonstrates sending an email notification using the GOV.UK Notify client, including how to handle API keys from environment variables and basic error handling. Remember to replace `YOUR_EMAIL_TEMPLATE_ID` with a valid ID from your Notify service.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}