Skip to main content

Django MSGS

This small framework provides you with a set of flexible tools for implementing the message sending functionality.
Any type of informational messaging are available: emails, sms, telegram...

Installation

pip install django-msgs

settings.py:

INSTALLED_APPS = [
...
'msgs',
]

Apply the migrations for creation the tables at your database:

./manage.py migrate msgs

Structure

Django MSGS contains two common data models: Message and Template. The first one stores your messages, the second one describes the messaging templates.
If you need new type of email, you should create new Tpl with the HTML inside. After that you can use it for sending messages with this template.
By default Django MSGS provide you with three proxy models: Email, SMS and Message. You can customize them on your taste.
Also you can find a template model for any type of message: EmailTemplate, SMSTemplate and MessageTemplate.

Quick example

Look at the admin interface and create some templates for your messages.

Now we can use them for sending messages:

from msgs.models import Email

template_key = 'registration'  # a unique key for search the template
Email.create(
    template=template_key,
    recipient='john.doe@example.com',
    context={
        'name': 'John Doe',
        'link': 'https://example.com/registration',
    },
).send()

If you need i18n options, you can just inherit the existing template models with adding the needed language fields and use the send method with a language prefix as you need.

Let's look at the one more very useful attribute -- related_to. This library uses a generic foreign key for linking messages with another objects. You should provide this object when you create a message.

from msgs.models import SMS

instance = new_user  # this is an object you want to link with the email

SMS.create(
    template='registration',
    recipient='1234567890',
    context={
        'name': 'John Doe',
        'link': 'https://example.com/registration',
    },
    related_to=instance,  # it does the trick
).send()

Providers

The Django MSGS works with multiple providers. All of them are placed at the providers folder. So you can discover them and choose what you need.

You can find the BaseProvider class, hence nobody can stop you to build your own provider.

Settings

MSGS = {
    'providers': {
        'sendgrid': {
            'backend': 'msgs.providers.sendgrid.SendgridProvider',  # use SendGrid Provider
            'options': {
                'is_active': True,  # turn on/off sending messages
                'api_key': 'api-key',
                'sender': 'sender@email.com',
            },
        },
        'telegram': {
            'backend': 'msgs.providers.telegram.TelegramProvider',
            'options': {
                'is_active': False,
                'token': 'telegram-bot-token',
                'chat': 'chat-id',
            },
        },
    },
    'options': {
        'default_language': 'en',
    },
    'development': 'telegram',  # what use on development (not works properly, be careful)
    'email': 'sendgrid',  # use SendGrid Provider for sending emails
    'sms': 'telegram',  # use Telegram Provider for sending sms
}

Metadata

Release files for django-msgs 1.7.7

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

Source distribution (sdist)

Source distribution for django-msgs 1.7.7
File Size Uploaded
django_msgs-1.7.7.tar.gz 22.5 kB Details

Release files / django_msgs-1.7.7.tar.gz

Download URL django_msgs-1.7.7.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8f75d2cf3816c6f961b741199dda6387704bee127c8fdea380fc22b5dadf37a8
BLAKE2b-256 checksum
How to use checksums
f314e12ce6bef5e45d6acf5f3007d0588f823b06905c7b61af82ed9e2061d1b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.7.7 This release

1 release file

1.7.6

1 release file

1.7.5

1 release file

1.7.4

1 release file

1.7.3

1 release file

1.7.2

1 release file

1.7.1

1 release file

1.7.0

1 release file

1.6.12

1 release file

1.6.2

1 release file

1.6.1

1 release file

1.5.4

1 release file

1.5.3

1 release file

1.4.3

1 release file

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