services
ApiService
Bases: BaseService
Handles api related requests.
Source code in unkey/services/apis.py
get_api
async
Gets information about an api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_id |
str
|
The id of the api. |
required |
Returns:
Type | Description |
---|---|
ResultT[models.Api]
|
A result containing the requested information or an error. |
Source code in unkey/services/apis.py
list_keys
async
list_keys(
api_id: str,
*,
owner_id: UndefinedOr[str] = UNDEFINED,
limit: int = 100,
offset: int = 0
) -> ResultT[models.ApiKeyList]
Gets a paginated list of keys for the given api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_id |
str
|
The id of the api. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
owner_id |
UndefinedOr[str]
|
The optional owner id to list the keys for. |
limit |
int
|
The max number of keys to include in this page. Defaults to 100. |
offset |
int
|
How many keys to offset by, for pagination. |
Returns:
Type | Description |
---|---|
ResultT[models.ApiKeyList]
|
A result containing api key list or an error. |
Source code in unkey/services/apis.py
BaseService
Bases: abc.ABC
The base service all API services inherit from.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
http_service |
HttpService
|
The http service to use for requests. |
required |
serializer |
serializer.Serializer
|
The serializer to use for handling incoming JSON data from the API. |
required |
Source code in unkey/services/base.py
HttpService
The HTTP service used to make requests to the unkey API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key |
str
|
The api key to use. |
required |
api_version |
t.Optional[int]
|
The optional version of the api to use. |
required |
api_base_url |
t.Optional[str]
|
The optional api base url to use. |
required |
Source code in unkey/services/http.py
16 17 18 19 20 21 22 23 24 25 26 27 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
close
async
fetch
async
fetch(
route: routes.CompiledRoute,
*,
payload: t.Optional[t.Dict[str, t.Any]] = None
) -> dict[str, t.Any] | models.HttpResponse
Fetches the given route.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
route |
routes.CompiledRoute
|
The route to make the request to. |
required |
payload |
t.Optional[t.Dict[str, t.Any]]
|
The optional payload to send in the request body. |
None
|
Returns:
Type | Description |
---|---|
dict[str, t.Any] | models.HttpResponse
|
The requested json data or the error response. |
Source code in unkey/services/http.py
set_api_key
Sets the api key used by the http service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key |
str
|
The new api key to use. |
required |
set_base_url
Sets the api base url used by the http service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_url |
str
|
The new base url to use. |
required |
start
async
KeyService
Bases: BaseService
Handles api key related requests.
Source code in unkey/services/keys.py
22 23 24 25 26 27 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
create_key
async
create_key(
api_id: str,
owner_id: str,
prefix: str,
*,
name: UndefinedOr[str] = UNDEFINED,
byte_length: UndefinedOr[int] = UNDEFINED,
meta: UndefinedOr[t.Dict[str, t.Any]] = UNDEFINED,
expires: UndefinedOr[int] = UNDEFINED,
remaining: UndefinedOr[int] = UNDEFINED,
ratelimit: UndefinedOr[models.Ratelimit] = UNDEFINED
) -> ResultT[models.ApiKey]
Creates a new api key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
UndefinedOr[str]
|
The name to use for this key. |
UNDEFINED
|
api_id |
str
|
The id of the api this key is for. |
required |
owner_id |
str
|
The owner id to use for this key. Represents the user who will use this key. |
required |
prefix |
str
|
The prefix to place at the beginning of the key. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
byte_length |
UndefinedOr[int]
|
The optional desired length of they in bytes. Defaults to 16. |
meta |
UndefinedOr[t.Dict[str, t.Any]]
|
An optional dynamic mapping of information used to provide context around this keys user. |
expires |
UndefinedOr[int]
|
The optional number of milliseconds into the future when this key should expire. |
remaining |
UndefinedOr[int]
|
The optional max number of times this key can be used. Useful for creating long lived keys but with a limit on total uses. |
ratelimit |
UndefinedOr[models.Ratelimit]
|
The optional Ratelimit to set on this key. |
Returns:
Type | Description |
---|---|
ResultT[models.ApiKey]
|
A result containing the requested information or an error. |
Source code in unkey/services/keys.py
revoke_key
async
Revokes a keys validity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_id |
str
|
The id of the key to revoke. |
required |
Returns:
Type | Description |
---|---|
ResultT[models.HttpResponse]
|
A result containing the http response or an error. |
Source code in unkey/services/keys.py
update_key
async
update_key(
key_id: str,
*,
name: UndefinedNoneOr[str] = UNDEFINED,
owner_id: UndefinedNoneOr[str] = UNDEFINED,
meta: UndefinedNoneOr[t.Dict[str, t.Any]] = UNDEFINED,
expires: UndefinedNoneOr[int] = UNDEFINED,
remaining: UndefinedNoneOr[int] = UNDEFINED,
ratelimit: UndefinedNoneOr[models.Ratelimit] = UNDEFINED
) -> ResultT[models.HttpResponse]
Updates an existing api key. To delete a key set its value
to None
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_id |
str
|
The id of the key to update. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
name |
UndefinedNoneOr[str]
|
The new name to use for this key. |
owner_id |
UndefinedNoneOr[str]
|
The new owner id to use for this key. |
meta |
UndefinedNoneOr[t.Dict[str, t.Any]]
|
The new dynamic mapping of information used to provide context around this keys user. |
expires |
UndefinedNoneOr[int]
|
The new number of milliseconds into the future when this key should expire. |
remaining |
UndefinedNoneOr[int]
|
The new max number of times this key can be used. |
ratelimit |
UndefinedNoneOr[models.Ratelimit]
|
The new Ratelimit to set on this key. |
Returns:
Type | Description |
---|---|
ResultT[models.HttpResponse]
|
A result containing the OK response or an error. |
Source code in unkey/services/keys.py
verify_key
async
Verifies a key is valid and within ratelimit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
The key to verify. |
required |
Returns:
Type | Description |
---|---|
ResultT[models.ApiKeyVerification]
|
A result containing the api key verification or an error. |