Skip to main content

A simple SMS text alert utility for Python projects

Project description

text-alert

Send an SMS text alert using Python and Gmail

Requirements

  • Python 3.11+ (required for reading toml files)
  • A configured Gmail Account (see below)

Step 1. Install this Module

Add this to your requirements.txt and install.

git+https://github.com/denisecase/text-alert.git

Step 2. Add .env.toml To your Python Project

Create a new .env.toml file in your Python project (or add these entries).

  • Update the outgoing email address to your gmail address.
  • Update the sms address for texts to your number, using your carrier's gateway (see .env.example.toml or do a search).
  • We'll create an app password later.
# SMTP Email Configuration
outgoing_email_host = "smtp.gmail.com"
outgoing_email_port = 587
outgoing_email_address = "yourname@gmail.com"
outgoing_email_password = "aaaabbbbccccdddd"

# SMS Configuration
sms_address_for_texts = "1112224444@msg.fi.google.com"

Step 3. Add .env.toml To .gitignore

Ensure your secrets are not published by adding an entry in .gitignore:

.env.toml

Step 4. Gmail - Enable IMAP

  • Open Gmail.
  • Click Settings or ⚙️ in the top-right.
  • Then click "See all settings".
  • Navigate to "Forwarding and POP/IMAP".
  • Under "IMAP access", select "Enable IMAP".
  • Click "Save Changes".

Step 5. Gmail - Generate an App Password

If your account has 2FA enabled, you must generate an App Password:

  • Go to https://support.google.com/accounts/answer/185833?hl=en
  • Click on "Create and manage your app passwords".
  • Sign in and navigate to Account "Security" / "App Passwords"
  • Create an app password - name it (e.g., "PythonTextAlerts").
  • Generate and copy the 16-character password.
  • Paste the 16-char as your password in .env.toml file.
    • Remove any spaces
    • Keep it private - ensure your .env.toml file is listed in .gitignore

Step 6. Import and Use in a Python Script

Once installed and your .env.toml file is ready, you can use it in your code.

from dc_texter import send_text

message = "Testing text alerts from Python."

try:
    send_text(body=message)
    print(f"SUCCESS. Text sent: {message}")
except RuntimeError as e:
    print(f"ERROR:  Sending failed: {e}")

Testing

To run this file locally for testing, fork & clone the repo, add .env.toml. Open the project repository in VS Code, open a PowerShell terminal and run

pytest
py dc_texter\texter.py

A Note on Organization

pip requires a folder/package to install.

Repository Name: text-alert

  • Uses dashes (-) as allowed in GitHub repository names.
  • Cannot be used as a Python package name due to dashes.
  • Has no effect on Python package imports.

Package (Folder) Name: dc_texter

  • Uses underscores (_) to ensure compatibility with Python imports.
  • Becomes an installable package when init.py file is added.

File Name: texter.py

  • The file name with a .py extension.
  • Can be executed as a script.
  • We avoid using the file name in imports if we set up init.py correctly.

pyproject.toml

  • [project] name = "dc_texter"`
  • Used for installation (pip install dc_texter).
  • The package folder should match.
[project]
name = "dc_texter" # install name

version = "0.1.0"

[tool.setuptools]
packages = ["dc_texter"] # list of package folders

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dc_texter-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dc_texter-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file dc_texter-0.1.1.tar.gz.

File metadata

  • Download URL: dc_texter-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for dc_texter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 30b70b8aa06d63d0e75774a5811f0d76b144c67f2e2e42d97b056585d4613374
MD5 65418d6336053b2fac7b5eceeb6423b5
BLAKE2b-256 4560ebc0c983380ab206f5e61580e3079c63c0769edba62736e7439c128b9da3

See more details on using hashes here.

File details

Details for the file dc_texter-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dc_texter-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for dc_texter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27887e6d86fee5e3e895e32c3fce8df265d9256fbd8eff17e2c1853dbc4dffd9
MD5 7757aa63d6547561f81858dd21f7b5ac
BLAKE2b-256 eb88f4d1bb4c14ebfdb6aa6da350092aada7825dc7287e307514ad9c6e39475e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page