Your first step
With your project set up, you are now ready to begin writing your first ProcessingStep in earnest.
One small step
Section titled “One small step”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”.
from pinexq.procon.dataslots import DataSlot, dataslot, MediaTypesfrom 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 executionif __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
@dataslotdecorators, as shown. - The mediatypes of these files should always be given; for example,
media_type=MediaTypes.TEXTensures the files are opened in text mode.
Running locally
Section titled “Running locally”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:
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.39Python: CPython 3.14.0pinexq-procon: 2.3.0pinexq-client: 1.0.0NoneThe function will return None, as expected, and you can check test/output.txt and confirm the contents were appended:
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.