# Local Environment

WARNING

Flows configured with environments are no longer supported. We recommend users transition to using RunConfig instead. See the Flow Configuration and Upgrading Environments to RunConfig documentation for more information.

# Overview

The Local Environment (LocalEnvironment) is meant to be a simple and minimally configurable execution Environment for Flow runs, and is the default Environment for all Flows registered with the Prefect API. The Local Environment functions as a way to execute Flows without any pre-existing infrastructure requirements and instead opts to run Flows directly in process.

The only needed configuration for the Local Environment is the specification of an Executor however if it is not specified then it defaults to the LocalExecutor.

For more information on the Local Environment visit the relevant API documentation.

# Process

# Initialization

The LocalEnvironment takes an optional executor argument. The executor argument accepts an Executor object that should be used to run this flow. If not specified, the local default executor is used.

# Setup

The LocalEnvironment has no setup step because it has no infrastructure requirements.

# Execute

The LocalEnvironment executes the flow locally in process, using the configured executor.

# Examples

# Using a LocalExecutor

Here we configure a LocalEnvironment to run a flow using a LocalExecutor. Note that this is the same as the default behavior - if you don't specify an environment on a Flow the same configuration will be created for you.

from prefect import Flow
from prefect.environments import LocalEnvironment
from prefect.executors import LocalExecutor

flow = Flow(
    "Local Executor Example",
    environment=LocalEnvironment(executor=LocalExecutor()),
)

# Using a DaskExecutor, with a local Dask cluster

Here we configure a LocalEnvironment to run a flow using a DaskExecutor, connected to a local temporary Dask cluster. When the flow run starts, a temporary local Dask cluster will be created just for that flow run.

from prefect import Flow
from prefect.environments import LocalEnvironment
from prefect.executors import DaskExecutor

flow = Flow(
    "Dask Executor Example",
    environment=LocalEnvironment(executor=DaskExecutor())
)

# Using a DaskExecutor, with an existing Dask cluster

Here we configure a LocalEnvironment to run a flow using a DaskExecutor, connected to an existing Dask cluster.

from prefect import Flow
from prefect.environments import LocalEnvironment
from prefect.executors import DaskExecutor

flow = Flow(
    "Dask Executor Example",
    environment=LocalEnvironment(
        executor=DaskExecutor(
            "tcp://address-of-the-dask-cluster:8786",
        )
    )
)