Skip to main content

A small event handling library on top of the Slack RTM API.

Project description

Unix build status on Travis CI Code coverage on Coveralls ISC Licensed Docs on Read the Docs Python Version Layabout on PyPI

Layabout is a small event handling library on top of the Slack RTM API.

from pprint import pprint
from layabout import Layabout

app = Layabout()


@app.handle('*')
def debug(slack, event):
    """ Pretty print every event seen by the app. """
    pprint(event)


@app.handle('message')
def echo(slack, event):
    """ Echo all messages seen by the app except our own. """
    if event.get('subtype') != 'bot_message':
        slack.rtm_send_message(event['channel'], event['text'])


def someone_leaves(events):
    """ Return False if a member leaves, otherwise True. """
    return not any(e.get('type') == 'member_left_channel'
                   for e in events)


if __name__ == '__main__':
    # Automatically load app token from $LAYABOUT_TOKEN and run!
    app.run(until=someone_leaves)
    print("Looks like someone left a channel!")

Installation

To install Layabout use pip and PyPI:

pip install layabout

What’s It Good For?

You can think of Layabout as a micro framework for building Slack bots. Since it wraps Slack’s RTM API it does best with tasks like interacting with users, responding to channel messages, and monitoring events. If you want more ideas on what you can do with it check out the examples.

Features

Not sold yet? Here’s a list of features to sweeten the deal.

  • Automatically load Slack API tokens from environment variables, provide them directly, or even bring your own SlackClient.

  • Register multiple event handlers for one event.

  • Register a single handler for multiple events by stacking decorators.

  • Configurable application shutdown.

  • Configurable retry logic in the event of lost connections.

  • Lightweight. Depends only on the official Python slackclient library.

Code of Conduct

Everyone interacting with the Layabout project’s codebase is expected to follow the Code of Conduct.

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

layabout-1.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

layabout-1.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file layabout-1.0.1.tar.gz.

File metadata

  • Download URL: layabout-1.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for layabout-1.0.1.tar.gz
Algorithm Hash digest
SHA256 eeab0ce909f6c2c5801ff9a4dba29f47a76edaa5036eb238f5c77b6f7bfd694e
MD5 0bb374be5b578c5c0c63986d4d35afff
BLAKE2b-256 684aadc840846463b7179579a7108b47f47dc59bc1ce6037515158d452a48ea9

See more details on using hashes here.

File details

Details for the file layabout-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: layabout-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for layabout-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02d4633ab9fab4265b3a4956c8777b247f4b6ca43bd4110d44d8364bb917900a
MD5 6d3f334726b6fd0e0bf9083e484ae13d
BLAKE2b-256 2a8757a92026c6b30012bcbc7ad56a1cc89f1ebb8f51f35ec680719c76cb9d9b

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