pybitlaunch is a python library for accessing the BitLaunch API.
You can view BitLaunch API docs here: https://developers.bitlaunch.io/
git clone https://github.com/bitlaunchio/pybitlaunch.git
cd pybitlaunch
python setup.py install
pip install -U pybitlaunch
import pybitlaunch
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)
For a comprehensive list of examples, check out the API documentation.
accountObj = client.Account.Show()
if accountObj is not None:
# process data
usage = client.Account.Usage("2020-10")
if usage is not None:
# process data
history = client.Account.History(1, 25)
if history is not None:
# process data
sshKeyObjArray = client.SSHKeys.List()
if sshKeyObjArray is not None:
# process data
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
err = client.SSHKeys.Delete(sshKeyObj.id)
if err is not None:
# handle error
transactionObjArray, err = client.Transactions.List(page=1, pPage=25) # Optional: page, pPage
if err is not None:
# handle error
else:
# process data
transactionObj, err = client.Transactions.Show(transactionObj.id)
if err is not None:
# handle error
else:
# process data
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
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
serverObj, err = client.Servers.List()
if err is not None:
# handle error
else:
# process data
serverObj, err = client.Servers.Show(serverObj.id)
if err is not None:
# handle error
else:
# process data
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
err = client.Servers.Destroy(serverObj.id)
if err is not None:
# handle error
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
err = client.Servers.Resize(serverObj.id, "nibble-2048")
if err is not None:
# handle error
err = client.Servers.Restart(serverObj.id)
if err is not None:
# handle error
server, err = client.Servers.Protection(serverObj.id, True)
if err is not None:
# handle error
else:
# process data
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