Hello, World!
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.
~15 min
Very Easy
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.
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
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.
{
"name": "hello-world",
"version": "0.1",
"platform": "docker",
"description": "An app named hello-world",
"entrypoint": "main.py",
"platform_config": {
"container": "python:latest"
},
"device_requirements": {
"min_cpu": 2,
"min_memory": 2
}
}
{
"id": "hello-world-template",
"description": "A template for hello-world",
"app": "hello-world",
"partitioner": "passthrough",
"assembler": "passthrough"
}
Submit and activate your app
Upload the content of your app:
bytenite app push hello-world
Activate your app to make it accept jobs:
bytenite app activate hello-world
Now, check your app's details and status by running the command:
bytenite app get hello-world
Finally, ensure that your template was correctly uploaded—you will need that for running jobs.
bytenite template get hello-world-template
Launch a job with 'hello-world-template'
Let's launch a job with your new hello-world-template
and test your app.
Send a POST request to the Job Create endpoint, including the following fields in the request body:
templateId
hello-world-template
dataSource
{
"dataSourceDescriptor": "url",
"params": {
"@type": "type.googleapis.com/bytenite.data_source.HttpDataSource",
"url": "https://storage.googleapis.com/video-test-public/hello-world-I.txt"
}
}
dataDestination
{
"dataSourceDescriptor": "bucket"
}
params
{
"app": {
"case": "upper"
}
}
Then, launch your job and check the results.
Here's a Postman collection that you can use to run your Hello World job:
Last updated
Was this helpful?