Support for standalone python-driven server? (E.g. Slack bot endpoint)

I can’t seem to determine from the KB whether it’s possible to run a python program which will handle HTTPS requests itself, rather than being invoked as a CGI script.

Specifically, I’d like to host a slack bot’s endpoint (this one: https://github.com/docmarionum1/slack-archive-bot , but I suppose there are other similar ones using python-slackclient).

I don’t have any experience with Passenger – from what I can tell, it is invoked by Apache, and then passes control to ruby/python/node/etc. This to me sounds like a CGI, but the claim is that it’s used for standalone frameworks like Flask. Would Passenger be able to run the above python web app?

Thanks in advance!

Should just work out of the box, although you’ll likely need to work in a virtual environment to install the slackclient.

$ cd ~
$ virtualenv virtual
$ source virtual/bin/activate
$ which python # just to test that you're the boss now
$ pip install slackclient==1.3.2

Note that if you’re on a shared server DreamHost reserve the right to kill any persistent process if it gets out of hand resource-wise.

Hi sXi, thanks for taking a look. I don’t see how this addresses my question. I know how to install a python package. That is distinct from being able to run a python program which will listen for HTTPS requests instead of Apache listening for requests. Can you explain further what will just work out of the box?

slackclient isn’t a server (it’s a client). Scripts can send out requests to HTTPS ports just like a browser on a user’s machine. The response port on which it will receive information is not 443. For example
$ wget -qO- https://dreamhost.com
will send out a request to port 443 but the reply printed to your shell is not being received and handled by Apache. The local port handling the response might well be 55173.

I was under the impression that the python package slackclient includes code to serve as an HTTPS endpoint, which is necessary if Slack clients want to be able to perform certain actions (yes, I think the Slack client must be serve as an HTTPS server). This may not be the case for slack-archive-bot, I haven’t dug into their code yet.

After more research I’ve learned that the more or less standard approach would be to use a framework like Flask or Django, for which Dreamhost recommends one use Passenger as a “WSGI” interface between Apache and Flask/Django. So, I think I’ve found my answer! The recommendation would be to avoid a standalone python app acting as server, and instead rely on the Apache/Passenger/Flask stack.

The slackclient that particular bot uses (v1) can be found here: https://github.com/slackapi/python-slackclient/tree/v1/slackclient

It doesn’t “serve” anything to the outside world any more than your web browser does.