aiosignald


Nameaiosignald JSON
Version 0.3.3 PyPI version JSON
download
home_pagehttps://git.sr.ht/~nicoco/aiosignald
SummaryPython bindings for signald
upload_time2022-09-23 06:49:04
maintainer
docs_urlNone
authorNicolas Cedilnik
requires_python>=3.8,<4
licenseAGPL-3.0-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Signald python bindings
=======================


[![pypi](https://badge.fury.io/py/aiosignald.svg)](https://pypi.org/project/aiosignald/)
[![Documentation Status](https://readthedocs.org/projects/aiosignald/badge/?version=latest)](https://aiosignald.readthedocs.io/en/latest/)
[![builds.sr.ht status](https://builds.sr.ht/~nicoco/aiosignald/commits/master/.build.yml.svg)](https://builds.sr.ht/~nicoco/aiosignald/commits/master/.build.yml?)

Interact with the signal messaging network in python with sweet, sweet autocompletion.

Most of the code is generated by the `generate.py` script that
uses the schema available at <https://signald.org/protocol.json>.

No 3rd party dep, just the python standard lib.

Install
-------

`pip install aiosignald`

Have signald running. See [their
docs](https://signald.org/articles/install/) about it.

Issue tracker: https://todo.sr.ht/~nicoco/aiosignald

Part of the [slidge project](https://sr.ht/~nicoco/slidge) (but can be used independently)

Usage
-----

### Example: echo bot

```py
import asyncio

from aiosignald import SignaldAPI
import aiosignald.generated as api

class EchoBot(SignaldAPI):
    async def handle_IncomingMessage(self, msg: api.IncomingMessagev1, _payload):
        # hook to the incoming event by naming you function handle_EventName
        # most stuff comes through an IncomingMessage anyway
        print("Received: ", msg)
        if (data_msg := msg.data_message) and (body := data_msg.body):
            await self.send(
                username=PHONE_NUMBER,
                recipientAddress=msg.source,
                messageBody=body
            )

async def main():
    loop = asyncio.get_running_loop()
    _, signald = await loop.create_unix_connection(
        EchoBot, path=SIGNALD_SOCKET_PATH)
    if ACCOUNT_TYPE == "primary":
        await signald.register(account=PHONE_NUMBER)
        # Some async code to get the SMS code
        code = await user_input("Enter your sms code?")
        await signald.verify(account=PHONE_NUMBER, code=code)
    else:
        # linking to an existing account is also possible
        resp = await signald.generate_linking_uri()
        print("Make this a QR code and scan it on your primary signal device:", resp.uri)
        await signald.finish_link(device_name="friendly-device-name", session_id=resp.session_id)
    await signald.on_con_lost

# See https://signald.org/articles/protocol/ for more info about this
SIGNALD_SOCKET_PATH = "/var/run/signald/signald.sock"
PHONE_NUMBER = "+XXXXXX"
ACCOUNT_TYPE = "primary"

asyncio.run(main())
```

Docs are available on [readthedocs](https://aiosignald.readthedocs.org).

            

Raw data

            {
    "_id": null,
    "home_page": "https://git.sr.ht/~nicoco/aiosignald",
    "name": "aiosignald",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4",
    "maintainer_email": "",
    "keywords": "",
    "author": "Nicolas Cedilnik",
    "author_email": "nicoco@nicoco.fr",
    "download_url": "https://files.pythonhosted.org/packages/42/72/e7218c2902cdd0d38746a39a981e13ea5e031b22a1c2c959f57fe3f58dc2/aiosignald-0.3.3.tar.gz",
    "platform": null,
    "description": "Signald python bindings\n=======================\n\n\n[![pypi](https://badge.fury.io/py/aiosignald.svg)](https://pypi.org/project/aiosignald/)\n[![Documentation Status](https://readthedocs.org/projects/aiosignald/badge/?version=latest)](https://aiosignald.readthedocs.io/en/latest/)\n[![builds.sr.ht status](https://builds.sr.ht/~nicoco/aiosignald/commits/master/.build.yml.svg)](https://builds.sr.ht/~nicoco/aiosignald/commits/master/.build.yml?)\n\nInteract with the signal messaging network in python with sweet, sweet autocompletion.\n\nMost of the code is generated by the `generate.py` script that\nuses the schema available at <https://signald.org/protocol.json>.\n\nNo 3rd party dep, just the python standard lib.\n\nInstall\n-------\n\n`pip install aiosignald`\n\nHave signald running. See [their\ndocs](https://signald.org/articles/install/) about it.\n\nIssue tracker: https://todo.sr.ht/~nicoco/aiosignald\n\nPart of the [slidge project](https://sr.ht/~nicoco/slidge) (but can be used independently)\n\nUsage\n-----\n\n### Example: echo bot\n\n```py\nimport asyncio\n\nfrom aiosignald import SignaldAPI\nimport aiosignald.generated as api\n\nclass EchoBot(SignaldAPI):\n    async def handle_IncomingMessage(self, msg: api.IncomingMessagev1, _payload):\n        # hook to the incoming event by naming you function handle_EventName\n        # most stuff comes through an IncomingMessage anyway\n        print(\"Received: \", msg)\n        if (data_msg := msg.data_message) and (body := data_msg.body):\n            await self.send(\n                username=PHONE_NUMBER,\n                recipientAddress=msg.source,\n                messageBody=body\n            )\n\nasync def main():\n    loop = asyncio.get_running_loop()\n    _, signald = await loop.create_unix_connection(\n        EchoBot, path=SIGNALD_SOCKET_PATH)\n    if ACCOUNT_TYPE == \"primary\":\n        await signald.register(account=PHONE_NUMBER)\n        # Some async code to get the SMS code\n        code = await user_input(\"Enter your sms code?\")\n        await signald.verify(account=PHONE_NUMBER, code=code)\n    else:\n        # linking to an existing account is also possible\n        resp = await signald.generate_linking_uri()\n        print(\"Make this a QR code and scan it on your primary signal device:\", resp.uri)\n        await signald.finish_link(device_name=\"friendly-device-name\", session_id=resp.session_id)\n    await signald.on_con_lost\n\n# See https://signald.org/articles/protocol/ for more info about this\nSIGNALD_SOCKET_PATH = \"/var/run/signald/signald.sock\"\nPHONE_NUMBER = \"+XXXXXX\"\nACCOUNT_TYPE = \"primary\"\n\nasyncio.run(main())\n```\n\nDocs are available on [readthedocs](https://aiosignald.readthedocs.org).\n",
    "bugtrack_url": null,
    "license": "AGPL-3.0-or-later",
    "summary": "Python bindings for signald",
    "version": "0.3.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "542e858fa765474f33fa27446f8bb588",
                "sha256": "a6b585174e9d13004f453991bb10fea2f6b3ff5375f2f4b0b32e0298c405390a"
            },
            "downloads": -1,
            "filename": "aiosignald-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "542e858fa765474f33fa27446f8bb588",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4",
            "size": 30830,
            "upload_time": "2022-09-23T06:49:03",
            "upload_time_iso_8601": "2022-09-23T06:49:03.151592Z",
            "url": "https://files.pythonhosted.org/packages/78/b9/e0063daddfb7314092d9b2f533b0618c530b7331a51f776d578f8c29af3b/aiosignald-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "f05c3f42137ea07628bfcf1d19e354a8",
                "sha256": "35ec5be5021b887d4925fd38da965c89ff0acbb2cd10d1eec88c749c7977231c"
            },
            "downloads": -1,
            "filename": "aiosignald-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f05c3f42137ea07628bfcf1d19e354a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4",
            "size": 30743,
            "upload_time": "2022-09-23T06:49:04",
            "upload_time_iso_8601": "2022-09-23T06:49:04.535721Z",
            "url": "https://files.pythonhosted.org/packages/42/72/e7218c2902cdd0d38746a39a981e13ea5e031b22a1c2c959f57fe3f58dc2/aiosignald-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-23 06:49:04",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "aiosignald"
}
        
Elapsed time: 0.43785s