Login and logout
The huggingface_hub library allows users to programmatically login and logout the
machine to the Hub.
login
huggingface_hub.login
< source >( token: typing.Optional[str] = None add_to_git_credential: bool = False new_session: bool = True write_permission: bool = False )
Parameters
-
token (
str, optional) — User access token to generate from https://huggingface.co/settings/token. -
add_to_git_credential (
bool, defaults toFalse) — IfTrue, token will be set as git credential. If no git credential helper is configured, a warning will be displayed to the user. IftokenisNone, the value ofadd_to_git_credentialis ignored and will be prompted again to the end user. -
new_session (
bool, defaults toTrue) — IfTrue, will request a token even if one is already saved on the machine. -
write_permission (
bool, defaults toFalse) — IfTrue, requires a token with write permission.
Raises
ValueError or ImportError
ValueError— If an organization token is passed. Only personal account tokens are valid to login.ValueError— If token is invalid.ImportError— If running in a notebook butipywidgetsis not installed.
Login the machine to access the Hub.
The token is persisted in cache and set as a git credential. Once done, the machine
is logged in and the access token will be available across all huggingface_hub
components. If token is not provided, it will be prompted to the user either with
a widget (in a notebook) or via the terminal.
To login from outside of a script, one can also use huggingface-cli login which is
a cli command that wraps login().
interpreter_login
huggingface_hub.interpreter_login
< source >( new_session: bool = True write_permission: bool = False )
Displays a prompt to login to the HF website and store the token.
This is equivalent to login() without passing a token when not run in a notebook. interpreter_login() is useful if you want to force the use of the terminal prompt instead of a notebook widget.
For more details, see login().
notebook_login
huggingface_hub.notebook_login
< source >( new_session: bool = True write_permission: bool = False )
Displays a widget to login to the HF website and store the token.
This is equivalent to login() without passing a token when run in a notebook. notebook_login() is useful if you want to force the use of the notebook widget instead of a prompt in the terminal.
For more details, see login().
logout
Logout the machine from the Hub.
Token is deleted from the machine and removed from git credential.