Skip to main content

Python client for SGC (SMS Gateway Center) API. Send SMS, manage account, sender IDs, schedules. Works with Unify SMS Gateway Center.

Project description

SGC Python SDK

Python client for the SGC (SMS Gateway Center) API. Send SMS, manage account, sender IDs, schedules, contacts, groups, and more. Works with Unify SMS Gateway Center.

Requirements: Python 3.7+, requests>=2.28.0


Prerequisites: Get Your API Credentials

You must have a registered account and API credentials from Unify SMS Gateway Center before using this SDK.

  1. Register or log in at https://unify.smsgateway.center.
  2. After login, get your API credentials from your account/settings (username, password, and API key).
  3. Create or use an existing Sender ID for sending SMS (required for the send API).

Without valid credentials from Unify, all API calls will return authentication errors (e.g. invalid credentials).


Installation

From PyPI

pip install sgc-python-sdk

From GitHub

pip install git+https://github.com/smsgatewaycenter/sgc_python_sdk.git

Local / development

cd /path/to/parent-of-sgc_python_sdk
pip install -r sgc_python_sdk/requirements.txt

To use the package from your code, set PYTHONPATH to the parent directory of sgc_python_sdk:

export PYTHONPATH=/path/to/parent-of-sgc_python_sdk
python -c "from sgc_python_sdk import sgc_auth, sgc_account; print('OK')"

Configuration

Set these environment variables with your Unify credentials:

Variable Required Description
SGC_API_BASE No API base URL. Default: https://unify.smsgateway.center
SGC_USER Yes Your Unify username
SGC_PASS Yes Your Unify password
SGC_APIKEY Yes Your API key from Unify

Optional (for sending SMS and debugging):

Variable Description
SGC_SMS_PHONE Recipient number for the test script (e.g. 919876543210)
SGC_SMS_SENDER Your Sender ID for the test script (e.g. SMSGAT)
SGC_SMS_TEXT Message text (default: Test from SGC Python SDK)
SGC_SMS_TEST Set to true for test mode (no real delivery when supported)
SGC_DEBUG Set to 1 to print full request URL and parameters (sensitive values masked)
SGC_USE_INDEX_PHP Set to 1 if Send SMS returns 404 (uses index.php?url=... style URL)

How to Test

After installing and setting your credentials, run the included test script to verify account, profile, sender IDs, schedule, and (optionally) send SMS.

  1. Set your Unify credentials and API base:

    export SGC_API_BASE="https://unify.smsgateway.center"
    export SGC_USER="your_unify_username"
    export SGC_PASS="your_unify_password"
    export SGC_APIKEY="your_api_key_from_unify"
    
  2. Run the test script:

    • If you installed via pip (PyPI or GitHub):
      python -m sgc_python_sdk.test_sdk
      
      Or from the repo root:
      python sgc_python_sdk/test_sdk.py
      
    • If using locally with PYTHONPATH:
      export PYTHONPATH=/path/to/parent-of-sgc_python_sdk
      python sgc_python_sdk/test_sdk.py
      
  3. What the test does:

    • 1) Account ReadAccountStatus – checks your account status.
    • 2) Account ReadProfile – fetches your profile.
    • 3) SenderId Read – lists your sender IDs.
    • 4) Schedule Read – lists scheduled messages.
    • 5) Send SMS (batch) – only runs if you set SGC_SMS_PHONE and SGC_SMS_SENDER (see below).
  4. To test sending an SMS, set the recipient and a valid Sender ID from your account:

    export SGC_SMS_PHONE="919876543210"
    export SGC_SMS_SENDER="YourSenderId"
    python sgc_python_sdk/test_sdk.py
    

    Use SGC_SMS_TEST=true for test mode (no real delivery when the API supports it). Use SGC_DEBUG=1 to see the full request URL and parameters.

If you see invalid credentials (216), double-check your username, password, and API key from Unify SMS Gateway Center.


Quick Start: Use in Your Code

from sgc_python_sdk import sgc_auth, sgc_user, sgc_account, sgc_senderid, sgc_sms, sgc_sms_send

# Use your Unify credentials
auth = sgc_auth()
auth.setUsername("your_unify_username")
auth.setPassword("your_unify_password")
auth.setApiKey("your_api_key_from_unify")

# Account status
user = sgc_user("json")
acc = sgc_account(auth, user)
print(acc.ReadAccountStatus())

# Send SMS (batch)
sms = sgc_sms("json")
sms.setSenderId("YourSenderId")   # Must exist in your Unify account
sms.setText("Hello from SDK")
sms.setPhone("919876543210")
sms.setMsgType("text")
sms.setTestMessage("false")       # "true" for test mode
sms.setDuplicateCheck("true")
sender = sgc_sms_send(auth, sms)
print(sender.batch())

You can also use environment variables and leave credentials out of code:

import os
from sgc_python_sdk import sgc_auth, sgc_user, sgc_account

auth = sgc_auth()
auth.setUsername(os.environ.get("SGC_USER", ""))
auth.setPassword(os.environ.get("SGC_PASS", ""))
auth.setApiKey(os.environ.get("SGC_APIKEY", ""))

user = sgc_user("json")
acc = sgc_account(auth, user)
print(acc.ReadAccountStatus())

API Overview

Area Class / module Main actions
Account sgc_account ReadAccountStatus, ReadProfile, etc.
Sender ID sgc_senderid Read, Create, Update, Delete
Schedule sgc_schedule Read, Update, Delete
Send SMS sgc_sms_send batch(), phonebook(), file()
API Key sgc_apikey Create, Read, Update, Delete
Contact sgc_contact CRUD
Group sgc_group CRUD
Password sgc_password Change
Reseller sgc_reseller_user_api, sgc_credit_management User and credit management

Boolean parameters such as testMessage and duplicateCheck must be "true" or "false"; the SDK normalizes them for you.


Troubleshooting

  • Invalid credentials (216)
    Ensure you are using the correct username, password, and API key from https://unify.smsgateway.center.

  • Send SMS returns 404
    Set SGC_USE_INDEX_PHP=1 so the client uses the index.php?url=... style URL.

  • Parameter testMessage / duplicateCheck error (147)
    The SDK sends "true" or "false" automatically; ensure you are on a recent SDK version.

  • See exact request URL and parameters
    Set SGC_DEBUG=1 and run your script again; the full URL and body params will be printed (sensitive values masked).


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

sgc_python_sdk-1.0.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

sgc_python_sdk-1.0.1-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file sgc_python_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: sgc_python_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.1

File hashes

Hashes for sgc_python_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d57a79a78cb12053d26bceb36ca86111f4db58e069f6033b6a4c6045e171f234
MD5 a77847e07be9818db13a5f3cf070a552
BLAKE2b-256 49387e7959d90cc8205cb5ad12710497218ad0fefec8247f72d8d37d823dcb59

See more details on using hashes here.

File details

Details for the file sgc_python_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sgc_python_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.1

File hashes

Hashes for sgc_python_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec44ad7e432cebced078762d1884d649de5a93fb2219095c5d1b612878ddb333
MD5 39fc4f9a0240bd6bede54f81c91a5e9f
BLAKE2b-256 300d889bbd1ad33bac2b3d20ac678a2395d1a1948f8bec313dbe93752a03e791

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