Skip to main content

DJ-Nexmo

PyPI version Build Status Coverage Status

The Nexmo API is awesome - but there are some problems that developers using Nexmo need to solve again and again. This Django app provides Django-specific functionality on top of the Nexmo Client Library for Python! Currently it contains:

  • A decorator for validating and re-combining SMS message parts.
  • Template filters for rendering phone numbers in international and national formats.

How To Install It

Currently, dj-nexmo only supports Python 3.4+, and Django 2.0+. We may backport to Django 1.x, but we have no intention of backporting to Python 2.

First, pip install dj-nexmo

Add "djnexmo" to INSTALLED_APPS in your settings.

Run python manage.py migrate djnexmo to create the necessary models.

Configuration

NEXMO_API_KEY

This optional setting should be set to your Nexmo API Key, which you can obtain from the dashboard.

NEXMO_API_SECRET

This optional setting should be set to your Nexmo API Secret, which you can obtain from the dashboard.

NEXMO_SIGNATURE_SECRET

This optional setting should be set to your Nexmo Signature Secret, which you can obtain by contacting Nexmo support. You will need this setting if you wish to validate incoming SMS.

NEXMO_SIGNATURE_METHOD

This optional setting should be set to your Nexmo signing method, which you should obtain from Nexmo support when you obtain your Nexmo signature secret.

NEXMO_APPLICATION_ID

This optional setting should be set to the ID of a Nexmo Voice application.

NEXMO_PRIVATE_KEY

This optional setting should be set to your Nexmo Voice application's private key, or a path to a file containing your private key.

Using the Nexmo Client

dj-nexmo configures a Nexmo Client object from the settings above. You can use it by importing it from the djnexmo package:

from djnexmo import client

client.send_sms({
    'to': '447700900301',
    'from': '447700900414',
    'text': 'Hello from DJ Nexmo!'
})

Incoming SMS

dj-nexmo provides a view decorator which will ensure your webhook view is only called once all the parts of an SMS are available.

# This will automatically check the signature of the incoming request.
# The view will only be called once all parts of the SMS have arrived.
@sms_webhook
def sms_registration(request):
    # Your parsed & merged SMS message will be available as `request.sms`:
    sms = request.sms

    # Don't do any long processing here - you should return a 200 response as soon as possible.
    ...

    return HttpResponse("OK")

Formatting Phone Numbers

dj-nexmo adds a couple of template filters for formatting phone numbers, wrapping the awesome phonenumbers library.

{% load phonenumbers %}

International: {{ "447700900486" | international }} => +44 7700 900486
Local Format: {{ "447700900486" | national }}       => 07700 900486

Coming Soon:

  • A management command for clearing the database of old message parts where not all parts were received.
  • A decorator to validate other webhooks from the Nexmo API.

License

This code is open-source, released under the Apache License. This means it is free to use for commercial or non-commercial purposes, and you can make any changes you would like or need.

Contribute!

We :heart: contributions -- if you'd like help contributing to this project, please contact us! If you want to do anything particularly significant, we recommend you open up an issue to discuss it with us first. If there's something you'd like to see, please open an issue for that too! If you find a bug, please create an issue - any help you can give providing a small code sample that demonstrates the problem you've seen would be very useful and means we should be able to solve your problem sooner!

Metadata

Release files for dj-nexmo 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-nexmo 0.0.4
File Size Uploaded Provenance
dj-nexmo-0.0.4.tar.gz 23.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-nexmo 0.0.4
File Interpreter ABI Platform
dj_nexmo-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 34.5 kB

Release files / dj-nexmo-0.0.4.tar.gz

Download URL dj-nexmo-0.0.4.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a8d323bd597b8beaf52ed6e38d37670e38c82bc06a7a5b8a79fe935a79df9861
BLAKE2b-256 checksum
How to use checksums
703197433514dd76d4dc13c09d51ebe409e799fbd485e3154cffb64b2d6fc6a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

Release files / dj_nexmo-0.0.4-py3-none-any.whl

Download URL dj_nexmo-0.0.4-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd6170326b27eb507669c7cbf54b62e8c7a9b9adb8b01ee85010e5be221ec6ce
BLAKE2b-256 checksum
How to use checksums
8fe5529d0da71a65fdaaa2fb9911c3fe48b02b84c97dffc9d2c719dd0d47567c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

Security for dj-nexmo 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page