Authentication (Python)

Authentication is the first step most applications will need to perform in order to manipulate their team's assets.

For the case of Authentication, we will be focused on the Client module, a class that has all the necessary methods you need to authenticate yourself.

1. Client.local(team_slug: Optional[str] = None):

The local authentication method has a global effect, meaning that it is global to your local machine. Authentication via this method will use the configurations in ~/.darwin/config.yaml.
The authentication here can be done with the team_slug, which defaults to none. This means that if you authenticate in the wrong team you won't have access to your assets. You will however, always have access to public assets, such as public datasets.
Returns the initialized client.

from darwin.client import Client

client = Client.local("my-team-slug")

2. Client.from_config(config_path: Path, team_slug: Optional[str] = None):

Returns the initialized client using the configuration file passed as a parameter.
Just like the previous function, you can optionally pass a team_slug which defaults to None.

from darwin.client import Client
from pathlib import Path

client = Client.from_config(Path("~/my_config.yaml"), "my-team-slug")

3. Client.from_guest(datasets_dir: Optional[Path] = None):

Authenticates the client as a guest. You can pass in dataset_dir as place where the client should be initialized (root path). The default path is ~/darwin/datasets".

from darwin.client import Client
from pathlib import Path

client = Client.from_guest(Path("dataset_path"))

4. Client.from_api_key(api_key: str, datasets_dir: Optional[Path] = None):

Authenticates the client with the given API key. You can pass in dataset_dir as place where the client should be initialized (root path). The default path is ~/darwin/datasets".
Returns the initialized client.

from darwin.client import Client

client = Client.from_api_key("MY_API_KEY", "dataset_path")

5. Common issues when authenticating

Unauthorized

One common issue is getting permissions denied. This can happen if you are authenticating with the wrong team-slug, always make sure you are authenticating as part of the correct teams.
Another possible cause for this is that your API key (if you are using one) was not built with the right access permissions.