Skip to main content

A Python Matrix client library, designed according to sans I/O principles.

Project description

nio

Build Status codecov license Documentation Status #nio

nio is a multilayered matrix client library. The underlying base layer doesn't do any IO on its own. On top of the base layer, a no-IO HTTP client implementation exists, as well as a full fledged batteries included asyncio layer using aiohttp.

Documentation

The full API documentation for nio can be found at https://matrix-nio.readthedocs.io

Installation

To install nio, simply use pip:

$ pip install matrix-nio

Note that this installs nio without end-to-end encryption support. For e2ee support, python-olm is needed which requires the libolm C library (version 3.x).

After libolm has been installed, the e2ee enabled version of nio can be installed using pip:

$ pip install "matrix-nio[e2e]"

Usage

Unless special requirements disallow the usage of asyncio, by far the easiest way to use nio is using the asyncio layer.

Please do note that these examples require python 3.5+ for the async/await syntax. nio on the other hand works with older python versions as well.

Sending a message

import asyncio
from nio import AsyncClient

async def main():
    client = AsyncClient("https://example.org", "@alice:example.org")

    await client.login("hunter1")
    await client.room_send(
        room_id="!test:example.org",
        message_type="m.room.message",
        content={
            "msgtype": "m.text",
            "body": "Hello World"
        }
    )
    await client.close()

asyncio.get_event_loop().run_until_complete(main())

Receiving messages

import asyncio
from nio import (AsyncClient, RoomMessageText)

async def message_cb(room, event):
    print(
        "Message received for room {} | {}: {}".format(
            room.display_name, room.user_name(event.sender), event.body
        )
    )

async def main():
    client = AsyncClient("https://example.org", "@alice:example.org")
    client.add_event_callback(message_cb, RoomMessageText)

    await client.login("hunter1")
    await client.sync_forever(timeout=30000)

asyncio.get_event_loop().run_until_complete(main())

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

matrix-nio-0.8.0.tar.gz (122.5 kB view details)

Uploaded Source

Built Distribution

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

matrix_nio-0.8.0-py3-none-any.whl (146.5 kB view details)

Uploaded Python 3

File details

Details for the file matrix-nio-0.8.0.tar.gz.

File metadata

  • Download URL: matrix-nio-0.8.0.tar.gz
  • Upload date:
  • Size: 122.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for matrix-nio-0.8.0.tar.gz
Algorithm Hash digest
SHA256 ab357e42a68a2fac7110040158be24c9562667f587c4061ee7ed93bb0c304624
MD5 993f3cc0a7d534eb8c1e6c7d0b0aa2d1
BLAKE2b-256 a5c4a53a587da9939f040b85c249cddd31ebf334beb746d794c6807c8ba96a2c

See more details on using hashes here.

File details

Details for the file matrix_nio-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: matrix_nio-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 146.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for matrix_nio-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7bb9d2c9b5b88726eab58198fc813fffeb43552ef4aee1e0a5be1e38654276b
MD5 74dff981e6d6a70cced0438db9cb714f
BLAKE2b-256 c3b29a240f674ab82aae34daf13abe84039c1797723c9586533119cad7e12680

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