gee
07/16/2025, 2:00 PMMarvin
07/16/2025, 2:00 PMMarvin
07/16/2025, 2:01 PMpython
from prefect import flow, task
@task
def say_hello(name):
return f"Hello {name}!"
@flow
def my_flow(name: str = "world"):
message = say_hello(name)
print(message)
if __name__ == "__main__":
my_flow()
You can save this as my_flow.py
and run it directly with:
bash
python my_flow.py
The flow will execute just like any other Python script. While Prefect will still maintain some local logging (it's part of how the framework tracks execution), you don't need to connect to any Prefect server or API.
This is one of the nice features of Prefect 3.x - flows are just Python functions with superpowers. You can develop and test them locally without any additional infrastructure or configuration.
If you want to see the flow in action with different parameters, you can also call it directly in a Python REPL or Jupyter notebook:
python
my_flow("Marvin") # Will print "Hello Marvin!"
The @flow
decorator adds functionality like automatic logging and state tracking, but it doesn't require any external connections to work. This makes it great for local development and testing.
Would you like me to explain more about what functionality is still available when running flows locally, or would you like to see more complex examples?gee
07/16/2025, 2:02 PMMarvin
07/16/2025, 2:02 PMNate
07/16/2025, 2:03 PMmy_flow.fn()
Marvin
07/16/2025, 2:03 PMbash
export PREFECT_LOGGING_TO_API_ENABLED=False
python your_flow.py
2. Set it in your Python script before defining your flow:
python
import os
os.environ["PREFECT_LOGGING_TO_API_ENABLED"] = "False"
from prefect import flow, task
# ... rest of your flow code
3. Use Prefect's settings API in your code:
python
from prefect.settings import Setting
from prefect.context import settings
with settings.update({"PREFECT_LOGGING_TO_API_ENABLED": False}):
my_flow()
If you want to make this change permanent for your local development environment, you can add the environment variable to your shell's configuration file (like .bashrc
or .zshrc
):
bash
echo "export PREFECT_LOGGING_TO_API_ENABLED=False" >> ~/.bashrc
This will prevent all your local flow runs from being logged to the server while still maintaining local execution capabilities and local logging.
Note that this only affects the logging to the API - your flow will still work normally and maintain local logs, but won't send any information to the Prefect server.
Would you like me to explain more about other logging configurations you can customize, or would you like to know how to selectively enable/disable this for specific flows?Nate
07/16/2025, 2:04 PMdisable_logging
context manager
and oh yeah you can disable PREFECT_LOGGING_TO_API_ENABLED
with temporary_settings
i guess toogee
07/16/2025, 2:04 PMNate
07/16/2025, 2:05 PMgee
07/16/2025, 2:05 PMNate
07/16/2025, 2:05 PMgee
07/16/2025, 2:06 PMNate
07/16/2025, 2:08 PMlocal
or something that either uses an ephemeral server or a different database or whatever you wantgee
07/16/2025, 2:14 PMprefect profile populate-defaults
creates cloud/local/test profiles. The test profile starts and stop a server before and after running the flow making it portable. The only way to achieve what I wanted here (don't send anything to any server) is by changing the script code and call flow.fn() instead. Note that this could be easily done either with an if in the if __name__ == "__main__"
block or importing. the flow into another script.Nate
07/16/2025, 2:16 PMprefect_test_harness
which we use for testing. but thats still writing to a tmp db. the only way to totally avoid writing data to the configured API is to call the underlying functions via .fn
or by literally removing the decoratorgee
07/16/2025, 2:16 PM⠹ Checking API connectivity...
Error authenticating with Prefect Cloud using profile 'ephemeral'
Marvin
07/16/2025, 2:16 PMMarvin
07/16/2025, 2:17 PMMarvin
07/16/2025, 2:17 PMbash
prefect profile use ephemeral
And ensure these environment variables are NOT set:
- PREFECT_API_KEY
- PREFECT_API_URL
(should be local)
2. Create a new profile for Prefect Cloud (if that's what you want):
bash
prefect profile create cloud
prefect profile use cloud
prefect cloud login
3. Check your current configuration:
bash
prefect profile inspect
This will show you what settings are active in your current profile.
The ephemeral profile is designed to work out-of-the-box for local development without any authentication. If you're seeing an authentication error, it likely means that:
- There might be conflicting environment variables set
- The profile might have been modified from its default state
- You might have Prefect Cloud settings that are interfering
Would you like me to help you:
1. Reset your ephemeral profile to its default state?
2. Set up a proper Prefect Cloud profile?
3. Check your current configuration to identify what's causing the conflict?
Just let me know which path you'd like to explore and I'll provide more specific guidance.Marvin
07/16/2025, 2:17 PMbash
prefect profile ls
2. You can create a new local profile:
bash
prefect profile create local
3. Then switch to it:
bash
prefect profile use local
4. To ensure it's set up for local development, you can set these settings:
bash
prefect config set PREFECT_API_URL="<http://127.0.0.1:4200/api>"
prefect config set PREFECT_SERVER_ALLOW_EPHEMERAL_MODE=true
If you want to inspect your current profile settings:
bash
prefect profile inspect
The ephemeral profile should work without authentication when properly configured for local development. If you're seeing authentication errors, it likely means the profile is trying to connect to Prefect Cloud instead of running in local mode.
Would you like me to help you set up a proper local development profile, or would you like to see more details about how the ephemeral profile works?gee
07/16/2025, 2:21 PM[profiles.ephemeral]
PREFECT_SERVER_ALLOW_EPHEMERAL_MODE = "true"
PREFECT_API_KEY = "pnu_<NOPE>
PREFECT_API_URL = "<https://api.prefect.cloud/api/accounts/5f98...4fb99/workspaces/8aaf2787-...4cf52a5>"
[profiles.local]
PREFECT_API_URL = "<http://127.0.0.1:4200/api>"
[profiles.test]
PREFECT_SERVER_ALLOW_EPHEMERAL_MODE = "true"
PREFECT_API_DATABASE_CONNECTION_URL = "sqlite+aiosqlite:///:memory:"
[profiles.cloud]
[profiles.prefect-cloud]
PREFECT_API_URL = "<https://api.prefect.cloud/api/accounts/5f98.....fb99/workspaces/8aaf27.....f52a5>"
PREFECT_API_KEY = "pnu_<NOPE>"
Marvin
07/16/2025, 2:21 PMMarvin
07/16/2025, 2:21 PMbash
prefect profile populate-defaults
This will reset the default profiles (including ephemeral) to their original state while preserving your custom profiles.
Your profiles.toml should then look more like this:
toml
[profiles.ephemeral]
PREFECT_SERVER_ALLOW_EPHEMERAL_MODE = "true"
PREFECT_API_URL = "<http://127.0.0.1:4200/api>"
[profiles.local]
PREFECT_API_URL = "<http://127.0.0.1:4200/api>"
[profiles.test]
PREFECT_SERVER_ALLOW_EPHEMERAL_MODE = "true"
PREFECT_API_DATABASE_CONNECTION_URL = "sqlite+aiosqlite:///:memory:"
[profiles.cloud]
PREFECT_API_URL = "<https://api.prefect.cloud/api/accounts/...>"
PREFECT_API_KEY = "your-api-key"
[profiles.prefect-cloud]
PREFECT_API_URL = "<https://api.prefect.cloud/api/accounts/...>"
PREFECT_API_KEY = "your-api-key"
Looking at your current setup:
1. Your ephemeral
profile has Cloud settings that should be in the cloud
or prefect-cloud
profile
2. You have both a cloud
and prefect-cloud
profile (you might want to consolidate these)
3. Your local
profile looks correct
4. Your test
profile looks correct
After running populate-defaults
, try switching to the ephemeral profile again:
bash
prefect profile use ephemeral
This should now work without any authentication errors since it will be properly configured for local development.
Would you like me to explain how to properly manage multiple profiles or help you consolidate your cloud profiles?