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 a the libolm C library.

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:

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())

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

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.4.tar.gz (191.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: matrix-nio-0.4.tar.gz
  • Upload date:
  • Size: 191.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for matrix-nio-0.4.tar.gz
Algorithm Hash digest
SHA256 9efb22150cddc713b3b3e17ef6bc0693eb64fef64ede2337c834f4b2aa89badb
MD5 402afcdb0f2a2c66dccf535d30a0ec85
BLAKE2b-256 8d181de2ae10acd7d603cb404cdb80476c30d3e82b88b46b3054bfa0c04d0705

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