Skip to content

API

airvpn.web.services.api

APIKey

An AirVPN API key belonging to the authenticated user.

Constructed from the key entries returned by the APIManager manifest.

Attributes:

Name Type Description
id str | None

Unique identifier of the key.

color str | None

CSS color assigned to the key for display purposes, as an HSL string (e.g. "hsl(68,80%,87.5%)").

name str | None

Display name of the key.

secret_short str | None

Truncated/masked preview of the key's secret, safe for display.

secret str | None

The key's full secret value.

creation_date datetime

UTC timestamp of when the key was created, converted from the manifest's Unix timestamp.

APIManager

Bases: ClientService

Manages the authenticated user's AirVPN API keys.

Wraps the AJAX endpoints behind https://airvpn.org/apisettings/ to list, add, rename, and delete API keys.

Attributes:

Name Type Description
keys list[APIKey]

All API keys currently owned by the user.

add() -> APIKey

Create a new API key.

The "add" action doesn't return the new key's data, so update is called afterward to refresh keys with the newly created key.

Returns:

Name Type Description
APIKey APIKey

The most recently added api key.

delete(key: APIKey | str)

Delete an existing API key.

Parameters:

Name Type Description Default
key APIKey | str

APIKey instance or key ID to delete.

required

Raises:

Type Description
InvalidAPIKey

If key is a string ID that doesn't match any known key.

edit(key: APIKey | str, name: str)

Rename an existing API key.

Parameters:

Name Type Description Default
key APIKey | str

APIKey instance or key ID to edit.

required
name str

New name to set for the key.

required

Raises:

Type Description
InvalidAPIKey

If key is a string ID that doesn't match any known key.

edit_request(name, value, **kwargs)

Send a generic edit_<name> action to the endpoint.

Convenience wrapper around request for the common pattern of editing a single field by name.

Parameters:

Name Type Description Default
name

Name of the field to edit; sent as the edit_{name} action.

required
value

New value to set for the field.

required
**kwargs

Additional form fields to send along with the request (e.g. an id or port identifying the target record).

{}

Returns:

Type Description

The parsed JSON response from the server.

Raises:

Type Description
APIError

If the response is a dict containing a non-None "error" field.

request(action: str, is_act: bool = False, **kwargs)

Send an AJAX action request to the endpoint.

Automatically attaches the CSRF token (fetching it first if not already known) and requests an AJAX-rendered response.

Parameters:

Name Type Description Default
action str

Name of the action to perform.

required
is_act bool

If the action param is act instead.

False
**kwargs

Additional form fields to send along with the request.

{}

Returns:

Type Description

The parsed JSON response from the server.

Raises:

Type Description
APIError

If the response is a dict containing a non-None "error" field.

update(data=None)

Refresh keys from the server manifest.

Fetches the current manifest and repopulates keys and the internal key lookup map from the response.