Skip to content

Repository files navigation

PyPI VersionTOML Python VersionPyPI DownloadsPepy Total DownloadsCodacy BadgeQuality Gate StatusDeployment PyPiDeployment PagesWorkflow TestWorkflow LintGitHub Last CommitGitHub Repo SizeGitHub Top LanguageGitHub ContributorsGitHub IssuesGitHub DiscussionsGitHub ForksGitHub Repo StarsGitHub Org StarsDiscordKo-fi

Vultr Python

Vultr Python

Python 3 wrapper for the Vultr API v2.

GitHubPyPiDocsVultr

Vultr API Reference: https://www.vultr.com/api

Tip

Please submit a Feature Request or report any Issues.

For more details visit www.vultr.com.

Install

From PyPi: https://pypi.org/project/vultr-python

python -m pip install vultr-python

From Source:

git clone https://github.com/cssnr/vultr-python.git
python -m pip install vultr-python

Usage

You will need to create an api key and whitelist your IP address for most functions.

Initialize the Vultr class with your API Key or use the VULTR_API_KEY environment variable.

fromvultrimportVultrvultr=Vultr("VULTR_API_KEY")

List plans and get available regions for that plan

plans=vultr.list_plans({"type": "vc2"}) # Filter by typeplan=plans[0] # 0 seems to be the base planregions=vultr.list_regions()
available=vultr.filter_regions(regions, plan["locations"])

Get the OS list and filter by name

os_list=vultr.list_os()
ubuntu_lts=vultr.filter_os(os_list, "Ubuntu 24.04 LTS x64")

Create a new ssh key from key string

sshkey=vultr.create_key("key-name", "ssh-rsa AAAA...")
vultr.delete_key(sshkey['id'])

Create a new instance

data= {
"os_id": ubuntu_lts["id"],
"sshkey_id": [sshkey["id"]],
"hostname": "my-new-host",
"label": "my-new-host",
}
instance=vultr.create_instance(available[0], plan, **data)

Arbitrary Methods get, post, patch, put, delete

plans=vultr.get("/plans", {"type": "vc2"})
sshkey=vultr.post("/ssh-keys", name="key-name", ssh_key="ssh-rsa AAAA...")
instance=vultr.patch("/instances/{instance-id}", plan=plans[1]["id"])
database=vultr.put("/databases/{database-id}", tag="new tag")
vultr.delete("/snapshots/{snapshot-id}")

Error Handling

>>>instance=vultr.create_instance("atl", "vc2-1c-0.5gb-v6", os_id=2284)
Traceback (mostrecentcalllast):
vultr.vultr.VultrException: Error400: Serveraddfailed: Ubuntu24.04LTSx64requiresaplanwithatleast1000MBmemory.

Using the VultrException class

fromvultrimportVultrExceptiontry:
instance=vultr.create_instance("atl", "vc2-1c-0.5gb-v6", os_id=2284)
exceptVultrExceptionaserror:
print(error.error)
# 'Server add failed: Ubuntu 24.04 LTS x64 requires a plan with at least 1000 MB memory.'print(error.status)
# 400

Full Documentation: https://cssnr.github.io/vultr-python

Vultr API Reference: https://www.vultr.com/api

Support

If you run into any issues or need help getting started, please do one of the following:

FeaturesIssuesDiscussionsDiscord

Contributing

If you would like to submit a PR, please review the CONTRIBUTING.md.

Please consider making a donation to support the development of this project and additional open source projects.

Ko-fi

For a full list of current projects visit: https://cssnr.github.io/

About

Python 3 wrapper for the Vultr API v2

Topics

Resources

Contributing

Stars

12 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages