Reference for ultralytics/hub/auth.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/auth.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.hub.auth.Auth
Auth(api_key: str = '', verbose: bool = False)
Manages authentication processes including API key handling, cookie-based authentication, and header generation.
The class supports different methods of authentication: 1. Directly using an API key. 2. Authenticating using browser cookies (specifically in Google Colab). 3. Prompting the user to enter an API key.
Attributes:
Name | Type | Description |
---|---|---|
id_token |
str | bool
|
Token used for identity verification, initialized as False. |
api_key |
str | bool
|
API key for authentication, initialized as False. |
model_key |
bool
|
Placeholder for model key, initialized as False. |
Handles API key validation, Google Colab authentication, and new key requests. Updates SETTINGS upon successful authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str
|
API key or combined key_id format. |
''
|
verbose
|
bool
|
Enable verbose logging. |
False
|
Source code in ultralytics/hub/auth.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
auth_with_cookies
auth_with_cookies() -> bool
Attempt to fetch authentication via cookies and set id_token.
User must be logged in to HUB and running in a supported browser.
Returns:
Type | Description |
---|---|
bool
|
True if authentication is successful, False otherwise. |
Source code in ultralytics/hub/auth.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
authenticate
authenticate() -> bool
Attempt to authenticate with the server using either id_token or API key.
Returns:
Type | Description |
---|---|
bool
|
True if authentication is successful, False otherwise. |
Source code in ultralytics/hub/auth.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
get_auth_header
get_auth_header()
Get the authentication header for making API requests.
Returns:
Type | Description |
---|---|
dict | None
|
The authentication header if id_token or API key is set, None otherwise. |
Source code in ultralytics/hub/auth.py
126 127 128 129 130 131 132 133 134 135 136 |
|
request_api_key
request_api_key(max_attempts: int = 3) -> bool
Prompt the user to input their API key.
Source code in ultralytics/hub/auth.py
73 74 75 76 77 78 79 80 81 82 83 |
|