Skip to main content

aiothreema

Async Python client for the Threema Gateway HTTP API — send simple or end-to-end encrypted text messages from asyncio code.

This library implements the Gateway's HTTP wire protocol and NaCl-based end-to-end encryption directly (the official threema.gateway SDK is unmaintained), built on aiohttp and PyNaCl.

Install

pip install aiothreema

Usage

import asyncio

from aiothreema import ThreemaGatewayClient


async def main() -> None:
    async with ThreemaGatewayClient("*GATEWAY", "api-secret") as client:
        await client.validate_credentials()
        message_id = await client.send_text_message("ABCD1234", "Hello!")
        print(message_id)


asyncio.run(main())

End-to-end encryption

Pass a private key to send E2E-encrypted messages. The recipient's public key is looked up automatically via the Gateway's /pubkeys/{id} endpoint.

async with ThreemaGatewayClient(
    "*GATEWAY", "api-secret", private_key="<64-char hex>"
) as client:
    await client.send_text_message("ABCD1234", "Hello, encrypted!")

Generating a key pair

from aiothreema import generate_key_pair, derive_public_key

private_key, public_key = generate_key_pair()
# Register public_key with your Gateway account at gateway.threema.ch,
# then store private_key securely — it cannot be recovered.

assert derive_public_key(private_key) == public_key

Using an existing aiohttp.ClientSession

When embedding this client in a larger application (e.g. a long-lived service that already manages its own session pool), pass a session explicitly instead of using the context-manager form — the client will not close a session it doesn't own:

client = ThreemaGatewayClient("*GATEWAY", "api-secret", session=my_session)
await client.send_text_message("ABCD1234", "Hello!")

Errors

All errors inherit from ThreemaGatewayError:

  • ThreemaAuthError — the Gateway ID or API secret was rejected.
  • ThreemaConnectionError — a network/transport failure talking to the Gateway.
  • ThreemaSendError — sending a message, or resolving a recipient's public key, failed.

Development

pip install -e ".[test]"
pytest --cov=aiothreema

License

MIT

Metadata

Release files for aiothreema 0.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 aiothreema 0.1.0
File Size Uploaded
aiothreema-0.1.0.tar.gz 7.6 kB Details

Built distribution (wheel)

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

Total release size: 14.3 kB

Release files / aiothreema-0.1.0.tar.gz

Download URL aiothreema-0.1.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
431f31616b9cb5113c84aa1576680727ef26594f518b904cbf76864b59628e5b
BLAKE2b-256 checksum
How to use checksums
6074181b286f38606556def597a30ca4c39ec8f4edebaa3006458184cf104057
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / aiothreema-0.1.0-py3-none-any.whl

Download URL aiothreema-0.1.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f90ef3531cfeacdfcfd82037627269120f6c4ddac7da46b151d53a8f376fa24
BLAKE2b-256 checksum
How to use checksums
6adb72a937fd1bcaa3c0ad9ff131284517b4370157cf0eefa21106bcb2d5287f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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