Skip to main content

A library that allows communication via the Signal IM service using the signald daemon.

Project description

pysignald

PyPI pipeline status

pysignald is a Python client for the excellent signald project, which in turn is a command-line client for the Signal messaging service.

pysignald allows you to programmatically send and receive messages to Signal.

Installation

You can install pysignald with pip:

$ pip install pysignald

Running

Just make sure you have signald installed. Here's an example of how to use pysignald:

from signald import Signal

s = Signal("+1234567890")

# If you haven't registered/verified signald, do that first:
s.register(voice=False)
s.verify("sms code")

s.send_message("+1098765432", "Hello there!")

for message in s.receive_messages():
    print(message)

You can also use the chat decorator interface:

from signald import Signal

s = Signal("+1234567890")

@s.chat_handler("hello there", order=10)  # This is case-insensitive.
def hello_there(message, match):
    # Returning `False` as the first argument will cause matching to continue
    # after this handler runs.
    stop = False
    reply = "Hello there!"
    return stop, reply


# Matching is case-insensitive. The `order` argument signifies when
# the handler will try to match (default is 100), and functions get sorted
# by order of declaration secondly.
@s.chat_handler("hello", order=10)
def hello(message, match):
    # This will match on "hello there" as well because of the "stop" return code in
    # the function above. Both replies will be sent.
    return "Hello!"


@s.chat_handler(re.compile("my name is (.*)"))  # This is case-sensitive.
def name(message, match):
    return "Hello %s." % match.group(1)


@s.chat_handler("")
def catch_all(message, match):
    # This will only be sent if nothing else matches, because matching
    # stops by default on the first function that matches.
    return "I don't know what you said."

s.run_chat()

Various

pysignald also supports different socket paths:

s = Signal("+1234567890", socket_path="/var/some/other/socket.sock")

It supports TCP sockets too, if you run a proxy. For example, you can proxy signald's UNIX socket over TCP with socat:

$ socat -d -d TCP4-LISTEN:15432,fork UNIX-CONNECT:/var/run/signald/signald.sock

Then in pysignald:

s = Signal("+1234567890", socket_path=("your.serveri.ip", 15432))

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

pysignald-0.0.7.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

pysignald-0.0.7-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pysignald-0.0.7.tar.gz.

File metadata

  • Download URL: pysignald-0.0.7.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5

File hashes

Hashes for pysignald-0.0.7.tar.gz
Algorithm Hash digest
SHA256 dc387be743c28b4d319dde6d2262dce06b3c030aa95c9c5acc12864cb6a8e977
MD5 8d228bd9e5d9970b75bb23de0b15361a
BLAKE2b-256 b6ba83af7723c345f13cd69843260823bc5ca714e9a77e23cb7b3f4b4b87237c

See more details on using hashes here.

File details

Details for the file pysignald-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: pysignald-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5

File hashes

Hashes for pysignald-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5318e431ae8beb1aacfaa4d38117c7bed0d7c3c0cb4dd0de326ad2519b1be984
MD5 93eb58f9d9dabec3f09063bcf0437275
BLAKE2b-256 2787e916c1d071c3b48ec85f26ba06acd5bbc0f86725443743dd90f313951b95

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