Configuration
Authentication¶
toggl_api.config.AuthenticationError
¶
Bases: ValueError
Authentication failed or was not provided.
toggl_api.config.generate_authentication() -> BasicAuth
¶
Gathers credentials from environment variables.
If using an API token as authentication: TOGGL_API_TOKEN.
If using email as authentication: TOGGL_API_TOKEN & TOGGL_PASSWORD.
Examples:
>>> generate_authentication()
<httpx.BasicAuth object at 0x...>
Raises:
-
AuthenticationError
–If credentials are not set or invalid.
Returns:
-
BasicAuth
–BasicAuth object that is used with Httpx client.
toggl_api.config.use_togglrc(config_path: Optional[Path] = None) -> BasicAuth
¶
Gathers credentials from a .togglrc file.
Mainly here for togglcli backwards compatibility.
Examples:
>>> use_togglrc()
<httpx.BasicAuth object at 0x...>
>>> use_togglrc(Path("home/dk/.config/"))
<httpx.BasicAuth object at 0x...>
Parameters:
-
config_path
(Optional[Path]
, default:None
) –Path to .togglrc folder not file. If None, will use $HOME/.togglrc for the default location.
Raises:
-
AuthenticationError
–If credentials are not set or invalid.
Returns:
-
BasicAuth
–BasicAuth object that is used with httpx client.
Note
The UserEndpoint has a verify_authentication method for verifying authentication with the Toggl API.
Default Workspace¶
toggl_api.config.retrieve_workspace_id(default: Optional[int] = None) -> int
¶
Helper function that collect the default workspace from the environment.
Examples:
>>> retrieve_workspace_id()
>>> retrieve_workspace_id(214812815)
Parameters:
-
default
(Optional[int]
, default:None
) –Workspace id alternative if not set through environment.
Raises:
-
ValueError
–If no workspace was found at the TOGGL_WORKSPACE_ID variable or the workspace set is not an integer.
Returns:
-
int
–The id of the workspace.
toggl_api.config.retrieve_togglrc_workspace_id(config_path: Optional[Path] = None) -> int
¶
Helper function that collects the default workspace id from a togglrc file.
Examples:
>>> retrieve_togglrc_workspace_id()
Parameters:
-
config_path
(Optional[Path]
, default:None
) –Alternative path to folder that contains the togglrc file.
Raises:
-
FileNotFoundError
–If a togglrc file has not been found.
-
NoSectionError
–If no option section is found in the config file.
-
NoOptionError
–If no 'default_wid' section is found in the config file.
-
ValueError
–If the workspace value is not an integer.
Returns:
-
int
–The id of the workspace.