Better interface for handling variables in Python scripts #14

Closed
opened 2022-07-05 01:38:39 +02:00 by blacklight · 0 comments
Owner

Platform variables are currently managed through the variable plugin. While the use of the plugin is very "Platypush-onic" (.get and .set methods are exposed as plugin actions) and provides an interface that is easy to use in the context of YAML procedures and hooks, it makes the variable handling process in Python scripts quite cumbersome. For example:

from platypush.procedure import procedure
from platypush.utils import run

@procedure
def my_procedure(**context):
  my_var = run('variable.get', name='my_var').get('my_var')
  run('variable.set', my_var=my_var+1)

We should instead provide a more Pythonic interface to hide the internals of the variable plugin:

from platypush.procedure import procedure
from platypush.variable import Variable

@procedure
def my_procedure(**context):
  my_var = Variable('my_var')
  cur_val = my_var.get()
  my_var.set(cur_val+1)
Platform variables are currently managed through the [`variable`](https://docs.platypush.tech/platypush/plugins/variable.html) plugin. While the use of the plugin is very "Platypush-onic" (`.get` and `.set` methods are exposed as plugin actions) and provides an interface that is easy to use in the context of YAML procedures and hooks, it makes the variable handling process in Python scripts quite cumbersome. For example: ```python from platypush.procedure import procedure from platypush.utils import run @procedure def my_procedure(**context): my_var = run('variable.get', name='my_var').get('my_var') run('variable.set', my_var=my_var+1) ``` We should instead provide a more Pythonic interface to hide the internals of the `variable` plugin: ```python from platypush.procedure import procedure from platypush.variable import Variable @procedure def my_procedure(**context): my_var = Variable('my_var') cur_val = my_var.get() my_var.set(cur_val+1) ```
blacklight added the
enhancement
label 2022-07-05 01:38:39 +02:00
blacklight self-assigned this 2022-07-05 01:38:39 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: platypush/platypush#14
No description provided.