Silk will execute Python code written using the WSGI model. How it does so depends on which silk platform version your account is hosted on.

Choosing a version of Python

You can choose among multiple versions of Python:

Silk platform Python version Command-line path
silkv1 2.6 (default) /usr/bin/python
silkv2 2.7 (default) /usr/bin/python
silkv2 3.5 /usr/local/bin/python35

If you need to switch Python versions, you can do so by creating or editing your site's .silk.ini file (for example ~/www-root/.silk.ini) and adding the version to the [python] section:

[python]
version = 3.5

Valid version choices are default, any of the versions listed in the table above, or newest (which provides the newest available on the system).

Web applications

Silk platform version 1

Silk will execute scripts ending in .py within a Python FCGI handler that runs within the WSGI model. Scripts will be dynamically loaded as modules on the first request, and their 'request_handler' attribute should be set to the instance of a function implementing the start_response() callable.

Example WSGI script

def my_handler(environ, start_response):
       start_response('200 OK', [('Content-Type', 'text/plain')])
       yield "Hello World\n"
       for k, v in sorted(environ.items()):
            yield "%s: %s\n" % (k, v)

request_handler = my_handler

Reloading applications

The environment variable wsgi_max_requests can be set to cause the FCGI wrapper to reload your Python script (module) every N requests. During development, you can set this to something very low to see incremental changes as you work. Otherwise, the FCGI wrapper will cache your code for FCGI_MAX_REQUESTS.

For example, in your .htaccess file:

SetEnv wsgi_max_requests 10

Silk platform version 2

Python applications use Phusion Passenger as an app server. You can run an application by placing the following in an .htaccess file in your ~/www-root/ directory:

PassengerAppType wsgi
PassengerStartupFile passenger_wsgi.py
PassengerAppRoot /users/m/y/mynetid/www-root
PassengerPython /usr/bin/python

PassengerAppRoot should be the full path to the directory where your application's startup file is located.

PassengerPython should be the full path to your preferred version of Python.

Reloading applications

An application needs to be restarted for code changes to take effect. You can do this by killing the current application process:

[myusername@silk21 ~]$ pkill -u myusername -f wsgi-loader

Your application will relaunch the next time it is requested from a web browser.

Modules

Python modules are managed using the pip command.

You can see which modules are currently installed by typing pip list, or see which you have installed yourself with pip list --user.

Additional modules can be installed by typing pip install --user <modulename>, which will place them in your home directory, under ~/.local/. Scripts or commands included with a module are placed in ~/.local/bin/ and can either be run directly from there or added to your PATH by adding a line such as the following to ~/.bash_profile:

export PATH=~/.local/bin:$PATH