Skip to main content

A Python wrapper for TextNow.

Project description



pythontextnow logo

Send SMS messages from Python!
A Python wrapper for TextNow.

TextNow Website

PyPi Version
Main Build Last Commit

Table of Contents

Installation

Use the package manager pip to install.

pip install pythontextnow

Usage

Make sure you have the following before you begin:

  • TextNow username
  • SID cookie

For a guide on how to obtain these for your account, check here.

Configure Client

Before you can call any methods, you must first set up your client config.

from pythontextnow import Client

USERNAME = "{your_username}"
SID_COOKIE = "{your_sid_cookie}"

Client.set_client_config(username=USERNAME, sid_cookie=SID_COOKIE)

The ConversationService is how you will perform any action.

It takes a list of phone numbers which define the conversation you would like to perform your actions on.

All phone numbers must be given in E.164 format.

from pythontextnow import ConversationService

PHONE_NUMBER_1 = "{some_phone_number}"
PHONE_NUMBER_2 = "{some_other_phone_number}"
conversation_service = ConversationService(conversation_phone_numbers=[PHONE_NUMBER_1, PHONE_NUMBER_2])

Get Messages

The get_messages() method will return a generator object.

This will return the messages from most -> least recent.

You can call next() with the returned generator each time you want to get the next group of messages.

messages_generator = conversation_service.get_messages()

messages = next(messages_generator)

You can also use a for loop to get all messages in a conversation.

messages_generator = conversation_service.get_messages()

all_messages = list()
for message_list in messages_generator:
    all_messages += message_list

You can specify how many messages back you would like to be retrieved by using the num_messages keyword argument.

messages_generator = conversation_service.get_messages(num_messages=10)

last_10_messages = list()
for message_list in messages_generator:
    last_10_messages += message_list

Send a Message

To send a text message, use the send_message() method.

conversation_service.send_message(message="Hello World!")

Send Media

To send media, use the send_media() method.

You can send:

  • Images
  • Videos
  • GIFs
conversation_service.send_message(file_path="C:\\my_media.png")

Mark a Message as Read

To mark a message as read, use the mark_as_read() method.

Mark a single message as read.

# assume you had a Message object saved to the variable "message_obj"

conversation_service.mark_as_read(message=message_obj)

Mark a list of messages as read.

# assume you had a list of Message objects saved to the variable "message_list"

conversation_service.mark_as_read(messages=message_list)

Delete a Message

To delete a message, use the delete_message() method.

Delete a message by its ID.

conversation_service.delete_message(message_id="123456")

Delete a message with its Message object.

# assume you had a Message object saved to the variable "message_obj"

conversation_service.delete_message(message=message_obj)

Delete a Conversation

To delete a conversation, use the delete_conversation() method.

conversation_service.delete_conversation()

Setup

Obtaining Your Username

You will need to know your TextNow username to utilize this library.

This is the same username that you would use to log in.

To find this username:

  • Go to TextNow's messaging page (make sure you are logged in)
  • Click "Settings"
  • Your username will be listed under "Account"

Obtaining Your Cookie

You will need an SID cookie to utilize this library.

To find this cookie:

In Chrome:

  • Access Developer Tools in your browser
  • Click on the "Application" tab
  • Click on the "Network" tab
  • Find a request under "Fetch/XHR"
  • Go to the "Headers" tab in the given request
  • Find the "Request Headers" section
  • Locate the "Cookie" field

In Firefox

  • Access Developer Tools in your browser
  • Click on the "Network" tab
  • Find a request under "XHR"
  • Go to the "Headers" tab in the given request
  • Find the "Request Headers" section
  • Locate the "Cookie" field
  • Locate the "connect.sid" field, the value will be your SID cookie

Running Tests

To run tests, run the following command:

  pytest

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

pythontextnow-1.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

pythontextnow-1.1.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file pythontextnow-1.1.0.tar.gz.

File metadata

  • Download URL: pythontextnow-1.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for pythontextnow-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1557a7db0dadfef49c2fcdacb92a4f33f5de7ffa61845e86d824c6cc8beace3d
MD5 c35294d7f1a13f5ed7d9a41bed4f54d1
BLAKE2b-256 2c79ed74a79ddb7a7ee84d3f442530f66def37e85f116a34ace0176fa5da2657

See more details on using hashes here.

File details

Details for the file pythontextnow-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pythontextnow-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4b0e0d9da0f1e9ec044d4c3070aa67071be90625d1c833297e012c28f3abc8
MD5 e082c8e1d5599e36c7b55d01886d921b
BLAKE2b-256 f627ec268b18dbbb14100fc6f646433c6bb38328c01706a56b17f919a53ce3f3

See more details on using hashes here.

Supported by

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