Class: QgsUserProfileManager

A manager for QGIS user profiles.

In QGIS 3 all settings, plugins, etc were moved into a %APPDATA%/profiles folder for each platform. This allows for manage different user profiles per machine vs the single default one that was allowed in the past.

A user profile is all settings and anything that used to be found in .qgis3 in the users home folder.

Class Hierarchy

Inheritance diagram of qgis.core.QgsUserProfileManager

Base classes

QObject

Methods

allProfiles

Returns a list of all found profile names.

createUserProfile

Create a user profile given by the name

defaultProfileName

Returns the name of the default profile that has been set in .default.

deleteProfile

Deletes a profile from the root profiles folder.

getProfile

Returns the profile from the given root profile location.

isNewProfileNotificationEnabled

Returns whether the manager is watching for the creation of new user profiles and emitting the profilesChanged() signal when this occurs.

lastProfileName

Returns the name of the most recently closed profile.

loadUserProfile

Starts a new instance of QGIS for the given profile.

profileExists

Check if a profile exists.

profileForName

Returns the profile found for a given name.

rootLocation

Returns the path to the root profiles location.

rootLocationIsSet

Check if the root location has been set for the manager.

setActiveUserProfile

Sets the active profile in the manager.

setDefaultFromActive

Set the default profile name from the current active profile.

setDefaultProfileName

Sets the default profile name.

setNewProfileNotificationEnabled

Sets whether the manager should watch for the creation of new user profiles and emit the profilesChanged() signal when this occurs.

setRootLocation

Set the root profile location for the profile manager.

setUserProfileSelectionPolicy

Sets the user profile selection policy.

settings

Returns the settings for the profile manager.

userProfile

The currently active user profile.

userProfileSelectionPolicy

Returns the user profile selection policy.

Static Methods

resolveProfilesFolder

Resolves the profiles folder for the given path.

Signals

profilesChanged

Emitted when the list of profiles is changed.

class qgis.core.QgsUserProfileManager[source]

Bases: QObject

__init__(rootLocation: str | None = '', parent: QObject | None = None)

User profile manager used to manage user profiles for the instance of QGIS.

Parameters:
  • rootLocation (Optional[str] = '')

  • parent (Optional[QObject] = None)

allProfiles(self) List[str][source]

Returns a list of all found profile names.

Return type:

List[str]

createUserProfile(self, name: str | None) QgsError[source]

Create a user profile given by the name

Parameters:

name (Optional[str])

Return type:

QgsError

Returns:

A QgsError which report if there was any error creating the user profile.

defaultProfileName(self) str[source]

Returns the name of the default profile that has been set in .default. First checks profile.ini in \profiles folder Then checks defaultProfile in global settings Finally returns “default” if all else fails

Return type:

str

Returns:

The name of the default profile.

Note

Setting overrideLocalProfile in global settings will always ignore profiles.ini

deleteProfile(self, name: str | None) QgsError[source]

Deletes a profile from the root profiles folder.

Parameters:

name (Optional[str]) – The name of the profile to delete.

Return type:

QgsError

Returns:

A QgsError with a message if the profile failed to be deleted.

Note

There is no undo on this as it deletes the folder from the machine.

getProfile(self, defaultProfile: str | None = '', createNew: bool = True, initSettings: bool = True) QgsUserProfile | None[source]

Returns the profile from the given root profile location. If no name is given it returns a profile called “default”. By default will create the profile folder if not found. By default will init the user settings.

Parameters:
  • defaultProfile (Optional[str] = '') – The profile name to find. Empty profile name will return “default” for the name.

  • createNew (bool = True) – Create the profile folder if it doesn’t exist.

  • initSettings (bool = True) – if the settings should be initialized

Return type:

Optional[QgsUserProfile]

Returns:

The user profile

Note

Returns a new QgsUserProfile. Ownership transferred to caller.

isNewProfileNotificationEnabled(self) bool[source]

Returns whether the manager is watching for the creation of new user profiles and emitting the profilesChanged() signal when this occurs. By default new profile notification is disabled.

Return type:

bool

lastProfileName(self) str[source]

Returns the name of the most recently closed profile. Empty if it is the first time QGIS is run.

Added in version 3.32.

Return type:

str

loadUserProfile(self, name: str | None)[source]

Starts a new instance of QGIS for the given profile.

Parameters:

name (Optional[str]) – The profile to start QGIS with.

profileExists(self, name: str | None) bool[source]

Check if a profile exists.

Return type:

bool

Returns:

False if the profile can’t be found.

Parameters:

name (Optional[str])

profileForName(self, name: str | None) QgsUserProfile | None[source]

Returns the profile found for a given name.

Parameters:

name (Optional[str]) – The name of the profile to return.

Return type:

Optional[QgsUserProfile]

Returns:

A QgsUserprofile pointing to the location of the user profile.

signal profilesChanged[source]

Emitted when the list of profiles is changed.

This signal will only be emitted when isNewProfileNotificationEnabled() is True. By default new profile notification is disabled.

static resolveProfilesFolder(basePath: str | None = '') str[source]

Resolves the profiles folder for the given path. Path will have \profiles appended to the path

Parameters:

basePath (Optional[str] = '') – The base path to resolve the path from to append the \profiles folder to.

Return type:

str

Returns:

The root path to store user profiles.

rootLocation(self) str[source]

Returns the path to the root profiles location.

Return type:

str

Returns:

The root path to the profiles folder.

rootLocationIsSet(self) bool[source]

Check if the root location has been set for the manager.

Return type:

bool

Returns:

True if the root location has been set.

setActiveUserProfile(self, profile: str | None)[source]

Sets the active profile in the manager. This can only be set once. Setting this again does nothing.

Parameters:

profile (Optional[str]) – The name of the active profile

setDefaultFromActive(self)[source]

Set the default profile name from the current active profile.

setDefaultProfileName(self, name: str | None)[source]

Sets the default profile name. The default profile name is used when loading QGIS with no arguments.

Parameters:

name (Optional[str]) – The name of the profile to save.

setNewProfileNotificationEnabled(self, enabled: bool)[source]

Sets whether the manager should watch for the creation of new user profiles and emit the profilesChanged() signal when this occurs. By default new profile notification is disabled.

Before calling this, ensure that the correct root location has been set via calling setRootLocation().

Parameters:

enabled (bool)

setRootLocation(self, rootProfileLocation: str | None)[source]

Set the root profile location for the profile manager. All profiles are loaded from this location. Will also contain a profiles.ini for holding profile settings.

Parameters:

rootProfileLocation (Optional[str]) – Path to the top level profile folder which contains folders for each profile.

setUserProfileSelectionPolicy(self, policy: Qgis.UserProfileSelectionPolicy)[source]

Sets the user profile selection policy.

Parameters:

policy (Qgis.UserProfileSelectionPolicy) – The policy to use when selecting a user profile.

Added in version 3.32.

settings(self) QSettings | None[source]

Returns the settings for the profile manager.

Added in version 3.32.

Return type:

Optional[QSettings]

userProfile(self) QgsUserProfile | None[source]

The currently active user profile.

Return type:

Optional[QgsUserProfile]

Returns:

The currently active user profile.

userProfileSelectionPolicy(self) Qgis.UserProfileSelectionPolicy[source]

Returns the user profile selection policy.

Added in version 3.32.

Return type:

Qgis.UserProfileSelectionPolicy