Developer Guide
Python Task API
Implementation Usage
4 min
k;liópo\[ for ease of use, swimlane has two different apis for interacting with python scripts a global and class level global the global usage was designed for scripters to be able to drop scripts into swimlane, configure a few variables, and be operational with little effort in this scenario, users will find anywhere they had arguments passed to the script via cli/etc and replace them with the swimlane context object sw context additionally, swimlane inserts a list of dictionaries (called sw outputs) into each script that can be used to return data to swimlane take the following demo script this script would be migrated by replacing the apikey and the iptolookup variables with variables from the context object additionally, the standard output printing can be removed to use the sw outputs object since we can capture messages from the standard output, moving the output to the outputs object is not necessary class developers who are familiar with object oriented programming concepts can leverage the class architecture pattern class applies to plugin tasks only, and not to custom scripts custom scripts do not contain plugin specific behaviors like being able to use swmain class when a developer defines a class with the name of swmain, it will be automatically invoked with the sw context object context argument after the class is initialized, the execute method is invoked on that instance of the class the execute method is where the 'work' of the task will be done when finished, the execute method returns an array of dictionaries as the output with this pattern, the context is encapsulated into the swmain singleton rather than accessing the global sw context or sw outputs objects and enforce a single exit point return object this rigid api helps to create more predictable, more maintainable, and easier readability plugin pattern swimlane’s internal plugins are authored in this format