Context Neutral
Executing code in clearskies starts with an “application”: a combination of code and configuration that can be run anywhere. In order to run an application, you attach it to the appropriate “context”: WSGI server, Lambda, Queue listener, CLI, test environment, etc… The same code can run in your production environment, on a dev machine, or in your test suite without making any changes.
Consider a simple hello world application:
import clearskies
def hello_world():
return 'Hello world!'
The following code would allow it to run in a WSGI server:
api = clearskies.contexts.wsgi(hello_word)
def application(env, start_response):
return api(env, start_response)
While a slight tweak would allow it to run in a Lambda behind an API gateway:
import clearskies_aws
api = clearskies_aws.contexts.lambda_api_gateway(hello_word)
def application(event, context):
return api(event, context)
Or from the command line:
cli = clearskies.contexts.cli(hello_word)
cli()