Skip to main content

A Python package to send SMS via multiple Iranian providers

Project description

IranSMS

A Python package to send SMS via multiple Iranian providers (Kavenegar, DnsPanel, IPPanel). Easily integrated with Django.


Table of Contents

  1. Installation
  2. Configuration
  3. Usage
  4. Providers
  5. Testing
  6. Contributing
  7. License

Installation

Install the package using pip:

pip install iransms

Configuration

Add the IRANSMS_CONFIG dictionary to your Django settings.py file to configure the SMS provider and credentials.

Example Configuration

settings.py

IRANSMS_CONFIG = {
    "provider": "kavenegar",  # or "dnspanel" or "ippanel"
    "kavenegar_api_key": "your_api_key",
    "kavenegar_from_number": "your_from_number",
    "dnspanel_username": "your_username",
    "dnspanel_password": "your_password",
    "dnspanel_from_number": "your_from_number",
    "ippanel_api_key": "your_api_key",
    "ippanel_from_number": "your_from_number",
}

Usage

Sending an SMS

You can send an SMS using the SMSSender class.

from iransms import SMSSender

sender = SMSSender()
result = sender.send_sms(to_number="9876543210", message="Hello from IranSMS!")

if result["success"]:
    print(f"SMS sent successfully via {result['provider']}")
else:
    print(f"Failed to send SMS via {result['provider']}: {result['message']}")

Using in Django

Example: Sending an SMS in a Django View

# views.py

from django.http import JsonResponse
from iransms import SMSSender

def send_sms_view(request):
    sender = SMSSender()
    result = sender.send_sms(to_number="9876543210", message="Hello from Django!")

    if result["success"]:
        return JsonResponse({"status": "SMS sent successfully!"})
    else:
        return JsonResponse({"status": f"Failed to send SMS: {result['message']}"}, status=500)

Example: Sending an SMS in a Django Model

# models.py

from django.db import models
from iransms import SMSSender

class Order(models.Model):
    customer_phone = models.CharField(max_length=15)
    status = models.CharField(max_length=50)

    def send_status_update(self):
        sender = SMSSender()
        message = f"Your order status is now {self.status}."
        result = sender.send_sms(to_number=self.customer_phone, message=message)
        return result["success"]

Using in Celery Tasks

If you’re using Celery for background tasks, you can send SMS asynchronously.

# tasks.py

from celery import shared_task
from iransms import SMSSender

@shared_task
def send_sms_async(to_number, message):
    sender = SMSSender()
    result = sender.send_sms(to_number=to_number, message=message)
    return result

Providers

Kavenegar

DnsPanel

IPPanel

Testing

To run the unit tests, navigate to the project directory and ru

python -m unittest discover tests

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeatureName).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeatureName).
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.

Enjoy using IranSMS! 🚀

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

iransms-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

iransms-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iransms-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.8

File hashes

Hashes for iransms-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a1bfc20cc7d0a72429629943bb41882bae73104efa8897ce0f649222ee5ab5e9
MD5 4cc856e00cdde703dad712aea29d3376
BLAKE2b-256 bdf749c33a5e036d3bfd8a8d12893b3a30b7a182558d2271a69903c25d64bb8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iransms-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.8

File hashes

Hashes for iransms-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e66c076effb4666f948297ab7d5e7eb42214744609e605396846dfa0d1ba40c4
MD5 ff97fb7bc8c9feb4571b2225476e28e5
BLAKE2b-256 f93d4adb745f78b76e1b7bafaf8d435a5ab9658165f5e650217727303f37cc0e

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