> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-update-reference-docs-60.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# login()

export const GitHubLink = ({url, compact = false}) => <a href={url} target="_blank" rel="noopener noreferrer" className={compact ? "source-link" : "github-source-link"}>
    {compact ? "ソースを表示" : <>
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
    </svg>
    GitHub のソース
      </>}
  </a>;

<GitHubLink compact url="https://github.com/wandb/wandb/blob/main/wandb/sdk/wandb_login.py#L20" />

## <Badge color="blue" size="lg" shape="rounded">関数</Badge> wandb.login()

W\&B にログインします。

通常はこれを使用する必要はありません。認証が必要なほとんどの W\&B の method は、暗黙的にログインできるためです。これは `wandb login` CLI に対応するプログラム向けの機能です。

これにより、このセッションのグローバル認証情報が更新されます (この call 以降、現在の Python プロセス内でのすべての wandb の使用に影響します) 。また、.netrc ファイルが更新される場合もあります。

アイデンティティトークンファイルが、WANDB\_IDENTITY\_TOKEN\_FILE 環境変数などを通じて設定されている場合、セッション (フェデレーションアイデンティティ) にはそのファイルが使用され、APIキー の読み取りや保存は行われません。

それ以外の場合、明示的に APIキー が指定されていれば、それが使用され、システムの .netrc ファイルに書き込まれます。キーが指定されていない場合でも、セッションがすでに認証済みであれば、セッションキーが検証に使用され (verify が True の場合) 、.netrc ファイルは更新されません。

上記のいずれにも該当しない場合、この関数は次のうち最初に見つかったものから APIキー を取得します。

* WANDB\_API\_KEY 環境変数
* システムまたは Workspace settings ファイル内の api\_key 設定
* .netrc ファイル (~~/.netrc、~~/\_netrc、または NETRC 環境変数で指定されたパス)
* 対話型プロンプト (利用可能な場合)

```python theme={null}
key: 'str | None' = None,
relogin: 'bool | None' = None,
host: 'str | None' = None,
force: 'bool | None' = None,
timeout: 'int | None' = None,
verify: 'bool' = True,
referrer: 'str | None' = None,
anonymous: 'DoNotSet' = DoNotSet
```

<div id="args">
  ## 引数
</div>

<ResponseField name="key" type="str | None">
  使用するAPIキー。
</ResponseField>

<ResponseField name="relogin" type="bool | None">
  true の場合、.netrc、環境変数などを読み取らずに、対話型プロンプトからAPIキーを取得します。
</ResponseField>

<ResponseField name="host" type="str | None">
  接続先のW\&BサーバーのURL。
</ResponseField>

<ResponseField name="force" type="bool | None">
  true の場合、対話型プロンプトでオフラインモードを選択できなくなります。
</ResponseField>

<ResponseField name="timeout" type="int | None">
  対話型プロンプトでユーザー入力を待機する秒数。非対話型環境で対話型プロンプトが誤って表示された場合のフェイルセーフとして使用できます。
</ResponseField>

<ResponseField name="verify" type="bool">
  W\&Bサーバーで認証情報を検証し、失敗した場合はAuthenticationErrorを発生させます。APIキーだけでなく、アイデンティティトークンでも使用できます。
</ResponseField>

<ResponseField name="referrer" type="str | None">
  分析のため、URLログインリクエストで使用するリファラー。
</ResponseField>

<ResponseField name="anonymous" type="DoNotSet">
  説明はありません。
</ResponseField>

<div id="returns">
  ## 戻り値
</div>

`bool`: `key` が設定されている場合。

<div id="raises">
  ## Raises
</div>

* `AuthenticationError`: 認証情報のサーバー検証に失敗した場合。
* `UsageError`: `api_key` を設定できず、tty もない場合。
