Welcome to libslack’s documentation!¶
libslack¶
Overview¶
libslack is a lightweight python wrapper around the Slack-Web-Api. As part of libslack a small tool called scmd.py which provides a command line interface for the slack api.
Requirements¶
- Python 3.4 and newer
Tools¶
Slack CMD (scmd)¶
The Slack CMD enables its user to use the slack web api via the command line.
Usage¶
Usage:
scmd (API_COMMAND | -h | -v ) [<params>] [--auth-token=<token>]
Options:
-h Show this screen.
-v Show version.
--auth-token=<token> The authentication token which will be used to access
the slack api.
As an alternative you can specify it in the .slackrc
or set the $SLACK_API_TOKEN environment variable.
Example¶
Call auth.test method¶
User@Host ~ $ scmd auth.test --auth-token xoxb-xxxxxxxxxx-yyyyyyyyyyyyyyyyyyyyyyyy
{'user_id': 'UXXXXXXXX', 'url': 'https://teamname.slack.com/', 'team': 'Teamname', 'user': 'username', 'team_id': 'TXXXXXXXX', 'ok': True}
Send a chat message using the web api¶
User@Host ~ $ scmd chat.postMessage "{'channel': 'CXXXXXXXX', 'text': 'this is a message send fd from the command line ;)'}" --auth-token="xoxp-xxxxxxxxxx-yyyyyyyyyy-xxxxxxxxxx-yyyyyy"
{'ok': True, 'message': {'username': 'bot', 'subtype': 'bot_message', 'ts': '1445633421.000121', 'text': 'this is a message send fd from the command line ;)', 'type': 'message'}, 'ts': '1445633421.000121', 'channel': 'CXXXXXXXX'}
Slack Shell (sls)¶
The Slack Shell provides an interactive shell which enables the user to interactively interact with the slack web api (e.g. query all registered users).
Usage¶
Usage:
sls [--auth-token=<token>]
sls -h | --help
sls -v | --version
Options:
-h --help Show this screen.
-v --version Show version.
--auth-token=<token> The authentication token which will be used to access
the slack api.
As an alternative you can specify it in the .slackyrc
or set the $SLACK_API_TOKEN environment variable.
Screenshot¶

API-Reference¶
-
class
libslack.slackapi.
SlackApi
(authentication_token, request=None)[source]¶ A SlackApi object can be used to interact with the slack api.
For futher details see methods.
-
call
(api_call, parameters=None)[source]¶ Executes a call on the remote slack api and returns an appropriate
SlackApiResponse
object.Parameters: - api_call (string) – which identifies the web api endpoint which shall be called.
- parameters (dict) –
which will be supplied to the web api endpoint.
e.g.:
{'channel': 'C1234567890', 'text': 'this message will be sent'}
Attention
The authentication-token allways will be passed to the endpoint implicitly.
Returns: an ApiResponse object containing the data provided by the slackapi endpoint.
Raise: Exception if an unknown api method is called.
-
-
class
libslack.slackapi.
SlackApiRequest
(api_call, authentication_token)[source]¶ The SlackApiRequest class handles and encapsulates a slack request.
-
execute
(request_parameters=None)[source]¶ Executes an ApiRequest, request an api call.
Parameters: - request_parameters (dict) –
which will be supplied to the web api endpoint.
e.g.:
{'channel': 'C1234567890', 'text': 'this message will be sent'}
Attention
The authentication-token allways will be passed to the endpoint implicitly.
- authentication_token – which grants access to the api.
Returns: an SlackApiResponse object based on the response of the slackapi endpoint.
Raise: Exception if an error occurs while executing the api call.
- request_parameters (dict) –
-
-
class
libslack.slackapi.
SlackApiResponse
(response_data)[source]¶ The SlackApiResponse class handles and encapsulates an response provided by the slackapi after an api method was called at the endpoint.
License¶
Copyright (c) 2015, Nicola Coretti All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS WARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.