Skip to main content

A simple, intuitive and fast Slack API client for the Slack Web API

Reason this release was yanked:

Import bug

Project description

SlackTime

Build Status

Background

  • This library is a wrapper around the Slack WebAPI (https://api.slack.com/methods)
  • This library uses the beautiful requests library (https://github.com/psf/requests) and the methods return requests.Response objects
  • This library is a homage to the great (and now archived) Slacker (https://github.com/os/slacker)
  • This library is a response to the official Slack client (https://github.com/slackapi/python-slackclient). I'm so petty I couldn't stand the the camel/snake-case hybrid: client.chat_postMessage
  • This library was made mostly by a script that scraped the Slack API method page and automagically generated the code
  • This library was touched up by a human and some tests and docs generated, but I am fully aware there could be bugs

Aim

This library aims to be:

  • Simple
  • Intuitive
  • Fast

Install

  • This library uses f-strings and therefore is 3.6+
  • Simply install using pip
pip install slack_time

Learn by example

Getting a client:

from slack_time import get_slack_time

slack_time = get_slack_time()
  • get_slack_time will grab the SLACK_API_TOKEN environment variable
  • Environment variable grabbed can be changed:
slack_time = get_slack_time('SLACK_TOKEN')

Making a client:

from slack_time import SlackTime

slack_time = SlackTime('xoxo-hello-world')
  • Or with other config:
from slack_time import SlackTime
import requests

token = "xoxo-gossip-girl"
session = requests.Session()
proxies = {"http": "10.10.10.10:80", "https": "10.11.12.13:8080"}
timeout = 60

slack_time = SlackTime(token, session=session, proxies=proxies, timeout=timeout)

Using the client:

from slack_time import get_slack_time

slack_time = get_slack_time()

slack.chat.post_message("general", "Hey team, I love this knock off Slacker library!")

Inspecting a response:

>>> resp = slack_time.api.test(foo='bar')
>>> resp
<Response [200]>
>>> resp.json()
{
    'ok': True,
    'args': {
        'token': 'xoxp-your-token',
        'foo': 'bar'
    }
}

Errors:

  • When an 'error' is returned in the response it will be raised as an exception
  • The exception will subclassed from SlackError
>>> slack_time.api.test(error='hello')
Traceback (most recent call last):
  ...
slack_time.api.hello: You tried to perform a request to https://slack.com/api/api.test.
The server returned a 'hello' response. Find out more at: https://api.slack.com/methods/api.test#errors

>>> from slack_time import SlackError
>>> try:
...     slack_time.api.test(error='hello')
... except SlackError:
...     pass

How it works

Some examples:

  • admin.conversations.convertToPrivate -> slack_time.admin.conversations.convert_to_private
  • admin.conversations.ekm.listOriginalConnectedChannelInfo -> admin.conversations.ekm.list_original_connected_channel_info
  • files.revokePublicURL -> files.revoke_public_url
  • etc

Examples

from slack_time import get_slack_time

slack = get_slack_time()

slack.files.upload('hello_world.txt')

with open('hello_world.txt') as f:
    slack.files.upload(f)

Docs

Please use the slack docs https://api.slack.com/methods

Contributing

  • I imagine there are bugs
  • Please feel free to submit a PR, you will need to install pre-commit (https://pre-commit.com/)

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

slack_time-0.1.4.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

slack_time-0.1.4-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file slack_time-0.1.4.tar.gz.

File metadata

  • Download URL: slack_time-0.1.4.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.1

File hashes

Hashes for slack_time-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1cb151ea785831f1062d7e7b44c26559a9adecd0c1484085129413dde392de77
MD5 ff9d89aeae50b11efe4616cdd7bf681d
BLAKE2b-256 2dba018a1776a3fd3a24b9439997948df51b4054c788be36836096eb7c19843b

See more details on using hashes here.

File details

Details for the file slack_time-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: slack_time-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.1

File hashes

Hashes for slack_time-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 11b20615d6478808541b680c576cf91cdf7c211e954fc46c0ad4bd8167f40a62
MD5 c50126b7a744cc64adf24eb167f2f3cd
BLAKE2b-256 910a0c7b2f456240ebeddb8eb684b910dc6a7710bb504f39ccec3360351aafdb

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