Python Configuration

From Ladon Webservice

Jump to: navigation, search


Before Production State

When developing a Ladon webservice project you can test it easily any time you want using the subcommand testserve of ladonX.Yctl (where X.Y is the major.minor of your Python version). This is nice for instance if you are prototyping or just need to see some results fast. For instance if you have Ladon installed for Python 2.7 and want to test the service class implemented in using port 8080, you would issue the following command:

ladon2.7ctl testserve -p 8080
Request a feature

Help ease the development

However Ladon is not a webserver project and the testserve command will not scale properly, so as you move past the test/prototyping stages of your project you should configure a real webserver to handle requests. Ladon uses WSGI therefore any webserver that supports WSGI should be capable of running a Ladon webservice.

Production state with Apache2 and mod_wsgi

In the following section are shown some examples of how to configure Apache2 with mod_wsgi to run a Ladon webservice implemented in the module

Adding to an existing virtual host

Let's say you have an Apache2 server already configured with a virtual host and you just want to setup an alias to a script that can handle your Ladon Service. All you have to do is edit the configuration file containing the VirtualHost tag and add the following directive:

WSGIScriptAlias /myservice/ /srv/ladon/myservice/

In the above example your site will execute the handler script when you access the path /myservice. The handler script will instantiate the LadonWSGIApplication with information about which module your service is implemented in and where to locate it.

The LadonWSGIApplication class:

  service_list: A list of module names to be imported into the Ladon WSGI Application.
  path_list:    A list of paths to add to Python`s module search path
  catalog_name: The displayed name of the webservice catalog
  catalog_desc: The description for the webservice catalog

Let's say for this example that the Ladon webservice implemented in module is located in the same directory as So we have the following structure:

jakob@jakob-vaio:/$ tree /srv
├── ladon
│   └── myservice
│       ├──
│       └──

In this case you can use the following example directly as handler:

from ladon.server.wsgi import LadonWSGIApplication
from os.path import abspath,dirname
application = LadonWSGIApplication(
  catalog_name='My Ladon webservice catalog',
  catalog_desc='This is the root of my cool webservice catalog')

In the example above the absolute path to the location of (__file__) is used as item in the path_list.

Creating a new virtual host as a Ladon webservice

If you want to create a new site with a Ladon webservice at the root of the site, you can use the following example as template, it creates a virtual host that responds to incomming requests to hostname

<VirtualHost *:80>
        WSGIScriptAlias / /srv/ladon/myservice/
        LogLevel warn
        ErrorLog ${APACHE_LOG_DIR}/mysite.com_error.log
        CustomLog ${APACHE_LOG_DIR}/mysite.com_access.log combined