Hi, Can someone explain me how from we read config...
# prefect-community
h
Hi, Can someone explain me how from we read configuration in prefect 2 from config.toml file earlier we were using
from prefect import config
what do we use in prefect 2 ?
m
Hi Hamza, I'm not sure if this is exactly what you're looking for, but I've found it useful to look at the cli code in some cases. For example in
prefect.cli.config.py
you'll see:
Copy code
context = prefect.context.get_settings_context()

    # Get settings at each level, converted to a flat dictionary for easy comparison
    default_settings = prefect.settings.get_default_settings()
    env_settings = prefect.settings.get_settings_from_env()
    current_profile_settings = context.settings
h
@Mark NS, i am specifically looking how i can read configuration from toml file in prefect 2, not sure if this allow us to do that but i can check and see if it works for me.
m
Well if you really only want to read the toml file, there is the direct approach: https://docs.python.org/3/library/tomllib.html
z
Hi! What are you trying to do more specifically?
Prefect 2 has profiles so the config is a little more complex
https://docs.prefect.io/api-ref/prefect/settings/#prefect.settings has a description explaining the implementation of settings
h
@Zanie, this means that toml files are depreciated in prefect2 ?
My prefect .toml file looks like this
Copy code
[myprofile]
remote_path = "some_path"
host = "my_host"
port = 89
earliest_date = "2015-06-01"
Now i am upgrading to prefect2 how can i use this configuration in prefect2 This how I am reading them currently
Copy code
from prefect import config

#read config
print(config.myprofile.host)
z
The Prefect config cannot be used for storing arbitrary data, it’s for Prefect settings only. You can read a toml file as described by Mark above?