How to distinguish between various environments (development / staging / production) in Prefect flows?

There is an entire Github discussion where many users share how they approached it:

There are a couple of ways how to handle it in Prefect <= 1.0 depending on which Cloud plan you are:

  • if you are on Enterprise, you could have a separate tenant for prod and staging environments which allow for a full isolation
  • if you are on a lower Cloud plan or on a Prefect Server, here are some options you can consider:
    1. You can use labels to distinguish between environments - this is the easiest and most straightforward approach
    2. You can treat projects as placeholders for different environments in the UI
    3. Or you can combine both: labels and projects.

When it comes to differentiating between different environments in your flow code, you could use extra utility functions that return a different run configuration or storage with different labels, depending on the environment, for example:

Here line 66 shows how it can be used in a flow: