Skip to main content

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.

Metadata

Release files for deltachat2 2.58.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 deltachat2 2.58.0
File Size Uploaded
deltachat2-2.58.0.tar.gz 49.4 kB Details

Built distribution (wheel)

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

Total release size: 98.3 kB

Release files / deltachat2-2.58.0.tar.gz

Download URL deltachat2-2.58.0.tar.gz
Size 49.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4242b2db8c01db0c65abae51f971c767ccbd77d2fd7eda4084c591437b9f6a35
BLAKE2b-256 checksum
How to use checksums
e4b8dc58fe7b287de698f0f7516dd78436311d61ba38a499e27ad92e2b13b353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / deltachat2-2.58.0-py3-none-any.whl

Download URL deltachat2-2.58.0-py3-none-any.whl
Size 48.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52e630cf9cb0c727f61fa7b8412fa6b5e3666425dd6dca8eb49b4bb5bd35e085
BLAKE2b-256 checksum
How to use checksums
437290c739a27cc4b8d6ac06df73aeb01c8b2aa7299986896ce2afdd5ea31ca9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

2.58.0 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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