Skip to main content

The official python SDK for Linode API v4

Project description


The official python library for the Linode API v4 in python. Documentation Status


pip install linode_api4

Building from Source

To build and install this package:

  • Clone this repository

  • python3 -m pip install .


Quick Start

In order to authenticate with the Linode API, you will first need to create a Linode Personal Access Token with your desired account permissions.

The following code sample can help you quickly get started using this package.

from linode_api4 import LinodeClient, Instance

# Create a Linode API client
client = LinodeClient("MY_PERSONAL_ACCESS_TOKEN")

# Create a new Linode
new_linode, root_pass = client.linode.instance_create(

# Print info about the Linode
print("Linode IP:", new_linode.ipv4[0])
print("Linode Root Password:", root_pass)

# List all Linodes on the account
my_linodes = client.linode.instances()

# Print the Label of every Linode on the account
print("All Instances:")
for instance in my_linodes:

# List Linodes in the us-southeast region
specific_linodes = client.linode.instances(
    Instance.region == "us-southeast"

# Print the label of each Linode in us-southeast
print("Instances in us-southeast:")
for instance in specific_linodes:

# Delete the new instance

Check out the Getting Started guide for more details on getting started with this library, or read the docs for more extensive documentation.


See the Install on a Linode example project for a simple use case demonstrating many of the features of this library.



Tests live in the test directory. When invoking tests, make sure you are in the root directory of this project. To run the full suite across all supported python versions, use tox:


Running tox also runs pylint and coverage reports.

The test suite uses fixtures stored as JSON in test/fixtures. These files contain sanitized JSON responses from the API - the file name is the URL called to produce the response, replacing any slashes with underscores.

Test classes should extend test.base.ClientBaseCase. This provides them with self.client, a LinodeClient object that is set up to work with tests. Importantly, any GET request made by this object will be mocked to retrieve data from the test fixtures. This includes lazy-loaded objects using this client (and by extension related models).

When testing against requests other than GET requests, self.mock_post (and equivalent methods for other HTTP verbs) can be used in a with block to mock out the intended request type. These functions accept the relative path from the api base url that should be returned, for example:

# this should return the result of GET /linode/instances/123
with self.mock_post('/linode/instances/123'):
  linode = self.client.linode.instance_create('g6-standard-2', 'us-east')
  self.assertEqual(, 123) # passes

Integration Tests

Integration tests live in the test/integration directory.


Export Linode API token as LINODE_TOKEN before running integration tests:

export LINODE_TOKEN = $(your_token)

Running the tests

Run the tests locally using the make command. Run the entire test suite using command below:

make testint

To run a specific package, use environment variable INTEGRATION_TEST_PATH with testint command:

make INTEGRATION_TEST_PATH="linode_client" testint

To run a specific model test suite, set the environment variable TEST_MODEL using file name in integration/models:

make TEST_MODEL="" testint

Lastly to run a specific test case use environment variable TEST_CASE with testint command:

make TEST_CASE=test_get_domain_record testint


This library is documented with Sphinx. Docs live in the docs directory. The easiest way to build the docs is to run sphinx-autobuild in that folder:

sphinx-autobuild docs docs/build

After running this command, sphinx-autobuild will host a local web server with the rendered documentation.

Classes and functions inside the library should be annotated with sphinx-compliant docstrings which will be used to automatically generate documentation for the library. When contributing, be sure to update documentation or include new docstrings where applicable to keep the library’s documentation up to date and useful.

Missing or inaccurate documentation is a bug. If you notice that the documentation for this library is out of date or unclear, please open an issue to make us aware of the problem.


Please follow the Contributing Guidelines when making a contribution.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linode_api4-5.10.0.tar.gz (148.4 kB view hashes)

Uploaded source

Built Distribution

linode_api4-5.10.0-py3-none-any.whl (107.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page