Skip to content

Your first step

With your project set up, you are now ready to begin writing your first ProcessingStep in earnest.

In this tutorial, we will do something more complicated: a Step that takes an input file, reads it, appends a string, and then outputs to a file. You will need to subclass Step, then implement your step function as a method; file input and output are handled with “dataslots”.

src/small_step.py
from pinexq.procon.dataslots import DataSlot, dataslot, MediaTypes
from pinexq.procon.step import Step
class SmallStep(Step):
@dataslot.input("input_file", media_type=MediaTypes.TEXT)
@dataslot.output("output_file", media_type=MediaTypes.TEXT)
def append(self, input_file: str, next_line: str, output_file: DataSlot) -> None:
temp_string = input_file + next_line
output_file.write_data_to_slots(temp_string)
# for command line execution
if __name__ == "__main__":
SmallStep()

A couple notes:

  • The block at the bottom allows us to execute this file as a script.
  • In order to declare file input and output, we need to use the @dataslot decorators, as shown.
  • The mediatypes of these files should always be given; for example, media_type=MediaTypes.TEXT ensures the files are opened in text mode.

We can now try our new step. Passing parameters through the command line is somewhat more complicated: we will need to pass Python-style dictionaries from parameter names to values. For instance, suppose we created input.txt in the test directory, containing “Hello World!”. We can then try the following:

Terminal window
foo@bar: ~/my_project$ uv run src/small_step.py -f append -di "{'input_file': ['test/input.txt']}" -do "{'output_file': ['test/output.txt']}" -p "{'next_line': '\nHello again!'}"
23-01-26 16:00:35 INFO Platform and package information:
OS: Linux-6.6.87.1-microsoft-standard-WSL2-x86_64-with-glibc2.39
Python: CPython 3.14.0
pinexq-procon: 2.3.0
pinexq-client: 1.0.0
None

The function will return None, as expected, and you can check test/output.txt and confirm the contents were appended:

test/output.txt
Hello World!
Hello again!

Note that we needed to use both single and double quotes to type the parameters properly. As well, since input dataslots can potentially contain more than one file, we had to give input/output dataslot files as a list. For full documentation on all options, try running uv run src/small_step.py run --help.