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 installpip install -U pybitlaunchimport pybitlaunchYou 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 datausage = client.Account.Usage("2020-10")
if usage is not None:
# process datahistory = client.Account.History(1, 25)
if history is not None:
# process datasshKeyObjArray = client.SSHKeys.List()
if sshKeyObjArray is not None:
# process datanewKey = pybitlaunch.SSHKey(name="sshkey_name", content="sshkey_rsa_pub")
sshKeyObj, err = client.SSHKeys.Create(newKey)
if err is not None:
# handle error
else:
# process dataerr = client.SSHKeys.Delete(sshKeyObj.id)
if err is not None:
# handle errortransactionObjArray, err = client.Transactions.List(page=1, pPage=25) # Optional: page, pPage
if err is not None:
# handle error
else:
# process datatransactionObj, err = client.Transactions.Show(transactionObj.id)
if err is not None:
# handle error
else:
# process datanewTransaction = 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 datacreateOptionsArray, err = client.CreateOptions.Show(hostID)
# createOptionsArray = ['hostID', 'image', 'region', 'size', 'available', 'bandwidthCost', 'planTypes', 'hostOptions']
if err is not None:
# handle error
else:
# process dataserverObj, err = client.Servers.List()
if err is not None:
# handle error
else:
# process dataserverObj, err = client.Servers.Show(serverObj.id)
if err is not None:
# handle error
else:
# process datanewServer = 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 dataerr = client.Servers.Destroy(serverObj.id)
if err is not None:
# handle errorcreateOpts, 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 errorerr = client.Servers.Resize(serverObj.id, "nibble-2048")
if err is not None:
# handle errorerr = client.Servers.Restart(serverObj.id)
if err is not None:
# handle errorserver, err = client.Servers.Protection(serverObj.id, True)
if err is not None:
# handle error
else:
# process dataports = [
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