Skip to main content


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

Release files for pythontextnow 1.1.0

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

Source distribution (sdist)

Source distribution for pythontextnow 1.1.0
File Size Uploaded
pythontextnow-1.1.0.tar.gz 18.5 kB Details

Built distribution (wheel)

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

Total release size: 41.5 kB

Release files / pythontextnow-1.1.0.tar.gz

Download URL pythontextnow-1.1.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1557a7db0dadfef49c2fcdacb92a4f33f5de7ffa61845e86d824c6cc8beace3d
BLAKE2b-256 checksum
How to use checksums
2c79ed74a79ddb7a7ee84d3f442530f66def37e85f116a34ace0176fa5da2657
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Release files / pythontextnow-1.1.0-py3-none-any.whl

Download URL pythontextnow-1.1.0-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f4b0e0d9da0f1e9ec044d4c3070aa67071be90625d1c833297e012c28f3abc8
BLAKE2b-256 checksum
How to use checksums
f627ec268b18dbbb14100fc6f646433c6bb38328c01706a56b17f919a53ce3f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

1 release file

1.0.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

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