Build Lightweight Python Components

    Lightweight Python components do not require you to build a new container imagefor every code change. They’re intended for fast iteration in a notebookenvironment.

    Advantages over container components:

    • Easier authoring: Components can be created in a local environment. Docker andKubernetes are not required.

    To build a component, define a stand-alone Python function and then call to convert the function to acomponent that can be used in a pipeline.

    There are several requirements for the component function:

      • It should not use any code declared outside the function definition.
      • Any helper functions should also be defined inside the main componentfunction.
    • The function can only import packages that are available in the base image.

      • If you need to import a package that’s not available in the default baseimage you can try to find a container image that already includes therequired packages. (As a workaround you can use the subprocess moduleto run for the required package.)
    • To build a component with multiple output values, use Python’styping.NamedTupletype hint syntax:

    The class is already imported, so that it can be used in thefunction declaration.

    Was this page helpful?

    Glad to hear it! Please .

    Sorry to hear that. Please tell us how we can improve.

    Last modified 10.09.2019: