Package: linode-api4
linode_api4The official python library for theLinode API v4in python.Installationpip install linode_api4Building from SourceTo build and install this package:Clone this repositorypython3-mpip install .UsageQuick StartIn order to authenticate with the Linode API, you will first need to create aLinode Personal Access Tokenwith your desired account permissions.The following code sample can help you quickly get started using this package.fromlinode_api4importLinodeClient,Instance# Create a Linode API clientclient=LinodeClient("MY_PERSONAL_ACCESS_TOKEN")# Create a new Linodenew_linode,root_pass=client.linode.instance_create(ltype="g6-nanode-1",region="us-southeast",image="linode/ubuntu22.04",label="my-ubuntu-linode")# Print info about the Linodeprint("Linode IP:",new_linode.ipv4[0])print("Linode Root Password:",root_pass)# List all Linodes on the accountmy_linodes=client.linode.instances()# Print the Label of every Linode on the accountprint("All Instances:")forinstanceinmy_linodes:print(instance.label)# List Linodes in the us-southeast regionspecific_linodes=client.linode.instances(Instance.region=="us-southeast")# Print the label of each Linode in us-southeastprint("Instances in us-southeast:")forinstanceinspecific_linodes:print(instance.label)# Delete the new instancenew_linode.delete()Check out theGetting Started guidefor more details on getting started
with this library, or readthe docsfor more extensive documentation.ExamplesSee theInstall on a Linodeexample project for a simple use case demonstrating
many of the features of this library.ContributingTestsTests live in thetestdirectory.  When invoking tests, make sure you are
in the root directory of this project.  To run the full suite across all
supported python versions, usetox:toxRunning tox also runs pylint and coverage reports.The test suite uses fixtures stored as JSON intest/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 extendtest.base.ClientBaseCase.  This provides them
withself.client, aLinodeClientobject 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 awithblock 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(linode.id, 123) # passesIntegration TestsIntegration tests live in thetest/integrationdirectory.Pre-requisiteExport Linode API token asLINODE_TOKENbefore running integration tests:export LINODE_TOKEN = $(your_token)Running the testsRun the tests locally using the make command. Run the entire test suite using command below:make testintTo run a specific package, use environment variableINTEGRATION_TEST_PATHwithtestintcommand:make INTEGRATION_TEST_PATH="linode_client" testintTo run a specific model test suite, set the environment variableTEST_MODELusing file name inintegration/models:make TEST_MODEL="test_account.py" testintLastly to run a specific test case use environment variableTEST_CASEwithtestintcommand:make TEST_CASE=test_get_domain_record testintDocumentationThis library is documented withSphinx.  Docs live in thedocsdirectory.
The easiest way to build the docs is to runsphinx-autobuildin that
folder:sphinx-autobuild docs docs/buildAfter running this command,sphinx-autobuildwill 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, pleaseopen an issueto make us aware of the problem.ContributingPlease follow theContributing Guidelineswhen making a contribution.