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, you will create 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 our step function as a method; file input and output are handled with “dataslots”, indicated with decorators. Adding a version decorator is also strongly recommended.

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

A couple notes:

  • The block at the bottom allows you to execute this file as a script.
  • In order to declare file input and output, you 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.

You can now try your new step. To specify parameters and dataslots through the command line, pass Python-style dictionaries from parameter names to values. Furthermore, because a dataslot can potentially contain more than one file, each dataslot takes a list of files.

For instance, create input.txt in the test directory, containing “Hello World!”. You can then try the following, specifying files for each dataslot input/output and values for each parameter:

Terminal window
foo@bar: ~/my_project$ uv run src/small_step.py --function append --input-dataslots "{'input_file': ['test/input.txt']}" --output-dataslots "{'__returns__': ['test/output.txt']}" --parameters "{'next_line': 'Hello 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

Note that dataslot.returns is a special output dataslot, with the name __returns__. For full documentation on all options, including short forms, try running uv run src/small_step.py run --help.

As shown above, your function returns None; this is expected, since the return value was directed into a file. You can now check test/output.txt and confirm the contents were appended:

test/output.txt
Hello World!
Hello again!