• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 8 years ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official Python bindings for the Linode API

linode_api4

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

https://img.shields.io/github/actions/workflow/status/linode/linode_api4-python/main.yml?label=tests Documentation Status

Installation

pip install linode_api4

Building from Source

To build and install this package:

  • Clone this repository
  • ./setup.py install

Usage

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(
    ltype="g6-nanode-1",
    region="us-southeast",
    image="linode/ubuntu22.04",
    label="my-ubuntu-linode"
)

# 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:
    print(instance.label)

# 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:
    print(instance.label)

# Delete the new instance
new_linode.delete()

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

Examples

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

Contributing

Tests

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:

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(linode.id, 123) # passes

Integration Tests

Integration tests live in the test/integration directory.

Pre-requisite

Export Linode API token as LINODE_CLI_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="test_account.py" testint

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

make TEST_CASE=test_get_domain_record testint

Documentation

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.

Contributing

Please follow the Contributing Guidelines when making a contribution.

More Repositories

1

apl-core

Application Platform for Linode Kubernetes Engine (or any other K8s)
Smarty
2,212
star
2

docs

Linode guides and tutorials.
Python
1,380
star
3

manager

Akamai's Cloud Manager is an open-source, single-page application designed as the primary frontend interface for interacting with the Linode API. It is entrusted by hundreds of thousands of customers with the management of their Linode services.
TypeScript
689
star
4

cli

This is the DEPRECATED Linode CLI. Use https://github.com/linode/linode-cli
Perl
466
star
5

linode-cli

The official Linode command line interface.
Python
376
star
6

longview

Linode Longview Agent
Perl
334
star
7

terraform-provider-linode

Terraform Linode provider
Go
203
star
8

linodego

Go client for Linode REST v4 API
Go
138
star
9

linode-cloud-controller-manager

Kubernetes Cloud Controller Manager for Linode
Go
83
star
10

terraform-linode-k8s

Kubernetes installer for Linode
HCL
67
star
11

linode-blockstorage-csi-driver

Container Storage Interface (CSI) Driver for Linode Block Storage
Go
65
star
12

ansible_linode

Linode Ansible Collection
Python
57
star
13

Marketplace-Apps

The Linode Marketplace is designed to make it easier for developers and companies to share One-Click Apps with the Linode community.
Shell
53
star
14

docker-volume-linode

Docker Volume driver for Linode Block Storage
Go
46
star
15

docker-machine-driver-linode

Linode Driver Plugin for Docker Machine using Linode APIv4
Go
44
star
16

cluster-api-provider-linode

A Cluster API implementation to create Kubernetes clusters for Linode (CAPL)
Go
26
star
17

beginners-guide-to-devops-tools

SCSS
26
star
18

linode-api-docs

Source for the Linode API v4 Docs
Python
23
star
19

packer-builder-linode

Packer Builder plugin for Linode Images
Go
21
star
20

apl-tasks

Tasks needed by APL to glue all the pieces together
TypeScript
20
star
21

provider-ceph

Provider Ceph is a Crossplane provider capable of managing S3 Buckets on one or more Ceph clusters.
Go
18
star
22

homebrew-cli

Homebrew formula for Linode CLI
Ruby
14
star
23

provider-linode

Provider Linode is a Crossplane provider for managing Linode Akamai Cloud Computing resources.
Go
12
star
24

packer-plugin-linode

Packer plugin for Linode Builder
Go
10
star
25

k8s-node-decorator

Add labels and annotations to your kubernetes nodes with this in cluster decorator that reads data from the metadata for the underlying linodes
Go
10
star
26

apl-clients

Factory to build and publish open API clients used in the apl-tasks repo
Shell
10
star
27

kontainer-engine-driver-lke

Kontainer Engine Driver for Rancher Cluster Driver
Go
8
star
28

developers

developers-linode-com
JavaScript
8
star
29

action-linode-cli

A GitHub Action for installing the Linode CLI
8
star
30

lelastic

elastic IP client
Go
7
star
31

linode-doc-template

Template for creating bounty docs for Linode.
6
star
32

rancher-ui-driver-linode

UI for Linode options when used as a Rancher Node Template
JavaScript
6
star
33

linode-react-components

React Components consumed by linode/manager and linode/linode-api-docs
JavaScript
6
star
34

linode-k8s-e2e-tests

A collection of end-to-end test for Kubernetes running on Linode
Go
6
star
35

velero-plugin

Verlero plugin that clones Linode CSI volumes for archival
Go
5
star
36

capi-bootstrap

Cluster API self-managed cluster bootstrapping
Go
4
star
37

linode-cosi-driver

A Kubernetes Container Object Storage Interface (COSI) Driver for Linode
Go
4
star
38

agreements

Linode's Legal Agreements
4
star
39

go-metadata

A Go package for interacting with the Linode Metadata Service.
Go
4
star
40

apl-docs

App Platform for LKE documentation website - https://apl-docs.net
JavaScript
4
star
41

linode-hugo-theme

JavaScript
4
star
42

manager-design

Design repository for the Linode manager
4
star
43

ui-cluster-driver-lke

UI for Linode options when used as a Rancher Cluster Driver
JavaScript
3
star
44

terraform-linode-dcos

[WORK-IN-PROGRESS] DC/OS Provisioning Terraform module for Linode
HCL
3
star
45

design-language-system

A repository of our foundational design tokens in various formats help build a cohesive and consistent visual language across digital platforms. Includes color palettes, typography, spacing, layout rules, and more. Provides a pre-built set of tokens for designers and developers to easily implement in their projects, promoting brand identity
TypeScript
3
star
46

apl-charts

App Platform for LKE - Catalog Helm charts
Smarty
3
star
47

ansible-specdoc

A utility for dynamically generating Ansible Collection documentation.
Python
2
star
48

py-metadata

A Python package for interacting with the Linode Metadata Service.
Python
2
star
49

styles

Linode stylesheets
CSS
2
star
50

lke-sintel-demo

Three manifest Nginx Ingress, Cert Manager, and External DNS demo on Linode Kubernetes Engine
HTML
2
star
51

ndproxy

Go
2
star
52

dhcpd-unnumbered

Go
2
star
53

arpproxy

Go
2
star
54

docs-cloud-projects

Jinja
1
star
55

docs-scripts

Python
1
star
56

ansible-specdoc-example

An example Ansible Collection using ansible-specdoc.
Python
1
star
57

splunk-addon-linode

Linode Splunk Integration
Python
1
star
58

rad-unnumbered

Go
1
star
59

cloud-firewall-controller

Go
1
star