From eb610c6dc8e673248c07c192737d24ea69f0e616 Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Mon, 8 Feb 2021 16:38:57 -0800 Subject: [PATCH 1/5] Getting started tutorial --- rsts/tutorials/getting_started.rst | 92 ++++++++++++++++++++++++++++++ rsts/tutorials/index.rst | 6 ++ 2 files changed, 98 insertions(+) create mode 100644 rsts/tutorials/getting_started.rst diff --git a/rsts/tutorials/getting_started.rst b/rsts/tutorials/getting_started.rst new file mode 100644 index 0000000000..1e6a1c4a39 --- /dev/null +++ b/rsts/tutorials/getting_started.rst @@ -0,0 +1,92 @@ +.. _tutorials-getting-started: + +######################################## +Writing Your First Workflow +######################################## + +By the end of this getting started guide you'll be familiar with how easy it is to author a Flyte workflow and run it locally. + +The easiest way to author a Flyte Workflow is using the provided python SDK called "FlyteKit". + +You can save some effort by cloning the ``flytekit-python-template`` repo, and re-initializing it as a new git repository :: + + pip install flytekit==0.16.6b + git clone git@github.com:lyft/flytekit-python-template.git myflyteproject + cd myflyteproject + rm -rf .git + git init + +Writing a Task +***************** + +The most basic Flyte primitive is a "task". Flyte Tasks are units of work that can be composed in a workflow. The simplest way to write a Flyte task is using the Flyte Python SDK - flytekit. + +Start by creating a new file :: + + + touch myapp/workflows/first.py + + +And add the required imports we'll need for this example: + + +.. code-block:: python + + import flytekit + from flytekit import task, workflow + from flytekit.types.file import FlyteFile + +From there, we can begin to write our first task. It should look something like this: + +.. code-block:: python + + def greet(name: str="world") -> FlyteFile: + working_dir = flytekit.current_context().working_directory + output_file = '{}/greeting.txt'.format(working_dir) + + greeting = f"Hello {name}" + with open(output_file,"a") as output: + output.write(greeting) + + print(greeting) + return FlyteFile["txt"](path=output_file) + + +Some of the new concepts demonstrated here are: + +* Use the :py:func:`flytekit.task` decorator to convert your typed python function to a Flyte task. +* A :py:class:`flytekit.types.file.FlyteFile` is a Flytekit type that represents binary data. It is used to offload data to a storage location like S3. Here we use it to store an image. + + +You can call this task + +.. code-block:: python + + greet(name="world") + +and iterate locally before adding it to part of a larger overall workflow. + +Writing a Workflow +********************* +Next you need to call that task from a workflow. In the same file, add these lines. + +.. code-block:: python + + @workflow + class GreeterWorkflow(name: str="world") -> FlyteFile: + greeting_file = greet(name=name) + return greeting_file + +This code block creates a workflow, with one task. The workflow itself has an input (the link to an image) that gets passed into the task, and an output, which is the processed image. + +You can call this workflow + +.. code-block:: python + + GreeterWorkflow(name=...) + +iterate locally before moving on to register it with Flyte. + +.. note:: + + Every invocation of a Flyte workflow requires specifying keyword args. diff --git a/rsts/tutorials/index.rst b/rsts/tutorials/index.rst index 8f4d7ff560..36d48625ac 100644 --- a/rsts/tutorials/index.rst +++ b/rsts/tutorials/index.rst @@ -4,3 +4,9 @@ Getting started and Tutorials ############################## +.. toctree:: + :maxdepth: 1 + :caption: Flyte Tutorials + :name: tutorialsecstoc + + tutorials/getting_started From e2d1d8abcbea0cbe063fcb9a8b01d1ec3b0db214 Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Mon, 8 Feb 2021 16:40:08 -0800 Subject: [PATCH 2/5] wip --- rsts/tutorials/getting_started.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rsts/tutorials/getting_started.rst b/rsts/tutorials/getting_started.rst index 1e6a1c4a39..3295ea7e44 100644 --- a/rsts/tutorials/getting_started.rst +++ b/rsts/tutorials/getting_started.rst @@ -6,6 +6,8 @@ Writing Your First Workflow By the end of this getting started guide you'll be familiar with how easy it is to author a Flyte workflow and run it locally. +Estimated time to complete: <5 minutes. + The easiest way to author a Flyte Workflow is using the provided python SDK called "FlyteKit". You can save some effort by cloning the ``flytekit-python-template`` repo, and re-initializing it as a new git repository :: From f68b26afe18886fd2ee2adf8e86f7026d1807c43 Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Mon, 8 Feb 2021 16:46:07 -0800 Subject: [PATCH 3/5] derp --- rsts/tutorials/getting_started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsts/tutorials/getting_started.rst b/rsts/tutorials/getting_started.rst index 3295ea7e44..c7579c2ab0 100644 --- a/rsts/tutorials/getting_started.rst +++ b/rsts/tutorials/getting_started.rst @@ -75,7 +75,7 @@ Next you need to call that task from a workflow. In the same file, add these li .. code-block:: python @workflow - class GreeterWorkflow(name: str="world") -> FlyteFile: + def GreeterWorkflow(name: str="world") -> FlyteFile: greeting_file = greet(name=name) return greeting_file From 04e14afb9bf138a15daf6e311a421b8dc8075aec Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Mon, 8 Feb 2021 17:21:18 -0800 Subject: [PATCH 4/5] nestled --- rsts/tutorials/{ => example.rst}/getting_started.rst | 0 rsts/tutorials/example.rst/index.rst | 11 +++++++++++ rsts/tutorials/getting_started/index.rst | 0 rsts/tutorials/index.rst | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) rename rsts/tutorials/{ => example.rst}/getting_started.rst (100%) create mode 100644 rsts/tutorials/example.rst/index.rst create mode 100644 rsts/tutorials/getting_started/index.rst diff --git a/rsts/tutorials/getting_started.rst b/rsts/tutorials/example.rst/getting_started.rst similarity index 100% rename from rsts/tutorials/getting_started.rst rename to rsts/tutorials/example.rst/getting_started.rst diff --git a/rsts/tutorials/example.rst/index.rst b/rsts/tutorials/example.rst/index.rst new file mode 100644 index 0000000000..7dc9fb1a68 --- /dev/null +++ b/rsts/tutorials/example.rst/index.rst @@ -0,0 +1,11 @@ +.. _tutorials: + +############### +Getting started +############### + +.. toctree:: + :maxdepth: 1 + :caption: Getting started examples + + getting_started diff --git a/rsts/tutorials/getting_started/index.rst b/rsts/tutorials/getting_started/index.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rsts/tutorials/index.rst b/rsts/tutorials/index.rst index 36d48625ac..f19a4c0d30 100644 --- a/rsts/tutorials/index.rst +++ b/rsts/tutorials/index.rst @@ -9,4 +9,5 @@ Getting started and Tutorials :caption: Flyte Tutorials :name: tutorialsecstoc - tutorials/getting_started + getting_started/index + Learn to use Flytekit by example From 02cbd5b76b0e0f04324c1695d9c3f99259be415a Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Mon, 8 Feb 2021 17:24:31 -0800 Subject: [PATCH 5/5] derp --- rsts/tutorials/example.rst/index.rst | 11 ----------- .../getting_started.rst | 0 rsts/tutorials/getting_started/index.rst | 11 +++++++++++ 3 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 rsts/tutorials/example.rst/index.rst rename rsts/tutorials/{example.rst => getting_started}/getting_started.rst (100%) diff --git a/rsts/tutorials/example.rst/index.rst b/rsts/tutorials/example.rst/index.rst deleted file mode 100644 index 7dc9fb1a68..0000000000 --- a/rsts/tutorials/example.rst/index.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. _tutorials: - -############### -Getting started -############### - -.. toctree:: - :maxdepth: 1 - :caption: Getting started examples - - getting_started diff --git a/rsts/tutorials/example.rst/getting_started.rst b/rsts/tutorials/getting_started/getting_started.rst similarity index 100% rename from rsts/tutorials/example.rst/getting_started.rst rename to rsts/tutorials/getting_started/getting_started.rst diff --git a/rsts/tutorials/getting_started/index.rst b/rsts/tutorials/getting_started/index.rst index e69de29bb2..7dc9fb1a68 100644 --- a/rsts/tutorials/getting_started/index.rst +++ b/rsts/tutorials/getting_started/index.rst @@ -0,0 +1,11 @@ +.. _tutorials: + +############### +Getting started +############### + +.. toctree:: + :maxdepth: 1 + :caption: Getting started examples + + getting_started