in src/huggingface_hub/_login.py [0:0]
def auth_list() -> None:
"""List all stored access tokens."""
tokens = get_stored_tokens()
if not tokens:
logger.info("No access tokens found.")
return
# Find current token
current_token = get_token()
current_token_name = None
for token_name in tokens:
if tokens.get(token_name) == current_token:
current_token_name = token_name
# Print header
max_offset = max(len("token"), max(len(token) for token in tokens)) + 2
print(f" {{:<{max_offset}}}| {{:<15}}".format("name", "token"))
print("-" * (max_offset + 2) + "|" + "-" * 15)
# Print saved access tokens
for token_name in tokens:
token = tokens.get(token_name, "<not set>")
masked_token = f"{token[:3]}****{token[-4:]}" if token != "<not set>" else token
is_current = "*" if token == current_token else " "
print(f"{is_current} {{:<{max_offset}}}| {{:<15}}".format(token_name, masked_token))
if _get_token_from_environment():
logger.warning(
"\nNote: Environment variable `HF_TOKEN` is set and is the current active token independently from the stored tokens listed above."
)
elif current_token_name is None:
logger.warning(
"\nNote: No active token is set and no environment variable `HF_TOKEN` is found. Use `huggingface-cli login` to log in."
)