gutter-appengine provides an App Engine front-end for gutter. It allows you to create and update switches using a UI and to register new arguments and operators particular to your application.
The first step is to include gutter-appengine in your app.yaml.
includes:
- lib/gutter/appengine/Next, in appengine_config.py set the default gutter manager to use the App Engine manager.
from gutter.client.settings import manager
from gutter.appengine.manager import default_manager
manager.default = default_managerNow, you are ready to define your switches and switch conditions. Also in appengine_config.py (and above setting the default manager so that the manager knows how to unpickle the classes).
from gutter.client import arguments
from gutter.appengine import registry
class User(arguments.Container):
nickname = arguments.String(lambda self: self.input.nickname())
email = arguments.String(lambda self: self.input.email())
user_id = arguments.String(lambda self: self.input.user_id())
class Account(arguments.Container):
account_group_id = arguments.String(lambda self: self.input.account_group_id())
class Partner(arguments.Container):
partner_id = arguments.String(lambda self: self.input.partner_id)
registry.arguments.register(User.email)
registry.arguments.register(User.nickname)
registry.arguments.register(User.user_id)
registry.arguments.register(Account.account_group_id)Navigate to /gutter/ to begin creating switches. The example in example_app
shows a full example of integrating gutter with your project.
A Switch takes one or more Conditions and passes or fails based on whether or not its input satisfies the Conditions. Each Condition takes one or more Arguments. You can think of this as defining a list of equations that any inputs must satisfy to pass or fail a switch.
class UserArguments(arguments.Container):
age = arguments.Integer(lambda self: self.input.age())
condition = Condition(UserArguments, 'age', LessThan(upper_limit=18))
switch = Switch('minor', compounded=False)
switch.conditions = [condition]To use a switch, call active and pass it an input. The input can be any object
matching the Arguments to your Condition. active will return True if the input
satisfies the condition or False otherwise.
from gutter.client.default import gutter
is_active = gutter.active('minor', User) # User is your domain objectIf you need more information on gutter internals, refer to the official gutter project.
Using virtualenv is recommended for development.
virtualenv .
source ./bin/activate
Development DependenciesWe use flake8 for checking both PEP-8 and common Python errors and invoke for continuous integration.
pip install -U flake8
pip install -U invokeYou can list available build tasks with inv -l.
Due to a limitation with Google Appengine, dependencies must be installed locally before running tests. TThe fetch_deps make command will install dependencies to the vendor directory.
inv fetch_depsYou need pip, setuptools and wheel to publish to PyPI.
inv publish