Skip to main content


Project description

About switchboard-tg2

switchboard-tg2 provides an easy way to plug Switchboard, a feature flipper library, into TurboGears2 applications.


switchboard-tg2 can be installed both from pypi:

easy_install switchboard-tg2

should just work for most of the users.

Using switchboard-tg2

In your application config/ import plug:

from tgext.pluggable import plug

Then at the end of the file call plug with switchboard-tg2:

plug(base_config, 'switchboard_tg2')

You will be able to access Switchboard’s admin UI at http://localhost:8080/switchboard.

You will also need to configure Switchboard’s access to memcached and MongoDB. By default Switchboard attempts to connect to both of these services on localhost and on the default ports. If it fails to connect it will fall back to in-memory equivalents and display warning messages in the admin UI.

While running with the in-memory mode enabled is fine for getting started quickly, please do not run in production in this mode!

Getting Started - An Example

The switchboard-tg2 code contains an example TurboGears 2 application, modified to use Switchboard. The application is a quickstart application and the only changes made to it where to setup Switchboard. You’ll find the application in the ‘example’ directory. Here’s how Switchboard was added to the app:

  1. Add the plug call to

    from tgext.pluggable import plug
    plug(base_config, 'switchboard_tg2')
  2. Import Switchboard’s operator and use it to optionally display a flash message from the controller, as an example of using Switchboard in Python code:

    from switchboard import operator
    if operator.is_active('hello_world'):
        flash('Hello World')
  3. Next, we want to pass the operator off to the template so that we can also use it there. Again, in the controller:

    return(page='index', operator=operator)
  4. Finally we can use the operator in the index.html template to make various parts of the page turn on or off:

    <py:if test="operator.is_active('getting_started')">

One thing to note: the template demonstrates the use of parent/child switches. The getting_started switch is the parent switch. Any switch prefixed with getting_started: will be a child. Children inherit conditions from their parents and can add conditions of their own.

To see all of these switches in action: run paster serve development.ini in the example directory and point your browser to http://localhost:8080/. Once you load the index page, all of the switches encountered will be automagically created within Switchboard. When you pull up the admin UI at http://localhost:8080/switchboard/, you’ll see the hello_world and getting_started switches.

Set the getting_started switch to “Active for everyone” and reload the index page. Now reload the Switchboard admin and you should see several more of the child switches for the Getting Started section. These switches weren’t created because they weren’t even checked until their parent switch was turned on.

Play around with turning various switches on and off to see what impact it has on the index page. You can also try adding conditions to a switch to see what happens when a switch is only active under certain conditions.

Here’s a diff of all the changes made to the example app to change it from the stock quickstart app to a Switchboard-enabled app:

More information

You can find more information about Switchboard and how to use it in your code in the Switchboard docs.

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

switchboard-tg2-0.3.tar.gz (3.8 kB view hashes)

Uploaded Source

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