Skip to main content

Client library for Delta Chat core JSON-RPC interface

Project description

Delta Chat client library for Python

Latest Release CI Code style: black

Client library for Delta Chat core JSON-RPC interface

Install

pip install deltachat2

To use this library, you need to have deltachat-rpc-server program installed, you can install it together with this library with:

pip install 'deltachat2[full]'

Usage

Example echo-bot written with deltachat2:

from deltachat2 import (
    Bot,
    EventType,
    IOTransport,
    MessageData,
    NewMsgEvent,
    Rpc,
    events,
)

hooks = events.HookCollection()


@hooks.on(events.RawEvent)
def log_event(_bot: Bot, _accid: int, event: EventType) -> None:
    """Log all core events for debugging."""
    print(event)


@hooks.on(events.NewMessage)
def echo(bot: Bot, accid: int, event: NewMsgEvent) -> None:
    """Echo back any text message"""
    msg = event.msg
    bot.rpc.send_msg(accid, msg.chat_id, MessageData(text=msg.text))


if __name__ == "__main__":
    with IOTransport() as trans:
        rpc = Rpc(trans)
        bot = Bot(rpc, hooks)

        accounts = rpc.get_all_account_ids()
        accid = accounts[0] if accounts else rpc.add_account()

        if not rpc.is_configured(accid):
            rpc.set_config(accid, "bot", "1")
            rpc.add_transport_from_qr(accid, "dcaccount:nine.testrun.org")

        link = rpc.get_chat_securejoin_qr_code(accid, None)
        print(f"Listening at: {link}")
        bot.run_forever()

Save the above code in a echobot.py file and run it with Python:

python echobot.py

Then write to the bot using the invite link that will be printed in the screen.

Developing bots faster ⚡

If you want to develop bots, you probably should use this library together with deltabot-cli-py, it takes away the repetitive process of creating the bot CLI and let you focus on writing your message processing logic.

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

deltachat2-1.0.3.tar.gz (49.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deltachat2-1.0.3-py3-none-any.whl (49.1 kB view details)

Uploaded Python 3

File details

Details for the file deltachat2-1.0.3.tar.gz.

File metadata

  • Download URL: deltachat2-1.0.3.tar.gz
  • Upload date:
  • Size: 49.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for deltachat2-1.0.3.tar.gz
Algorithm Hash digest
SHA256 585edac2bd955af8d0ad65c05af98ce412841a58bfef6ff1ca77df0d02f56c2b
MD5 e18c32cd2d5c05fab764e3bd2d437669
BLAKE2b-256 99c866893d367fee5b41b3f74d2ebc7a224019038efd1fae31acbc4a9a63e09c

See more details on using hashes here.

File details

Details for the file deltachat2-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: deltachat2-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 49.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for deltachat2-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9ad9e85e374028063a3db79fe24dfbd9310bf17c36d04363ff74f4f4c07a49ce
MD5 0029e7fa10bcd09bad076467b5a59a44
BLAKE2b-256 6f04bd73b23dd95339424a91e3dc1db7c3f176e728ecd3736ff8a94e711a265f

See more details on using hashes here.

Supported by

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