Skip to content

An Example

Info

Python code in the examples is primarily boilerplate code generated by the fy tool. The developer only adds custom logic code at the end.

Flow

flow HelloWorld -> None:
    property greeting using hello_world
    method greet using greeting
flows/greet__using_greeting__fy.py
"""fy
flow HelloWorld -> None:
    property greeting using hello_world
    method greet using greeting
"""
from fy_core.base.flow_base import FlowBase

from mixins.method.greet.using_greeting_fy import (
    Greet_UsinGreeting_MethodMixin,
)
from mixins.property.greeting.using_hello_world_fy import (
    Greeting_UsingHelloWorld_PropertyMixin,
)


# fy:start ===>>>
class Greet_UsingGreeting_Flow(
    # Property Mixins
    Greeting_UsingHelloWorld_PropertyMixin,
    # Method Mixins
    Greet_UsinGreeting_MethodMixin,
    # Base
    FlowBase[None],
):
    def __call__(self) -> None:
        # fy:end <<<===
        self._greet()

Abstract Property greeting

property greeting: str
mixins/property/greeting/abc_fy.py
"""fy
property greeting: str
"""
import abc


# fy:start ===>>>
class Greeting_PropertyMixin_ABC(abc.ABC):
    @property
    @abc.abstractmethod
    def _greeting(self) -> str:
        raise NotImplementedError()
        # fy:end <<<===

Property greeting implementation

property greeting: str using hello_world:
mixins/property/greeting/using_hello_world_fy.py
"""fy
property greeting: str using hello_world:
"""


# fy:start ===>>>
class Greeting_UsingHelloWorld_PropertyMixin:

    @property
    def _greeting(self) -> str:
        # fy:end <<<===
        return "Hello, World!"

Method greet implementation

method greet -> None using greeting:
    property greeting
mixins/method/greet/using_greeting_fy.py
"""fy
method greet -> None using greeting:
    property greeting
"""
import abc

from mixins.property.greeting.abc_fy import (
    Greeting_PropertyMixin_ABC,
)


# fy:start ===>>>
class Greet_UsingGreeting_MethodMixin(
    # Property Mixins
    Greeting_PropertyMixin_ABC,
    abc.ABC,
):
    def _greet(self) -> None:
        # fy:end <<<===
        print(self._greeting)

A Quick Overview

  1. The _fy.py file starts with the docstring """fy, where the fy code resides. In this example, we define a flow that includes two mixin implementations: a property greeting that returns the string "Hello, World!" and a method greet that utilizes the implementation of the greeting property.
  2. The block of python code between comments # fy:start ===>>> and # fy:end <<<=== is generated by the fy tool.
  3. The user begins by writing the fy block, then runs the tool to generate the boilerplate code, and finally adds custom logic where necessary.