If you want to update the settings in your current profile in a Python script, use prefect.settings.update_current_settings
.
Here is an example:
from prefect.settings import update_current_profile
from prefect.settings import PREFECT_API_URL
update_current_profile(settings={PREFECT_API_URL: "foo"})
assert PREFECT_API_URL.value() == "foo"