Skip to content

Configuration

Authentication

toggl_api.config.AuthenticationError

Bases: ValueError

Authentication failed or was not provided.

toggl_api.config.generate_authentication

generate_authentication() -> BasicAuth

Gather 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 DESCRIPTION
AuthenticationError

If credentials are not set or invalid.

RETURNS DESCRIPTION
BasicAuth

BasicAuth object that is used with HTTPx client.

toggl_api.config.use_togglrc

use_togglrc(config_path: Path | None = None) -> BasicAuth

Gather 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...>
PARAMETER DESCRIPTION
config_path

Path to .togglrc folder not file. If None, will use $HOME/.togglrc for the default location.

TYPE: Path | None DEFAULT: None

RAISES DESCRIPTION
AuthenticationError

If credentials are not set or invalid.

RETURNS DESCRIPTION
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

retrieve_workspace_id(default: int | None = None) -> int

Collect the default workspace from the environment.

Examples:

>>> retrieve_workspace_id()
>>> retrieve_workspace_id(214812815)
PARAMETER DESCRIPTION
default

Workspace id alternative if not set through environment.

TYPE: int | None DEFAULT: None

RAISES DESCRIPTION
WorkspaceMissingError

If no workspace was found at the TOGGL_WORKSPACE_ID variable or the workspace set is not an integer.

RETURNS DESCRIPTION
int

The id of the workspace.

toggl_api.config.retrieve_togglrc_workspace_id

retrieve_togglrc_workspace_id(config_path: Path | None = None) -> int

Collect the default workspace id from a togglrc file.

Examples:

>>> retrieve_togglrc_workspace_id()
PARAMETER DESCRIPTION
config_path

Alternative path to folder that contains the togglrc file.

TYPE: Path | None DEFAULT: None

RAISES DESCRIPTION
FileNotFoundError

If a togglrc file has not been found.

WorkspaceMissingError

If no workspace is found or the workspace is invalid.

RETURNS DESCRIPTION
int

The id of the workspace.