Skip to content

BitLaunchIO/pybitlaunch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

pybitlaunch

pybitlaunch is a python library for accessing the BitLaunch API.

You can view BitLaunch API docs here: https://developers.bitlaunch.io/

Install

Source

git clone https://github.com/bitlaunchio/pybitlaunch.git
cd pybitlaunch
python setup.py install

PIP

pip install -U pybitlaunch

Usage

import pybitlaunch

Authentication

You must use your API Token to authenticate with BitLaunch API. You can (re)generate your access token on the BitLaunch API Page.

You can then use your token to create a new client.

client = pybitlaunch.Client(token)

Documentation

For a comprehensive list of examples, check out the API documentation.

Account

Show

accountObj = client.Account.Show()
if accountObj is not None:
    # process data

Usage

usage = client.Account.Usage("2020-10")
if usage is not None:
    # process data

History

history = client.Account.History(1, 25)
if history is not None:
    # process data

SSHKeys

List

sshKeyObjArray = client.SSHKeys.List()
if sshKeyObjArray is not None:
    # process data

Create

newKey = pybitlaunch.SSHKey(name="sshkey_name", content="sshkey_rsa_pub")

sshKeyObj, err = client.SSHKeys.Create(newKey)
if err is not None:
    # handle error
else:
    # process data

Delete

err = client.SSHKeys.Delete(sshKeyObj.id)
if err is not None:
    # handle error

Transactions

List

transactionObjArray, err = client.Transactions.List(page=1, pPage=25) # Optional: page, pPage
if err is not None:
    # handle error
else:
    # process data

Show

transactionObj, err = client.Transactions.Show(transactionObj.id)
if err is not None:
    # handle error
else:
    # process data

Create

newTransaction = pybitlaunch.Transaction(
    amountUSD = 20,
    cryptoSymbol = None, # Optional
    lightningNetwork = None # Optional
)

transactionObj, err = client.Transactions.Create(newTransaction)
if err is not None:
    # handle error
else:
    # process data

CreateOptions

Show

createOptionsArray, err = client.CreateOptions.Show(hostID)
# createOptionsArray = ['hostID', 'image', 'region', 'size', 'available', 'bandwidthCost', 'planTypes', 'hostOptions']
if err is not None:
    # handle error
else:
    # process data

Servers

List

serverObj, err = client.Servers.List()
if err is not None:
    # handle error
else:
    # process data

Show

serverObj, err = client.Servers.Show(serverObj.id)
if err is not None:
    # handle error
else:
    # process data

Create

newServer = pybitlaunch.Server(
    name = "myServer",
    hostID = 4,
    hostImageID = "10000",
    sizeID = "nibble-1024",
    regionID = "lon1",
    password = "MySecurePassword", # Optional must use sshKeys instead
    sshKeys = [sshKeyObj["id"]], # Optional must use password instead
    initscript = None # Optional
)

serverObj, err = client.Servers.Create(serverObj)
if err is not None:
    # handle error
else:
    # process data

Destroy

err = client.Servers.Destroy(serverObj.id)
if err is not None:
    # handle error

Rebuild

createOpts, err = client.CreateOptions.Show(4)
if err is not None:
    # handle error

newImage = pybitlaunch.RebuildImage(
    createOpts["image"][0]["versions"][1]["id"],
    createOpts["image"][0]["versions"][1]["description"]
)

err = client.Servers.Rebuild(serverObj.id, newImage)
if err is not None:
    # handle error

Resize

err = client.Servers.Resize(serverObj.id, "nibble-2048")
if err is not None:
    # handle error

Restart

err = client.Servers.Restart(serverObj.id)
if err is not None:
    # handle error

Protection

server, err = client.Servers.Protection(serverObj.id, True)
if err is not None:
    # handle error
else:
    # process data

SetPorts

ports = [
    pybitlaunch.Port(1234, "tcp"),
    pybitlaunch.Port(1234, "udp"),
    pybitlaunch.Port(1235, "tcp"),
]

server, err = client.Servers.SetPorts(serverObj.id, ports)
if err is not None:
    # handle error
else:
    # process data

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages