Linode Client

The LinodeClient is responsible for managing your connection to the API using your token. A LinodeClient is required for all connections to the API, and a reference to one is required by every model. A LinodeClient is created with a token, either an OAuth Token from the OAuth Exchange (see oauth for more information) or a Personal Access Token. See our getting_started guide for more information:

from linode_api4 import LinodeClient

token = "api-token" # your token goes here

client = LinodeClient(token)

Grouping

The LinodeClient class is divided into groups following the API’s overall design - some methods and functions are accessible only through members of the LinodeClient class:

# access an ungrouped member
client.regions() # /regions

# access a grouped member - note the URL matches the grouping
client.linode.instances() # /linode/instances

The LinodeClient itself holds top-level collections of the API, while anything that exists under a group in the API belongs to a member of the client.

LinodeClient class

class linode_api4.LinodeClient(token, base_url='https://api.linode.com/v4', user_agent=None, page_size=None, retry=True, retry_rate_limit_interval=1.0, retry_max=5, retry_statuses=None, ca_path=None)[source]
__init__(token, base_url='https://api.linode.com/v4', user_agent=None, page_size=None, retry=True, retry_rate_limit_interval=1.0, retry_max=5, retry_statuses=None, ca_path=None)[source]

The main interface to the Linode API.

Parameters:
  • token (str) – The authentication token to use for communication with the API. Can be either a Personal Access Token or an OAuth Token.

  • base_url (str) – The base URL for API requests. Generally, you shouldn’t change this.

  • user_agent (str) – What to append to the User Agent of all requests made by this client. Setting this allows Linode’s internal monitoring applications to track the usage of your application. Setting this is not necessary, but some applications may desire this behavior.

  • page_size (int) – The default size to request pages at. If not given, the API’s default page size is used. Valid values can be found in the API docs, but at time of writing are between 25 and 500.

  • retry (bool) – Whether API requests should automatically be retries on known intermittent responses.

  • retry_rate_limit_interval (Union[float, int]) – The amount of time to wait between HTTP request retries.

  • retry_max (int) – The number of request retries that should be attempted before raising an API error.

  • retry_statuses (List of int) – Additional HTTP response statuses to retry on. By default, the client will retry on 408, 429, and 502 responses.

  • ca_path (str) – The path to a CA file to use for API requests in this client.

account

Access methods related to your account - see AccountGroup for more information

beta

Access methods related to Beta Program - See BetaProgramGroup for more information.

database

Access methods related to Managed Databases - see DatabaseGroup for more information.

domain_create(domain, master=True, **kwargs)[source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.domains.create(...) for all new projects.

domains

Access methods related to Domains - see DomainGroup for more information.

image_create(disk, label=None, description=None)[source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.images.create(...) for all new projects.

image_create_upload(label: str, region: str, description: str = None) Tuple[Image, str][source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.images.create_upload(...) for all new projects.

image_upload(label: str, region: str, file: BinaryIO, description: str = None) Image[source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.images.upload(...) for all new projects.

images

Access methods related to Images - See ImageGroup for more information.

linode

Access methods related to Linodes - see LinodeGroup for more information

lke

Access methods related to LKE - see LKEGroup for more information.

load(target_type, target_id, target_parent_id=None)[source]

Constructs and immediately loads the object, circumventing the lazy-loading scheme by immediately making an API request. Does not load related objects.

For example, if you wanted to load an Instance object with ID 123, you could do this:

loaded_linode = client.load(Instance, 123)

Similarly, if you instead wanted to load a NodeBalancerConfig, you could do so like this:

loaded_nodebalancer_config = client.load(NodeBalancerConfig, 456, 432)
Parameters:
  • target_type (type) – The type of object to create.

  • target_id (int or str) – The ID of the object to create.

  • target_parent_id (int, str, or None) – The parent ID of the object to create, if applicable.

Returns:

The resulting object, fully loaded.

Return type:

target_type

Raises:

ApiError – if the requested object could not be loaded.

longview

Access information related to the Longview service - see LongviewGroup for more information

networking

Access methods related to networking on your account - see NetworkingGroup for more information

nodebalancer_create(region, **kwargs)[source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.nodebalancers.create(...) for all new projects.

nodebalancers

Access methods related to NodeBalancers - see NodeBalancerGroup for more information.

object_storage

Access methods related to Object Storage - see ObjectStorageGroup for more information

polling

Access methods related to Event polling - See PollingGroup for more information.

profile

Access methods related to your user - see ProfileGroup for more information

regions

Access methods related to Regions - See RegionGroup for more information.

support

Access methods related to support - see SupportGroup for more information

tag_create(label, instances=None, domains=None, nodebalancers=None, volumes=None, entities=[])[source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.tags.create(...) for all new projects.

tags

Access methods related to Tags - See TagGroup for more information.

volume_create(label, region=None, linode=None, size=20, **kwargs)[source]

Note

This method is an alias to maintain backwards compatibility. Please use LinodeClient.volumes.create(...) for all new projects.

volumes

Access methods related to Volumes - See VolumeGroup for more information.

vpcs

Access methods related to VPCs - See VPCGroup for more information.

Groups

These groups are accessed off of the LinodeClient class by name. For example:

client.linode.instances()

See LinodeClient for more information on the naming of these groups, although generally they are named the same as the first word of the group.

AccountGroup

Includes methods for managing your account.

class linode_api4.linode_client.AccountGroup(client: LinodeClient)[source]

Collections related to your account.

__call__()[source]

Retrieves information about the acting user’s account, such as billing information. This is intended to be called off of the LinodeClient class, like this:

account = client.account()

API Documentation: https://www.linode.com/docs/api/account/#account-view

Returns:

Returns the acting user’s account information.

Return type:

Account

add_payment_method(data, is_default, type)[source]

Adds a Payment Method to your Account with the option to set it as the default method.

API Documentation: https://www.linode.com/docs/api/account/#payment-method-add

Parameters:

data (dict) – An object representing the credit card information you have on file with Linode to make Payments against your Account.

Example usage::
data = {

“card_number”: “4111111111111111”, “expiry_month”: 11, “expiry_year”: 2020, “cvv”: “111”

}

Parameters:
  • is_default (bool) – Whether this Payment Method is the default method for automatically processing service charges.

  • type (str) – The type of Payment Method. Enum: [“credit_card]

add_promo_code(promo_code)[source]

Adds an expiring Promo Credit to your account.

API Documentation: https://www.linode.com/docs/api/account/#promo-credit-add

Parameters:

promo_code (str) – The Promo Code.

availabilities(*filters)[source]

Returns a list of all available regions and the resource types which are available to the account.

API doc: https://www.linode.com/docs/api/account/#region-service-availability

Returns:

a list of region availability information.

Return type:

PaginatedList of AccountAvailability

enrolled_betas(*filters)[source]

Returns a list of all Beta Programs an account is enrolled in.

API doc: https://www.linode.com/docs/api/beta-programs/#enrolled-beta-programs-list

Returns:

a list of Beta Programs.

Return type:

PaginatedList of AccountBetaProgram

events(*filters)[source]

Lists events on the current account matching the given filters.

API Documentation: https://www.linode.com/docs/api/account/#events-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of events on the current account matching the given filters.

Return type:

PaginatedList of Event

events_mark_seen(event)[source]

Marks event as the last event we have seen. If event is an int, it is treated as an event_id, otherwise it should be an event object whose id will be used.

API Documentation: https://www.linode.com/docs/api/account/#event-mark-as-seen

Parameters:

event (Event or int) – The Linode event to mark as seen.

invoices()[source]

Returns Invoices issued to this account.

API Documentation: https://www.linode.com/docs/api/account/#invoices-list

Parameters:

filters – Any number of filters to apply to this query.

Returns:

Invoices issued to this account.

Return type:

PaginatedList of Invoice

join_beta_program(beta: str | BetaProgram)[source]

Enrolls an account into a beta program.

API doc: https://www.linode.com/docs/api/beta-programs/#beta-program-enroll

Parameters:

beta (BetaProgram or str) – The object or id of a beta program to join.

Returns:

A boolean indicating whether the account joined a beta program successfully.

Return type:

bool

linode_managed_enable()[source]

Enables Linode Managed for the entire account and sends a welcome email to the account’s associated email address.

API Documentation: https://www.linode.com/docs/api/account/#linode-managed-enable

logins()[source]

Returns a collection of successful logins for all users on the account during the last 90 days.

API Documentation: https://www.linode.com/docs/api/account/#user-logins-list-all

Returns:

A list of Logins on this account.

Return type:

PaginatedList of Login

maintenance()[source]

Returns a collection of Maintenance objects for any entity a user has permissions to view. Cancelled Maintenance objects are not returned.

API Documentation: https://www.linode.com/docs/api/account/#user-logins-list-all

Returns:

A list of Maintenance objects on this account.

Return type:

List of Maintenance objects as MappedObjects

notifications()[source]

Returns a collection of Notification objects representing important, often time-sensitive items related to your Account.

API Documentation: https://www.linode.com/docs/api/account/#notifications-list

Returns:

A list of Notifications on this account.

Return type:

List of Notification objects as MappedObjects

oauth_client_create(name, redirect_uri, **kwargs)[source]

Creates a new OAuth client.

API Documentation: https://www.linode.com/docs/api/account/#oauth-client-create

Parameters:
  • name (str) – The name of this application.

  • redirect_uri (str) – The location a successful log in from https://login.linode.com should be redirected to for this client.

Returns:

The created OAuth Client.

Return type:

OAuthClient

oauth_clients(*filters)[source]

Returns the OAuth Clients associated with this account.

API Documentation: https://www.linode.com/docs/api/account/#oauth-clients-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of OAuth Clients associated with this account.

Return type:

PaginatedList of OAuthClient

payment_methods()[source]

Returns a list of Payment Methods for this Account.

API Documentation: https://www.linode.com/docs/api/account/#payment-methods-list

Returns:

A list of Payment Methods on this account.

Return type:

PaginatedList of PaymentMethod

payments()[source]

Returns a list of Payments made on this account.

API Documentation: https://www.linode.com/docs/api/account/#payments-list

Returns:

A list of payments made on this account.

Return type:

PaginatedList of Payment

service_transfer_create(entities)[source]

Creates a transfer request for the specified services.

API Documentation: https://www.linode.com/docs/api/account/#service-transfer-create

Parameters:

entities (dict) – A collection of the services to include in this transfer request, separated by type.

Example usage::
entities = {
“linodes”: [

111, 222

]

}

service_transfers()[source]

Returns a collection of all created and accepted Service Transfers for this account, regardless of the user that created or accepted the transfer.

API Documentation: https://www.linode.com/docs/api/account/#service-transfers-list

Returns:

A list of Service Transfers on this account.

Return type:

PaginatedList of ServiceTransfer

settings()[source]

Returns the account settings data for this acocunt. This is not a listing endpoint.

API Documentation: https://www.linode.com/docs/api/account/#account-settings-view

Returns:

The account settings data for this account.

Return type:

AccountSettings

transfer()[source]

Returns a MappedObject containing the account’s transfer pool data.

API Documentation: https://www.linode.com/docs/api/account/#network-utilization-view

Returns:

Information about this account’s transfer pool data.

Return type:

MappedObject

user_create(email, username, restricted=True)[source]

Creates a new user on your account. If you create an unrestricted user, they will immediately be able to access everything on your account. If you create a restricted user, you must grant them access to parts of your account that you want to allow them to manage (see User.grants for details).

The new user will receive an email inviting them to set up their password. This must be completed before they can log in.

API Documentation: https://www.linode.com/docs/api/account/#user-create

Parameters:
  • email (str) – The new user’s email address. This is used to finish setting up their user account.

  • username (str) – The new user’s unique username. They will use this username to log in.

  • restricted (True) – If True, the new user must be granted access to parts of the account before they can do anything. If False, the new user will immediately be able to manage the entire account. Defaults to True.

:returns The new User. :rtype: User

users(*filters)[source]

Returns a list of users on this account.

API Documentation: https://www.linode.com/docs/api/account/#users-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of users on this account.

Return type:

PaginatedList of User

BetaGroup

Includes methods for enrolling in beta programs.

DatabaseGroup

Includes methods for managing Linode Managed Databases.

class linode_api4.linode_client.DatabaseGroup(client: LinodeClient)[source]

Encapsulates Linode Managed Databases related methods of the LinodeClient. This should not be instantiated on its own, but should instead be used through an instance of LinodeClient:

client = LinodeClient(token)
instances = client.database.instances() # use the DatabaseGroup

This group contains all features beneath the /databases group in the API v4.

engines(*filters)[source]

Returns a list of Linode Managed Database Engines. These may be used to create Managed Databases, or simply referenced to on their own. Engines can be filtered to return specific engines, for example:

mysql_engines = client.database.engines(DatabaseEngine.engine == 'mysql')

API Documentation: https://www.linode.com/docs/api/databases/#managed-database-engines-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of types that match the query.

Return type:

PaginatedList of DatabaseEngine

instances(*filters)[source]

Returns a list of Managed Databases active on this account.

API Documentation: https://www.linode.com/docs/api/databases/#managed-databases-list-all

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of databases that matched the query.

Return type:

PaginatedList of Database

mysql_create(label, region, engine, ltype, **kwargs)[source]

Creates an MySQLDatabase on this account with the given label, region, engine, and node type. For example:

client = LinodeClient(TOKEN)

# look up Region and Types to use.  In this example I'm just using
# the first ones returned.
region = client.regions().first()
node_type = client.database.types()[0]
engine = client.database.engines(DatabaseEngine.engine == 'mysql')[0]

new_database = client.database.mysql_create(
    "example-database",
    region,
    engine.id,
    type.id
 )

API Documentation: https://www.linode.com/docs/api/databases/#managed-mysql-database-create

Parameters:
  • label (str) – The name for this cluster

  • region (str or Region) – The region to deploy this cluster in

  • engine (str or Engine) – The engine to deploy this cluster with

  • ltype (str or Type) – The Linode Type to use for this cluster

mysql_instances(*filters)[source]

Returns a list of Managed MySQL Databases active on this account.

API Documentation: https://www.linode.com/docs/api/databases/#managed-mysql-databases-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of MySQL databases that matched the query.

Return type:

PaginatedList of MySQLDatabase

postgresql_create(label, region, engine, ltype, **kwargs)[source]

Creates an PostgreSQLDatabase on this account with the given label, region, engine, and node type. For example:

client = LinodeClient(TOKEN)

# look up Region and Types to use.  In this example I'm just using
# the first ones returned.
region = client.regions().first()
node_type = client.database.types()[0]
engine = client.database.engines(DatabaseEngine.engine == 'postgresql')[0]

new_database = client.database.postgresql_create(
    "example-database",
    region,
    engine.id,
    type.id
 )

API Documentation: https://www.linode.com/docs/api/databases/#managed-postgresql-database-create

Parameters:
  • label (str) – The name for this cluster

  • region (str or Region) – The region to deploy this cluster in

  • engine (str or Engine) – The engine to deploy this cluster with

  • ltype (str or Type) – The Linode Type to use for this cluster

postgresql_instances(*filters)[source]

Returns a list of Managed PostgreSQL Databases active on this account.

API Documentation: https://www.linode.com/docs/api/databases/#managed-postgresql-databases-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of PostgreSQL databases that matched the query.

Return type:

PaginatedList of PostgreSQLDatabase

types(*filters)[source]

Returns a list of Linode Database-compatible Instance types. These may be used to create Managed Databases, or simply referenced to on their own. DatabaseTypes can be filtered to return specific types, for example:

database_types = client.database.types(DatabaseType.deprecated == False)

API Documentation: https://www.linode.com/docs/api/databases/#managed-database-types-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of types that match the query.

Return type:

PaginatedList of DatabaseType

DomainGroup

Includes methods for managing Linode Domains.

class linode_api4.linode_client.DomainGroup(client: LinodeClient)[source]
__call__(*filters)[source]

Retrieves all of the Domains the acting user has access to.

This is intended to be called off of the LinodeClient class, like this:

domains = client.domains()

API Documentation: https://www.linode.com/docs/api/domains/#domains-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Domains the acting user can access.

Return type:

PaginatedList of Domain

create(domain, master=True, **kwargs)[source]

Registers a new Domain on the acting user’s account. Make sure to point your registrar to Linode’s nameservers so that Linode’s DNS manager will correctly serve your domain.

API Documentation: https://www.linode.com/docs/api/domains/#domain-create

Parameters:
  • domain (str) – The domain to register to Linode’s DNS manager.

  • master (bool) – Whether this is a master (defaults to true)

  • tags (list[str]) – A list of tags to apply to the new domain. If any of the tags included do not exist, they will be created as part of this operation.

Returns:

The new Domain object.

Return type:

Domain

ImageGroup

Includes methods for managing Linode Images.

class linode_api4.linode_client.ImageGroup(client: LinodeClient)[source]
__call__(*filters)[source]

Retrieves a list of available Images, including public and private Images available to the acting user. You can filter this query to retrieve only Images relevant to a specific query, for example:

debian_images = client.images(
    Image.vendor == "debain")

API Documentation: https://www.linode.com/docs/api/images/#images-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of available Images.

Return type:

PaginatedList of Image

create(disk, label=None, description=None, cloud_init=False)[source]

Creates a new Image from a disk you own.

API Documentation: https://www.linode.com/docs/api/images/#image-create

Parameters:
  • disk (Disk or int) – The Disk to imagize.

  • label (str) – The label for the resulting Image (defaults to the disk’s label.

  • description (str) – The description for the new Image.

  • cloud_init (bool) – Whether this Image supports cloud-init.

Returns:

The new Image.

Return type:

Image

create_upload(label: str, region: str, description: str = None, cloud_init: bool = False) Tuple[Image, str][source]

Creates a new Image and returns the corresponding upload URL.

API Documentation: https://www.linode.com/docs/api/images/#image-upload

Parameters:
  • label (str) – The label of the Image to create.

  • region (str) – The region to upload to. Once the image has been created, it can be used in any region.

  • description (str) – The description for the new Image.

  • cloud_init (bool) – Whether this Image supports cloud-init.

Returns:

A tuple containing the new image and the image upload URL.

Return type:

(Image, str)

upload(label: str, region: str, file: BinaryIO, description: str = None) Image[source]

Creates and uploads a new image.

API Documentation: https://www.linode.com/docs/api/images/#image-upload

Parameters:
  • label (str) – The label of the Image to create.

  • region (str) – The region to upload to. Once the image has been created, it can be used in any region.

  • file – The BinaryIO object to upload to the image. This is generally obtained from open(“myfile”, “rb”).

  • description (str) – The description for the new Image.

Returns:

The resulting image.

Return type:

Image

LinodeGroup

Includes methods for managing and creating Linode Instances, as well as accessing and working with associated features.

class linode_api4.linode_client.LinodeGroup(client: LinodeClient)[source]

Encapsulates Linode-related methods of the LinodeClient. This should not be instantiated on its own, but should instead be used through an instance of LinodeClient:

client = LinodeClient(token)
instances = client.linode.instances() # use the LinodeGroup

This group contains all features beneath the /linode group in the API v4.

static build_instance_metadata(user_data=None, encode_user_data=True)[source]

Builds the contents of the metadata field to be passed into the instance_create method. This helper can also be used when cloning and rebuilding Instances. Creating an Instance with User Data:

new_linode, password = client.linode.instance_create(
    "g6-standard-2",
    "us-east",
    image="linode/ubuntu22.04",
    metadata=client.linode.build_instance_metadata(user_data="myuserdata")
)
Parameters:
  • user_data (str) – User-defined data to provide to the Linode Instance through the Metadata service.

  • encode_user_data (bool) – If true, the provided user_data field will be automatically encoded to a valid base64 string. This field should only be set to false if the user_data param is already base64-encoded.

Returns:

The built metadata structure.

Return type:

dict

instance_create(ltype, region, image=None, authorized_keys=None, **kwargs)[source]

Creates a new Linode Instance. This function has several modes of operation:

Create an Instance from an Image

To create an Instance from an Image, call instance_create with a Type, a Region, and an Image. All three of these fields may be provided as either the ID or the appropriate object. In this mode, a root password will be generated and returned with the new Instance object.

For example:

new_linode, password = client.linode.instance_create(
    "g6-standard-2",
    "us-east",
    image="linode/debian9")

ltype = client.linode.types().first()
region = client.regions().first()
image = client.images().first()

another_linode, password = client.linode.instance_create(
    ltype,
    region,
    image=image)
To output the password from the above example:

print(password)

To output the first IPv4 address of the new Linode:

print(new_linode.ipv4[0])

To delete the new_linode (WARNING: this immediately destroys the Linode):

new_linode.delete()

Create an Instance from StackScript

When creating an Instance from a StackScript, an Image that the StackScript support must be provided.. You must also provide any required StackScript data for the script’s User Defined Fields.. For example, if deploying StackScript 10079 (which deploys a new Instance with a user created from keys on github:

stackscript = StackScript(client, 10079)

new_linode, password = client.linode.instance_create(
   "g6-standard-2",
   "us-east",
   image="linode/debian9",
   stackscript=stackscript,
   stackscript_data={"gh_username": "example"})

In the above example, “gh_username” is the name of a User Defined Field in the chosen StackScript. For more information on StackScripts, see the StackScript guide.

Create an Instance from a Backup

To create a new Instance by restoring a Backup to it, provide a Type, a Region, and the Backup to restore. You may provide either IDs or objects for all of these fields:

existing_linode = Instance(client, 123)
snapshot = existing_linode.available_backups.snapshot.current

new_linode = client.linode.instance_create(
    "g6-standard-2",
    "us-east",
    backup=snapshot)

Create an empty Instance

If you want to create an empty Instance that you will configure manually, simply call instance_create with a Type and a Region:

empty_linode = client.linode.instance_create("g6-standard-2", "us-east")

When created this way, the Instance will not be booted and cannot boot successfully until disks and configs are created, or it is otherwise configured.

API Documentation: https://www.linode.com/docs/api/linode-instances/#linode-create

Parameters:
  • ltype (str or Type) – The Instance Type we are creating

  • region (str or Region) – The Region in which we are creating the Instance

  • image (str or Image) – The Image to deploy to this Instance. If this is provided and no root_pass is given, a password will be generated and returned along with the new Instance.

  • stackscript (int or StackScript) – The StackScript to deploy to the new Instance. If provided, “image” is required and must be compatible with the chosen StackScript.

  • stackscript_data (dict) – Values for the User Defined Fields defined in the chosen StackScript. Does nothing if StackScript is not provided.

  • backup (int of Backup) – The Backup to restore to the new Instance. May not be provided if “image” is given.

  • authorized_keys (list or str) – The ssh public keys to install in the linode’s /root/.ssh/authorized_keys file. Each entry may be a single key, or a path to a file containing the key.

  • label (str) – The display label for the new Instance

  • group (str) – The display group for the new Instance

  • booted (bool) – Whether the new Instance should be booted. This will default to True if the Instance is deployed from an Image or Backup.

  • tags (list[str]) – A list of tags to apply to the new instance. If any of the tags included do not exist, they will be created as part of this operation.

  • private_ip (bool) – Whether the new Instance should have private networking enabled and assigned a private IPv4 address.

  • metadata (dict) – Metadata-related fields to use when creating the new Instance. The contents of this field can be built using the build_instance_metadata method.

  • firewall (int or Firewall) – The firewall to attach this Linode to.

  • interfaces (list[ConfigInterface] or list[dict[str, Any]]) – An array of Network Interfaces to add to this Linode’s Configuration Profile. At least one and up to three Interface objects can exist in this array.

Returns:

A new Instance object, or a tuple containing the new Instance and the generated password.

Return type:

Instance or tuple(Instance, str)

Raises:
  • ApiError – If contacting the API fails

  • UnexpectedResponseError – If the API response is somehow malformed. This usually indicates that you are using an outdated library.

instances(*filters)[source]

Returns a list of Linode Instances on your account. You may filter this query to return only Linodes that match specific criteria:

prod_linodes = client.linode.instances(Instance.group == "prod")

API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Instances that matched the query.

Return type:

PaginatedList of Instance

kernels(*filters)[source]

Returns a list of available Kernels. Kernels are used when creating or updating LinodeConfigs,LinodeConfig>.

API Documentation: https://www.linode.com/docs/api/linode-instances/#kernels-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of available kernels that match the query.

Return type:

PaginatedList of Kernel

stackscript_create(label, script, images, desc=None, public=False, **kwargs)[source]

Creates a new StackScript on your account.

API Documentation: https://www.linode.com/docs/api/stackscripts/#stackscript-create

Parameters:
  • label (str) – The label for this StackScript.

  • script (str) – The script to run when an Instance is deployed with this StackScript. Must begin with a shebang (#!).

  • images (list of Image) – A list of Images that this StackScript supports. Instances will not be deployed from this StackScript unless deployed from one of these Images.

  • desc (str) – A description for this StackScript.

  • public (bool) – Whether this StackScript is public. Defaults to False. Once a StackScript is made public, it may not be set back to private.

Returns:

The new StackScript

Return type:

StackScript

stackscripts(*filters, **kwargs)[source]

Returns a list of StackScripts, both public and private. You may filter this query to return only StackScripts that match certain criteria. You may also request only your own private StackScripts:

my_stackscripts = client.linode.stackscripts(mine_only=True)

API Documentation: https://www.linode.com/docs/api/stackscripts/#stackscripts-list

Parameters:
  • filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

  • mine_only (bool) – If True, returns only private StackScripts

Returns:

A list of StackScripts matching the query.

Return type:

PaginatedList of StackScript

types(*filters)[source]

Returns a list of Linode Instance types. These may be used to create or resize Linodes, or simply referenced on their own. Types can be filtered to return specific types, for example:

standard_types = client.linode.types(Type.class == "standard")

API documentation: https://www.linode.com/docs/api/linode-types/#types-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of types that match the query.

Return type:

PaginatedList of Type

LKEGroup

Includes methods for interacting with Linode Kubernetes Engine.

class linode_api4.linode_client.LKEGroup(client: LinodeClient)[source]

Encapsulates LKE-related methods of the LinodeClient. This should not be instantiated on its own, but should instead be used through an instance of LinodeClient:

client = LinodeClient(token)
instances = client.lke.clusters() # use the LKEGroup

This group contains all features beneath the /lke group in the API v4.

cluster_create(region, label, node_pools, kube_version, **kwargs)[source]

Creates an LKECluster on this account in the given region, with the given label, and with node pools as described. For example:

client = LinodeClient(TOKEN)

# look up Region and Types to use.  In this example I'm just using
# the first ones returned.
target_region = client.regions().first()
node_type = client.linode.types()[0]
node_type_2 = client.linode.types()[1]
kube_version = client.lke.versions()[0]

new_cluster = client.lke.cluster_create(
    target_region,
    "example-cluster",
    [client.lke.node_pool(node_type, 3), client.lke.node_pool(node_type_2, 3)],
    kube_version
 )

API Documentation: https://www.linode.com/docs/api/linode-kubernetes-engine-lke/#kubernetes-cluster-create

Parameters:
  • region (Region or str) – The Region to create this LKE Cluster in.

  • label (str) – The label for the new LKE Cluster.

  • node_pools (one or a list of dicts containing keys “type” and “count”. See node_pool for a convenient way to create correctly- formatted dicts.) – The Node Pools to create.

  • kube_version (KubeVersion or str) – The version of Kubernetes to use

  • kwargs – Any other arguments to pass along to the API. See the API docs for possible values.

Returns:

The new LKE Cluster

Return type:

LKECluster

clusters(*filters)[source]

Returns a PaginagtedList of LKECluster objects that belong to this account.

https://www.linode.com/docs/api/linode-kubernetes-engine-lke/#kubernetes-clusters-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A Paginated List of LKE clusters that match the query.

Return type:

PaginatedList of LKECluster

node_pool(node_type, node_count)[source]

Returns a dict that is suitable for passing into the node_pools array of cluster_create. This is a convenience method, and need not be used to create Node Pools. For proper usage, see the docs for cluster_create.

Parameters:
  • node_type (Type or str) – The type of node to create in this node pool.

  • node_count (int) – The number of nodes to create in this node pool.

Returns:

A dict describing the desired node pool.

Return type:

dict

versions(*filters)[source]

Returns a PaginatedList of KubeVersion objects that can be used when creating an LKE Cluster.

API Documentation: https://www.linode.com/docs/api/linode-kubernetes-engine-lke/#kubernetes-versions-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A Paginated List of kube versions that match the query.

Return type:

PaginatedList of KubeVersion

LongviewGroup

Includes methods for interacting with our Longview service.

class linode_api4.linode_client.LongviewGroup(client: LinodeClient)[source]

Collections related to Linode Longview.

client_create(label=None)[source]

Creates a new LongviewClient, optionally with a given label.

API Documentation: https://www.linode.com/docs/api/longview/#longview-client-create

Parameters:

label – The label for the new client. If None, a default label based on the new client’s ID will be used.

Returns:

A new LongviewClient

Raises:
  • ApiError – If a non-200 status code is returned

  • UnexpectedResponseError – If the returned data from the api does not look as expected.

clients(*filters)[source]

Requests and returns a paginated list of LongviewClients on your account.

API Documentation: https://www.linode.com/docs/api/longview/#longview-clients-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Longview Clients matching the given filters.

Return type:

PaginatedList of LongviewClient

longview_plan_update(longview_subscription)[source]

Update your Longview plan to that of the given subcription ID.

Parameters:

longview_subscription (str) – The subscription ID for a particular Longview plan. A value of null corresponds to Longview Free.

Returns:

The updated Longview Plan

Return type:

LongviewPlan

subscriptions(*filters)[source]

Requests and returns a paginated list of LongviewSubscriptions available

API Documentation: https://www.linode.com/docs/api/longview/#longview-subscriptions-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Longview Subscriptions matching the given filters.

Return type:

PaginatedList of LongviewSubscription

NetworkingGroup

Includes methods for managing your networking systems.

class linode_api4.linode_client.NetworkingGroup(client: LinodeClient)[source]

Collections related to Linode Networking.

firewall_create(label, rules, **kwargs)[source]

Creates a new Firewall, either in the given Region or attached to the given Instance.

API Documentation: https://www.linode.com/docs/api/networking/#firewall-create

Parameters:
  • label (str) – The label for the new Firewall.

  • rules (dict) – The rules to apply to the new Firewall. For more information on Firewall rules, see our Firewalls Documentation.

Returns:

The new Firewall.

Return type:

Firewall

Example usage:

rules = {
     'outbound': [
         {
             'action': 'ACCEPT',
             'addresses': {
                 'ipv4': [
                     '0.0.0.0/0'
                 ],
                 'ipv6': [
                     "ff00::/8"
                 ]
             },
             'description': 'Allow HTTP out.',
             'label': 'allow-http-out',
             'ports': '80',
             'protocol': 'TCP'
         }
     ],
     'outbound_policy': 'DROP',
     'inbound': [],
     'inbound_policy': 'DROP'
 }

 firewall = client.networking.firewall_create('my-firewall', rules)
firewalls(*filters)[source]

Retrieves the Firewalls your user has access to.

API Documentation: https://www.linode.com/docs/api/networking/#firewalls-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Firewalls the acting user can access.

Return type:

PaginatedList of Firewall

ip_addresses_assign(assignments, region)[source]

Assign multiple IPv4 addresses and/or IPv6 ranges to multiple Linodes in one Region. This allows swapping, shuffling, or otherwise reorganizing IPs to your Linodes.

The following restrictions apply:
  • All Linodes involved must have at least one public IPv4 address after assignment.

  • Linodes may have no more than one assigned private IPv4 address.

  • Linodes may have no more than one assigned IPv6 range.

Parameters:
  • region (str or Region) – The Region in which the assignments should take place. All Instances and IPAddresses involved in the assignment must be within this region.

  • assignments (dct) – Any number of assignments to make. See IPAddress.to for details on how to construct assignments.

ip_addresses_share(ips, linode)[source]

Configure shared IPs. IP sharing allows IP address reassignment (also referred to as IP failover) from one Linode to another if the primary Linode becomes unresponsive. This means that requests to the primary Linode’s IP address can be automatically rerouted to secondary Linodes at the configured shared IP addresses.

API Documentation: https://www.linode.com/docs/api/networking/#ip-addresses-share

Parameters:
  • linode – The id of the Instance or the Instance to share the IPAddresses with. This Instance will be able to bring up the given addresses.

  • ips (str or IPAddress) – Any number of IPAddresses to share to the Instance. Enter an empty array to remove all shared IP addresses.

Type:

linode: int or Instance

ip_allocate(linode, public=True)[source]

Allocates an IP to a Instance you own. Additional IPs must be requested by opening a support ticket first.

API Documentation: https://www.linode.com/docs/api/networking/#ip-address-allocate

Parameters:
  • linode (Instance or int) – The Instance to allocate the new IP for.

  • public (bool) – If True, allocate a public IP address. Defaults to True.

Returns:

The new IPAddress.

Return type:

IPAddress

ips(*filters)[source]

Returns a list of IP addresses on this account, excluding private addresses.

API Documentation: https://www.linode.com/docs/api/networking/#ip-addresses-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of IP addresses on this account.

Return type:

PaginatedList of IPAddress

ips_assign(region, *assignments)[source]

Redistributes IP Addressees within a single region. This function takes a Region and a list of assignments to make, then requests that the assignments take place. If any Instance ends up without a public IP, or with more than one private IP, all of the assignments will fail.

Note

This function does not update the local Linode Instance objects when called. In order to see the new addresses on the local instance objects, be sure to invalidate them with invalidate() after this completes.

Example usage:

linode1 = Instance(client, 123)
linode2 = Instance(client, 456)

# swap IPs between linodes 1 and 2
client.networking.assign_ips(linode1.region,
                             linode1.ips.ipv4.public[0].to(linode2),
                             linode2.ips.ipv4.public[0].to(linode1))

# make sure linode1 and linode2 have updated ipv4 and ips values
linode1.invalidate()
linode2.invalidate()

API Documentation: https://www.linode.com/docs/api/networking/#linodes-assign-ipv4s

Parameters:
  • region (str or Region) – The Region in which the assignments should take place. All Instances and IPAddresses involved in the assignment must be within this region.

  • assignments (dct) – Any number of assignments to make. See IPAddress.to for details on how to construct assignments.

DEPRECATED: Use ip_addresses_assign() instead

ips_share(linode, *ips)[source]

Shares the given list of IPAddresses with the provided Instance. This will enable the provided Instance to bring up the shared IP Addresses even though it does not own them.

API Documentation: https://www.linode.com/docs/api/networking/#ipv4-sharing-configure

Parameters:
  • linode – The Instance to share the IPAddresses with. This Instance will be able to bring up the given addresses.

  • ips (str or IPAddress) – Any number of IPAddresses to share to the Instance.

Type:

linode: int or Instance

DEPRECATED: Use ip_addresses_share() instead

ipv6_pools(*filters)[source]

Returns a list of IPv6 pools on this account.

API Documentation: https://www.linode.com/docs/api/networking/#ipv6-pools-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of IPv6 pools on this account.

Return type:

PaginatedList of IPv6Pool

ipv6_ranges(*filters)[source]

Returns a list of IPv6 ranges on this account.

API Documentation: https://www.linode.com/docs/api/networking/#ipv6-ranges-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of IPv6 ranges on this account.

Return type:

PaginatedList of IPv6Range

vlans(*filters)[source]

Note

This endpoint is in beta. This will only function if base_url is set to https://api.linode.com/v4beta.

Returns a list of VLANs on your account.

API Documentation: https://www.linode.com/docs/api/networking/#vlans-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A List of VLANs on your account.

Return type:

PaginatedList of VLAN

NodeBalancerGroup

Includes methods for managing Linode NodeBalancers.

class linode_api4.linode_client.NodeBalancerGroup(client: LinodeClient)[source]
__call__(*filters)[source]

Retrieves all of the NodeBalancers the acting user has access to.

This is intended to be called off of the LinodeClient class, like this:

nodebalancers = client.nodebalancers()

API Documentation: https://www.linode.com/docs/api/nodebalancers/#nodebalancers-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of NodeBalancers the acting user can access.

Return type:

PaginatedList of NodeBalancers

create(region, **kwargs)[source]

Creates a new NodeBalancer in the given Region.

API Documentation: https://www.linode.com/docs/api/nodebalancers/#nodebalancer-create

Parameters:

region (Region or str) – The Region in which to create the NodeBalancer.

Returns:

The new NodeBalancer

Return type:

NodeBalancer

ObjectStorageGroup

Includes methods for interacting with Linode Objects Storage. For interacting with buckets and objects, use the s3 API directly with a library like boto3.

class linode_api4.linode_client.ObjectStorageGroup(client: LinodeClient)[source]

This group encapsulates all endpoints under /object-storage, including viewing available clusters, buckets, and managing keys and TLS/SSL certs, etc.

bucket_create(cluster, label, acl: ObjectStorageACL = 'private', cors_enabled=False)[source]

Creates an Object Storage Bucket in the specified cluster. Accounts with negative balances cannot access this command. If the bucket already exists and is owned by you, this endpoint returns a 200 response with that bucket as if it had just been created.

This endpoint is available for convenience. It is recommended that instead you use the more fully-featured S3 API directly.

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-bucket-create

Parameters:
  • acl (str Enum: private,public-read,authenticated-read,public-read-write) – The Access Control Level of the bucket using a canned ACL string. For more fine-grained control of ACLs, use the S3 API directly.

  • cluster (str) – The ID of the Object Storage Cluster where this bucket should be created.

  • cors_enabled (bool) – If true, the bucket will be created with CORS enabled for all origins. For more fine-grained controls of CORS, use the S3 API directly.

  • label (str) – The name for this bucket. Must be unique in the cluster you are creating the bucket in, or an error will be returned. Labels will be reserved only for the cluster that active buckets are created and stored in. If you want to reserve this bucket’s label in another cluster, you must create a new bucket with the same label in the new cluster.

Returns:

A Object Storage Buckets that created by user.

Return type:

ObjectStorageBucket

buckets(*filters)[source]

Returns a paginated list of all Object Storage Buckets that you own. This endpoint is available for convenience. It is recommended that instead you use the more fully-featured S3 API directly.

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-buckets-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Object Storage Buckets that matched the query.

Return type:

PaginatedList of ObjectStorageBucket

cancel()[source]

Cancels Object Storage service. This may be a destructive operation. Once cancelled, you will no longer receive the transfer for or be billed for Object Storage, and all keys will be invalidated.

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-cancel

clusters(*filters)[source]

Returns a list of available Object Storage Clusters. You may filter this query to return only Clusters that are available in a specific region:

us_east_clusters = client.object_storage.clusters(ObjectStorageCluster.region == "us-east")

API Documentation: https://www.linode.com/docs/api/object-storage/#clusters-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Object Storage Clusters that matched the query.

Return type:

PaginatedList of ObjectStorageCluster

keys(*filters)[source]

Returns a list of Object Storage Keys active on this account. These keys allow third-party applications to interact directly with Linode Object Storage.

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-keys-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Object Storage Keys that matched the query.

Return type:

PaginatedList of ObjectStorageKeys

keys_create(label, bucket_access=None)[source]

Creates a new Object Storage keypair that may be used to interact directly with Linode Object Storage in third-party applications. This response is the only time that “secret_key” will be populated - be sure to capture its value or it will be lost forever.

If given, bucket_access will cause the new keys to be restricted to only the specified level of access for the specified buckets. For example, to create a keypair that can only access the “example” bucket in all clusters (and assuming you own that bucket in every cluster), you might do this:

client = LinodeClient(TOKEN)

# look up clusters
all_clusters = client.object_storage.clusters()

new_keys = client.object_storage.keys_create(
    "restricted-keys",
    bucket_access=[
        client.object_storage.bucket_access(cluster, "example", "read_write")
        for cluster in all_clusters
    ],
)

To create a keypair that can only read from the bucket “example2” in the “us-east-1” cluster (an assuming you own that bucket in that cluster), you might do this:

client = LinodeClient(TOKEN)
new_keys_2 = client.object_storage.keys_create(
    "restricted-keys-2",
    bucket_access=client.object_storage.bucket_access("us-east-1", "example2", "read_only"),
)

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-key-create

Parameters:
  • label (str) – The label for this keypair, for identification only.

  • bucket_access (dict or list of dict) – One or a list of dicts with keys “cluster,” “permissions”, and “bucket_name”. If given, the resulting Object Storage keys will only have the requested level of access to the requested buckets, if they exist and are owned by you. See the provided bucket_access function for a convenient way to create these dicts.

Returns:

The new keypair, with the secret key populated.

Return type:

ObjectStorageKeys

object_url_create(cluster_id, bucket, method, name, content_type=None, expires_in=3600)[source]

Creates a pre-signed URL to access a single Object in a bucket. This can be used to share objects, and also to create/delete objects by using the appropriate HTTP method in your request body’s method parameter.

This endpoint is available for convenience. It is recommended that instead you use the more fully-featured S3 API directly.

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-object-url-create

Parameters:
  • cluster_id (str) – The ID of the cluster this bucket exists in.

  • bucket (str) – The bucket name.

  • content_type (str) – The expected Content-type header of the request this signed URL will be valid for. If provided, the Content-type header must be sent with the request when this URL is used, and must be the same as it was when the signed URL was created. Required for all methods except “GET” or “DELETE”.

  • expires_in (int 360..86400) – How long this signed URL will be valid for, in seconds. If omitted, the URL will be valid for 3600 seconds (1 hour). Defaults to 3600.

  • method (str) – The HTTP method allowed to be used with the pre-signed URL.

  • name (str) – The name of the object that will be accessed with the pre-signed URL. This object need not exist, and no error will be returned if it doesn’t. This behavior is useful for generating pre-signed URLs to upload new objects to by setting the method to “PUT”.

Returns:

The signed URL to perform the request at.

Return type:

MappedObject

transfer()[source]

The amount of outbound data transfer used by your account’s Object Storage buckets, in bytes, for the current month’s billing cycle. Object Storage adds 1 terabyte of outbound data transfer to your data transfer pool.

API Documentation: https://www.linode.com/docs/api/object-storage/#object-storage-transfer-view

Returns:

The amount of outbound data transfer used by your account’s Object Storage buckets, in bytes, for the current month’s billing cycle.

Return type:

MappedObject

PollingGroup

Includes methods related to account event polling.

class linode_api4.linode_client.PollingGroup(client: LinodeClient)[source]

This group contains various helper functions for polling on Linode events.

event_poller_create(entity_type: str, action: str, entity_id: int = None) EventPoller[source]

Creates a new instance of the EventPoller class.

Parameters:
Returns:

The new EventPoller object.

Return type:

EventPoller

wait_for_entity_free(entity_type: str, entity_id: int, timeout: int = 240, interval: int = 5)[source]

Waits for all events relevant events to not be scheduled or in-progress.

Parameters:
  • entity_type (str) – The type of the entity to poll for events on. Valid values for this field can be found here: https://www.linode.com/docs/api/account/#events-list__responses

  • entity_id (int) – The ID of the entity to poll for.

  • timeout (int) – The timeout in seconds for this polling operation.

  • interval (int) – The interval in seconds to wait between polls.

ProfileGroup

Includes methods for managing your user.

class linode_api4.linode_client.ProfileGroup(client: LinodeClient)[source]

Collections related to your user.

__call__()[source]

Retrieve the acting user’s Profile, containing information about the current user such as their email address, username, and uid. This is intended to be called off of a LinodeClient object, like this:

profile = client.profile()

API Documentation: https://www.linode.com/docs/api/profile/#profile-view

Returns:

The acting user’s profile.

Return type:

Profile

apps(*filters)[source]

Returns the Authorized Applications for this user

API Documentation: https://www.linode.com/docs/api/profile/#authorized-apps-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Authorized Applications for this user

Return type:

PaginatedList of AuthorizedApp

logins()[source]

Returns the logins on your profile.

API Documentation: https://www.linode.com/docs/api/profile/#logins-list

Returns:

A list of logins for this profile.

Return type:

PaginatedList of ProfileLogin

phone_number_delete()[source]

Delete the verified phone number for the User making this request.

API Documentation: https://www.linode.com/docs/api/profile/#phone-number-delete

Returns:

Returns True if the operation was successful.

Return type:

bool

phone_number_verification_code_send(iso_code, phone_number)[source]

Send a one-time verification code via SMS message to the submitted phone number.

API Documentation: https://www.linode.com/docs/api/profile/#phone-number-verification-code-send

Parameters:
  • iso_code (str) – The two-letter ISO 3166 country code associated with the phone number.

  • phone_number (str) – A valid phone number.

Returns:

Returns True if the operation was successful.

Return type:

bool

phone_number_verify(otp_code)[source]

Verify a phone number by confirming the one-time code received via SMS message after accessing the Phone Verification Code Send (POST /profile/phone-number) command.

API Documentation: https://www.linode.com/docs/api/profile/#phone-number-verify

Parameters:

otp_code (str) – The one-time code received via SMS message after accessing the Phone Verification Code Send

Returns:

Returns True if the operation was successful.

Return type:

bool

security_questions()[source]

Returns a collection of security questions and their responses, if any, for your User Profile.

API Documentation: https://www.linode.com/docs/api/profile/#security-questions-list

security_questions_answer(questions)[source]

Adds security question responses for your User. Requires exactly three unique questions. Previous responses are overwritten if answered or reset to null if unanswered.

Example question: {

“question_id”: 11, “response”: “secret answer 3”

}

ssh_key_upload(key, label)[source]

Uploads a new SSH Public Key to your profile This key can be used in later Linode deployments.

API Documentation: https://www.linode.com/docs/api/profile/#ssh-key-add

Parameters:
  • key (str) – The ssh key, or a path to the ssh key. If a path is provided, the file at the path must exist and be readable or an exception will be thrown.

  • label (str) – The name to give this key. This is purely aesthetic.

Returns:

The newly uploaded SSH Key

Return type:

SSHKey

Raises:

ValueError – If the key provided does not appear to be valid, and does not appear to be a path to a valid key.

ssh_keys(*filters)[source]

Returns the SSH Public Keys uploaded to your profile.

API Documentation: https://www.linode.com/docs/api/profile/#ssh-keys-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of SSH Keys for this profile.

Return type:

PaginatedList of SSHKey

token_create(label=None, expiry=None, scopes=None, **kwargs)[source]

Creates and returns a new Personal Access Token.

API Documentation: https://www.linode.com/docs/api/profile/#personal-access-token-create

Parameters:
  • label (str) – The label of the new Personal Access Token.

  • expiry (datetime or str) – When the new Personal Accses Token will expire.

  • scopes (str) – A space-separated list of OAuth scopes for this token.

Returns:

The new Personal Access Token.

Return type:

PersonalAccessToken

tokens(*filters)[source]

Returns the Person Access Tokens active for this user.

API Documentation: https://www.linode.com/docs/api/profile/#personal-access-tokens-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of tokens that matches the query.

Return type:

PaginatedList of PersonalAccessToken

trusted_devices()[source]

Returns the Trusted Devices on your profile.

API Documentation: https://www.linode.com/docs/api/profile/#trusted-devices-list

Returns:

A list of Trusted Devices for this profile.

Return type:

PaginatedList of TrustedDevice

user_preferences()[source]

View a list of user preferences tied to the OAuth client that generated the token making the request.

user_preferences_update(**preferences)[source]

Updates a user’s preferences.

RegionGroup

Includes methods for accessing information about Linode Regions.

class linode_api4.linode_client.RegionGroup(client: LinodeClient)[source]
__call__(*filters)[source]

Returns the available Regions for Linode products.

This is intended to be called off of the LinodeClient class, like this:

region = client.regions()

API Documentation: https://www.linode.com/docs/api/regions/#regions-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of available Regions.

Return type:

PaginatedList of Region

availability(*filters)[source]

Returns the availability of Linode plans within a Region.

API Documentation: https://www.linode.com/docs/api/regions/#regions-availability-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of entries describing the availability of a plan in a region.

Return type:

PaginatedList of RegionAvailabilityEntry

SupportGroup

Includes methods for viewing and opening tickets with our support department.

class linode_api4.linode_client.SupportGroup(client: LinodeClient)[source]

Collections related to support tickets.

ticket_open(summary, description, managed_issue=False, regarding=None, **kwargs)[source]

Opens a support ticket on this account.

API Documentation: https://www.linode.com/docs/api/support/#support-ticket-open

Parameters:
  • summary (str) – The summary or title for this support ticket.

  • description (str) – The full details of the issue or question.

  • regarding – The resource being referred to in this ticket.

  • managed_issue (bool) – Designates if this ticket relates to a managed service.

Returns:

The new support ticket.

Return type:

SupportTicket

tickets(*filters)[source]

Returns a list of support tickets on this account.

API Documentation: https://www.linode.com/docs/api/support/#support-tickets-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of support tickets on this account.

Return type:

PaginatedList of SupportTicket

TagGroup

Includes methods for managing Linode Tags.

class linode_api4.linode_client.TagGroup(client: LinodeClient)[source]
__call__(*filters)[source]

Retrieves the Tags on your account. This may only be attempted by unrestricted users.

This is intended to be called off of the LinodeClient class, like this:

tags = client.tags()

API Documentation: https://www.linode.com/docs/api/domains/#domain-create

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Tags on the account.

Return type:

PaginatedList of Tag

create(label, instances=None, domains=None, nodebalancers=None, volumes=None, entities=[])[source]

Creates a new Tag and optionally applies it to the given entities.

API Documentation: https://www.linode.com/docs/api/tags/#tags-list

Parameters:
  • label (str) – The label for the new Tag

  • entities (list of Instance, Domain, NodeBalancer, and/or Volume) – A list of objects to apply this Tag to upon creation. May only be taggable types (Linode Instances, Domains, NodeBalancers, or Volumes). These are applied in addition to any IDs specified with instances, domains, nodebalancers, or volumes, and is a convenience for sending multiple entity types without sorting them yourself.

  • instances (list of Instance or list of int) – A list of Linode Instances to apply this Tag to upon creation

  • domains (list of Domain or list of int) – A list of Domains to apply this Tag to upon creation

  • nodebalancers (list of NodeBalancer or list of int) – A list of NodeBalancers to apply this Tag to upon creation

  • volumes (list of Volumes or list of int) – A list of Volumes to apply this Tag to upon creation

Returns:

The new Tag

Return type:

Tag

VolumeGroup

Includes methods for managing Linode Volumes.

class linode_api4.linode_client.VolumeGroup(client: LinodeClient)[source]
__call__(*filters)[source]

Retrieves the Block Storage Volumes your user has access to.

This is intended to be called off of the LinodeClient class, like this:

volumes = client.volumes()

API Documentation: https://www.linode.com/docs/api/volumes/#volumes-list

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of Volumes the acting user can access.

Return type:

PaginatedList of Volume

create(label, region=None, linode=None, size=20, **kwargs)[source]

Creates a new Block Storage Volume, either in the given Region or attached to the given Instance.

API Documentation: https://www.linode.com/docs/api/volumes/#volumes-list

Parameters:
  • label (str) – The label for the new Volume.

  • region (Region or str) – The Region to create this Volume in. Not required if linode is provided.

  • linode (Instance or int) – The Instance to attach this Volume to. If not given, the new Volume will not be attached to anything.

  • size (int) – The size, in GB, of the new Volume. Defaults to 20.

  • tags (list[str]) – A list of tags to apply to the new volume. If any of the tags included do not exist, they will be created as part of this operation.

Returns:

The new Volume.

Return type:

Volume

VPCGroup

Includes methods for managing Linode VPCs.

class linode_api4.linode_client.VPCGroup(client: LinodeClient)[source]
__call__(*filters) PaginatedList[source]

Retrieves all of the VPCs the acting user has access to.

This is intended to be called off of the LinodeClient class, like this:

vpcs = client.vpcs()

API Documentation: TODO

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of VPC the acting user can access.

Return type:

PaginatedList of VPC

create(label: str, region: Region | str, description: str | None = None, subnets: List[Dict[str, Any]] | None = None, **kwargs) VPC[source]

Creates a new VPC under your Linode account.

API Documentation: TODO

Parameters:
  • label (str) – The label of the newly created VPC.

  • region (Union[Region, str]) – The region of the newly created VPC.

  • description (Optional[str]) – The user-defined description of this VPC.

  • subnets (List[Dict[str, Any]]) – A list of subnets to create under this VPC.

Returns:

The new VPC object.

Return type:

VPC

ips(*filters) PaginatedList[source]

Retrieves all of the VPC IP addresses for the current account matching the given filters.

This is intended to be called from the LinodeClient class, like this:

vpc_ips = client.vpcs.ips()

API Documentation: TODO

Parameters:

filters – Any number of filters to apply to this query. See Filtering Collections for more details on filtering.

Returns:

A list of VPCIPAddresses the acting user can access.

Return type:

PaginatedList of VPCIPAddress