Skip to main content

Basic network daemon library for nuqql

Project description

nuqql-based

nuqql-based is a basic network daemon library that implements the nuqql interface. It can be used as a dummy backend for nuqql, e.g., for testing or as a basis for the implementation of other nuqql backends.

Other backends using nuqql-based:

Dependencies:

  • daemon (optional): for daemonize support

Setup

You can install nuqql-based, for example, with pip for your user only with the following command:

$ pip install --user nuqql-based

If you prefer to check out this repository with git and work with the repository directly, you can install nuqql-based for your user in editable mode with the following command:

$ pip install --user -e .

Usage

Creating a nuqql backend with the nuqql-based library consists of the steps in the following boilerplate code:

from nuqql_based.based import Based
from nuqql_based.callback import Callback

# create a new backend
BACKEND_NAME = "myBackend"
BACKEND_VERSION = "0.1"
based = Based(BACKEND_NAME, BACKEND_VERSION)

# set callbacks
callbacks = [
    # based events
    (Callback.BASED_CONFIG, based_config),
    (Callback.BASED_INTERRUPT, based_interrupt),
    (Callback.BASED_QUIT, based_quit),

    # nuqql messages
    (Callback.QUIT, stop),
    (Callback.ADD_ACCOUNT, add_account),
    (Callback.DEL_ACCOUNT, del_account),
    (Callback.SEND_MESSAGE, send_message),
    (Callback.SET_STATUS, set_status),
    (Callback.GET_STATUS, get_status),
    (Callback.CHAT_LIST, chat_list),
    (Callback.CHAT_JOIN, chat_join),
    (Callback.CHAT_PART, chat_part),
    (Callback.CHAT_SEND, chat_send),
    (Callback.CHAT_USERS, chat_users),
    (Callback.CHAT_INVITE, chat_invite),
]
based.set_callbacks(callbacks)
based.start()

You can omit the callbacks you do not need in the callbacks list. In addition to the code above, you need to implement the callbacks you specify in your callbacks list.

The parameters passed to all callbacks are: the account, the callback and a callback-specific parameter tuple. The following example shows the send_message callback:

async def send_message(account, callback, params):
    """
    Send a message to another user.
    """

    dest, msg = params
    # do something with the message...

    return ""

The callbacks are only used for commands coming from nuqql. You must handle backend-specific events like receiving messages from other users in your backend code and optionally pass them to nuqql-based. The following example shows how incoming messages from other users can be passed to nuqql-based with Message.message() and receive_msg():

from nuqql_based.message import Message

def receive(account, timestamp, sender, destination, text):
    """
    Receive message from other user.
    """

    msg = Message.message(account, timestamp, sender, destination, text)
    account.receive_msg(msg)

Changes

  • v0.3.0:
    • Switch to asyncio and increase required Python version to >= 3.7
    • Remove copy of the buddy list from Account and rename callback UPDATE_BUDDIES to GET_BUDDIES to match new behaviour
    • Add callbacks:
      • HELP_WELCOME: welcome/help message for clients
      • HELP_ACCOUNT_ADD: help text for adding accounts
    • Add configuration option for filtering own messages
  • v0.2.0:
    • Use only one log file
    • Add "push-accounts" to configuration/command line arguments
    • Add more info messages and extend output of "help" command
    • Change callback parameter from account id to Account
    • Add tests
    • Cleanups and fixes
  • v0.1:
    • First release.

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

nuqql-based-0.3.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

nuqql_based-0.3.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file nuqql-based-0.3.0.tar.gz.

File metadata

  • Download URL: nuqql-based-0.3.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for nuqql-based-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1c26794b5f172dfd29f1b8d55fd6e35d5b5df001fb2fc05164c228f96a1001ef
MD5 a97edb50ac53b4ed84652864aa297f5e
BLAKE2b-256 db978f0c60b9f5c76ebbfa973ce200c05382d8616a8573a5db6626b9cdd93369

See more details on using hashes here.

File details

Details for the file nuqql_based-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nuqql_based-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for nuqql_based-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffe36e16d8a1373a1379b865f83fe48cfb9f32a5f70056ae6ca247c94b43d6f0
MD5 2a57e5fe47a48b07e1a25ea34c8e5a00
BLAKE2b-256 b0070fc3b07d336b10b4bd735825dd82626c380802f60d3ce7074e27035e2286

See more details on using hashes here.

Supported by

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