A Python API for Asanak
Project description
Asanak API
A Python client library for the Asanak SMS API. This package provides a simple and intuitive interface to interact with Asanak SMS services.
Installation
You can install the package via pip:
pip install asanak-api
Quick Start
from asanak_api import AsanakAPI
# Initialize the client
api = AsanakAPI(username="your_username", password="your_password")
# Or use the API key format (username,password)
# api = AsanakAPI(api_key="your_username,your_password")
# Send an SMS
response = api.sms_send({
"source": "your_source_number",
"destination": ["destination_number1", "destination_number2"],
"message": "Hello from Asanak API!"
})
print(response)
Authentication
Asanak SMS provider uses username and password for authentication. You can provide these credentials in two ways:
-
Separate username and password parameters:
api = AsanakAPI(username="your_username", password="your_password")
-
Combined API key:
api = AsanakAPI(api_key="your_username,your_password")
Available Methods
SMS Operations
-
Send SMS:
api.sms_send({ "source": "your_source_number", "destination":"recipient_number1,recipient_number2,...", "message": "Your message content" })
-
Send Template SMS:
api.sms_template({ "source": "your_source_number", "destination": "recipient_number1,recipient_number2,...", "message": "Your template name", "variables": {"var1": "value1", "var2": "value2"} })
-
Send Peer-to-Peer SMS:
api.sms_p2p( { { "source": "your_source_number", "destinations": "recipient_number1", "messages": "Message for recipient1" }, { "source": "your_source_number", "destinations": "recipient2", "messages": "Message for recipient2" } } )
-
Check SMS Status:
api.sms_status({"msgid": "your_message_id"})
Other Operations
-
Get Templates List:
api.sms_template_list()
-
Get Credit:
api.get_credit()
-
Get Rial Credit:
api.get_rial_credit()
Response Format
All API methods return responses in the following format:
{
"status": status_code, # Status code of the response
"message": "message", # Message describing the status
"data": {...} # Response data
}
Status Codes
The library includes predefined status codes that help you interpret API responses:
- SMS Status codes - Available in
SMS_STATUSdictionary - API Status codes - Available in
API_STATUSdictionary
Exception Handling
The library can raise the following exceptions:
APIException: For API-related errorsHTTPException: For HTTP connection issues
from asanak_api import AsanakAPI, APIException, HTTPException
try:
api = AsanakAPI(api_key="your_api_key")
response = api.sms_send({...})
except APIException as e:
print(f"API Error: {e}")
except HTTPException as e:
print(f"HTTP Error: {e}")
Requirements
- Python >= 3.12
- requests >= 2.32.3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asanak_api-0.1.1.tar.gz.
File metadata
- Download URL: asanak_api-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88a84030d93359ce77a24713ed1d0922d54c0b37bfe5837161908191fd5a2340
|
|
| MD5 |
c8c9fdb38a2f0abbe317572f783fb857
|
|
| BLAKE2b-256 |
178d64e8e26490b3161433acc8b6cc435fcab1689ff452f19b76374b528ead61
|
File details
Details for the file asanak_api-0.1.1-py3-none-any.whl.
File metadata
- Download URL: asanak_api-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
546aa86261375b6bbf579bf2b8c5c48b079b0f258f62f6d272155d088a72be03
|
|
| MD5 |
bd73fadc270c68338f14286fa963bb5d
|
|
| BLAKE2b-256 |
afdd13c6847000b1cb313904861a201d9f2da111d6a0eb677c7d39f969280d84
|