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: t.Optional[str] = None,
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 |
t.Optional[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 WOM 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 |
|
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 |
KeyService
Bases: BaseService
Handles api key related requests.
Source code in unkey/services/keys.py
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 |
|
create_key
async
create_key(
api_id: str,
owner_id: str,
prefix: str,
*,
byte_length: int = 16,
meta: t.Dict[str, t.Any] = {},
expires: t.Optional[int] = None,
ratelimit: t.Optional[models.Ratelimit] = None
) -> ResultT[models.ApiKey]
Creates a new api key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
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 |
int
|
The optional desired length of they in bytes. Defaults to 16. |
meta |
t.Dict[str, t.Any]
|
An optional dynamic mapping of information used to provide context around this keys user. |
expires |
t.Optional[int]
|
The optional number of milliseconds into the future when this key should expire. |
ratelimit |
t.Optional[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
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. |