Skip to main content

Direct7 Python SDK

Python SDK to seamlessly incorporate communication features into your Python applications via the Direct7 REST API. This SDK empowers you to effortlessly initiate SMS,Whatsapp, Slack, Viber messages and 2 factor authentication features.

Documentation

The documentation for the Direct7 REST API can be found here Direct7 API Reference.

Installation

The SDK is available on PyPI and can be installed using pip:

pip install direct7

Usage

To get started you need to have an active Direct7 account, If you haven't yet registered, please proceed to Sign up

Authentication

In order to initiate API requests, create a client object using your Direct7 API token. To obtain an API token, kindly visit the following link: https://app.d7networks.com/api-tokens.

Examples

SMS

Send SMS

from direct7 import Client

client = Client(api_token="Your API token")

client.sms.send_messages(
        {"recipients": ["+9199XXXXXXXX"], "content": "Greetings from D7 API", "unicode": False},
        originator="Sender",
        report_url="https://the_url_to_receive_delivery_report.com",
        schedule_time='2024-02-05T09:48:42+0000',
        )

Send an Unicode SMS

from direct7 import Client

client = Client(api_token="Your API token")

client.sms.send_messages(
        {"recipients": ["+9199XXXXXXXX"],"content": "مرحبا بالعالم!", "unicode": True},
        originator="Sender",
        report_url="https://the_url_to_receive_delivery_report.com",
        )

Check SMS Request Status

from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_message
client.sms.get_status(request_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Verify

Send OTP

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.send_otp(originator="SignOTP", recipient="+97150900XXXX", content = "Greetings from D7 API, your mobile verification code is: {}", expiry = 600, data_coding = "text")

Re-Send OTP

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.resend_otp(otp_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Verify OTP

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.verify_otp(otp_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1", otp_code="1425")

Check Verify Request Status

from direct7 import Client

client = Client(api_token="Your API token")

# otp_id is the id returned in the response of send_otp
client.verify.get_status(otp_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Verify V2

Verify V2 is available under client.verify.v2. Existing client.verify calls continue to use V1.

Send OTP (V2)

V2 uses a verification flow created in the dashboard (channels, language and message are configured in the flow).

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.v2.send_otp(recipient="+97150900XXXX", flow_id="Your flow ID")

Re-Send OTP (V2)

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.v2.resend_otp(otp_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Verify OTP (V2)

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.v2.verify_otp(otp_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1", otp_code="1425")

Check Verify Request Status (V2)

from direct7 import Client

client = Client(api_token="Your API token")

client.verify.v2.get_status(otp_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Whatsapp

Send Whatsapp Free-form Message (Location Details)

from direct7 import Client

client = Client(api_token="Your API token")

client.whatsapp.send_whatsapp_freeform_message(originator="91906152XXXX",
                                               recipient="91906112XXXX",
                                                message_type="LOCATION", latitude="12.93803129081362",
                                                longitude="77.61088653615994",
                                                name="Mobile Pvt Ltd", address="30, Hosur Rd, 7th Block, Koramangala, Bengaluru, Karnataka 560095")

Send Whatsapp Templated Message.

from direct7 import Client

client = Client(api_token="Your API token")

client.whatsapp.send_whatsapp_templated_message(originator="91906152XXXX", recipient="91906112XXXX", template_id="monthly_promotion", language= "en", body_parameter_values={"0": "promotion"})

Send Whatsapp Interactive Message.

from direct7 import Client

client = Client(api_token="Your API token")

parameters = {
    "display_text": "Visit Alpha",
    "url": "https://www.luckyshrub.com?clickID=kqDGWd24Q5TRwoEQTICY7W1JKoXvaZOXWAS7h1P76s0R7Paec4"
}
    
response_send_messages = client.whatsapp.send_whatsapp_interactive_message(originator="+91906152XXXX",
                                                                           recipient="91906112XXXX",
                                                                           interactive_type="cta_url",
                                                                           header_type="text",
                                                                           header_text="Payment$ for D7 Whatsapp Service",
                                                                           body_text="Direct7 Networks is a messaging service provider that specializes in helping organizations efficiently communicate with their customers.",
                                                                           footer_text="Thank You",
                                                                           parameters=parameters)

Check Whatsapp Request Status

from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_message
client.whatsapp.get_status(request_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Whatsapp Read Receipt

from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_message
client.whatsapp.read_receipt(message_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Whatsapp User Initiated Media Download

from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_message
client.whatsapp.download_media(media_id="16554534343")

Number Lookup

Search Phone Number Details

from direct7 import Client

client = Client(api_token="Your API token")

client.number_lookup.search_number_details(recipient="+914257845XXXX")

Viber

Send Viber Message

from direct7 import Client

client = Client(api_token="Your API token")

client.viber.send_viber_message(recipients=["+97150900XXXX","+97845900XXX"], content="Greetings from D7 API", label="PROMOTION", originator="INFO2WAY", call_back_url="https://the_url_to_recieve_delivery_report.com")

Check Viber Request Status

from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_viber_message
client.viber.get_status(request_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

Slack

Send Slack Message

from direct7 import Client

client = Client(api_token="Your API token")

client.slack.send_slack_message(content="Greetings from D7 API", work_space_name="WorkspaceName", channel_name="ChannelName", report_url="https://the_url_to_recieve_delivery_report.com")

Check Slack Request Status

from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_slack_message
client.slack.get_status(request_id="0012c7f5-2ba5-49db-8901-4ee9be6dc8d1")

FAQ

How do I get my API token?

You can get your API token from the Direct7 dashboard. If you don't have an account yet, you can create one for free.

Supported Python versions

The SDK supports Python 3.6 and higher.

Supported APIs

As of now, the SDK supports the following APIs:

API Supported?
SMS API ✅
Verify API ✅
Whatsapp API ✅
Number Lookup API ✅
Viber API ✅
Slack API ✅

How do I get started?

You can find the platform documentation @ Direct7 Docs.

How do I get help?

If you need help using the SDK, you can create an issue on GitHub or email to support@d7networks.com

Contributing

We welcome contributions to the Direct7 Python SDK. If you have any ideas for improvements or bug fixes, please feel free to create an issue on GitHub.

Metadata

Release files for direct7 0.0.16

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

Source distribution (sdist)

Source distribution for direct7 0.0.16
File Size Uploaded Provenance Actions
direct7-0.0.16.tar.gz 14.5 kB Without provenance Details for direct7-0.0.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for direct7 0.0.16
File Interpreter ABI Platform Actions
direct7-0.0.16-py3-none-any.whl Python 3 none any Details for direct7-0.0.16-py3-none-any.whl

Total release size: 27.2 kB

Release files / direct7-0.0.16.tar.gz

Download URL direct7-0.0.16.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d0c22074d7341fa4627e4cef2c8a9bdede6e649f40cc8e616005919a9064677e
BLAKE2b-256 checksum
How to use checksums
c4fad6253f82c9fb0010ca48646d8f92dfab40d4dff2cf8be3b7f5f189289cb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / direct7-0.0.16-py3-none-any.whl

Download URL direct7-0.0.16-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fddeee7ef3687e94ff46992b2ac1c9fd926f9e4cdbe957fae581cbbf58f35eeb
BLAKE2b-256 checksum
How to use checksums
835f9ecdce5ab6e56c484bd5d9bca9c318ac4b7a8f9b14fad99f6319ad805be1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for direct7 0.0.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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