Giter Site home page Giter Site logo

enygren / linode_api4-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from linode/linode_api4-python

0.0 0.0 0.0 826 KB

Official Python bindings for the Linode API

Home Page: https://linode-api4.readthedocs.io/

License: BSD 3-Clause "New" or "Revised" License

Python 99.85% Makefile 0.15%

linode_api4-python's Introduction

linode_api4

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

https://travis-ci.com/linode/linode_api4-python.svg?branch=master 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 tests 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

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.

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.

linode_api4-python's People

Contributors

abalarin avatar alexanderlarin avatar awiddersheim avatar backtrace-ci-bot avatar beli-sk avatar borgeslucaz avatar dorthu avatar ezilber-akamai-zz avatar georgedhill avatar glenns avatar illblew avatar irishgordo avatar jamesottinger avatar jonesinator avatar jwodder avatar lbgarber avatar lgarber-akamai avatar mathiasfrohlich avatar mikeabrahamsen avatar nvllsvm avatar phillc avatar rmcintosh avatar rylabs-billy avatar tjhop avatar xazrad avatar xrmx avatar yoshizzle avatar zliang-akamai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.