⚠️ Layabout is deprecated. There will be no further support. ⚠️
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!")
To install Layabout use pip and PyPI:
pip install layabout
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.
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.
Everyone interacting with the Layabout project's codebase is expected to follow the Code of Conduct.