The goal of this tutorial is to build a simple ByteNite app that outputs the string "Hello, World!" to a file. Use this tutorial if you're new to ByteNite and want to have a quick sense of the workflow.
Duration
Difficulty
Prerequisites
~15 min
Very Easy
1
Download sample app
Run the app new command in your terminal to create an app directory locally named "hello-world":
bytenite app new hello-world
Check that a new directory named "hello-world" was indeed created at your base path:
ls
2
Write the main script
Locate your pre-generated Python entry point (./hello-world/app/main.py) and add the code to the file.
We'll make the app perform a few simple steps:
Read a string from the input text file (chunk).
Convert the string to a case matching the input parameter 'case'.
Write the result to a text file in the task results directory.
main.py
if __name__ == '__main__':
print("Python task started")
result_path = os.path.join(task_results_dir, 'processed_chunk.txt')
try:
# 1. Reading Inputs
# Expect a text file to be passed by the partitioner
with open(chunk_path, 'r', encoding="utf-8") as infile:
my_string = infile.read()
# 2. Handling Parameters
# Expect the job parameters to have a key named 'case', and the options to be "upper", "lower", and "title"
case = app_params['case']
# 3. Developing the Core Functionality
# Process the string based on the case parameter
if case == "upper":
my_string = my_string.upper()
elif case == "lower":
my_string = my_string.lower()
elif case == "title":
my_string = my_string.title()
else:
my_string = my_string
# 4. Saving Outputs
# Save the string directly into a text file to the default task results directory
with open(os.path.join(task_results_dir, "hello_world_processed.txt"), 'w', encoding="utf-8") as outfile:
outfile.write(my_string)
except Exception as e:
print("Python exception: ", e)
raise e
3
Check your manifest and template files
The manifest and template files are automatically generated and located in your hello-world directory. Ensure they contain the correct configurations as shown below.
Note: We're using passthrough partitioning and assembling engines in this template, so there's no need to configure these components.