Python library for Vultr API
Project description
Python Library for Vultr API
The unofficial python library for the Vultr API.
Installation
pip install -U pyvultr
Usage
Configuration
from pyvultr import VultrV2
# Set your api key or we'll get it from env `VULTR_API_KEY`.
VULTR_API_KEY = '...'
v2 = VultrV2(api_key=VULTR_API_KEY)
Get Account
account = v2.account.get()
print(account)
List Region
regions: VultrPagination[BackupItem] = v2.region.list()
# Here `regions` is a VultrPagination object, you can use it like list, eg: get by index or slice.
# VultrPagination will help you automatically get the next page when you need it.
print(regions[3:5])
# >>> [RegionItem(id='dfw', country='US', options=['ddos_protection'], continent='North America', city='Dallas'), RegionItem(id='ewr', country='US', options=['ddos_protection', 'block_storage'], continent='North America', city='New Jersey')]
print(regions[12])
# >>> RegionItem(id='ord', country='US', options=['ddos_protection'], continent='North America', city='Chicago')
# Of course you can use `for` to iterate all items.
# But be careful, it will cause a lot of requests if it's has a lot of data.
for region in regions:
print(region)
# A smarter way to iterate is to determine the number of iterations you want.
smart_regions: VultrPagination[RegionItem] = v2.region.list(capacity=3)
for region in smart_regions:
print(region)
# >>> RegionItem(id='ams', country='NL', options=['ddos_protection'], continent='Europe', city='Amsterdam')
# >>> RegionItem(id='atl', country='US', options=['ddos_protection'], continent='North America', city='Atlanta')
# >>> RegionItem(id='cdg', country='FR', options=['ddos_protection'], continent='Europe', city='Paris')
# At last, you can get all data just like calling attributes (better programming experience if you use IDE):
first_region: RegionItem = regions.first()
print(first_region.country, first_region.city)
# >>> NL Amsterdam
CLI
PyVultr also provides a command line interface.
It's a simple wrapper of the python library using Fire, and it has a beautiful output by using Pygments.
It registered a command pyvultr
in the system, so you can just type pyvultr
to use it:
# please setup Your API Key first:
# you can generate your API Key from https://my.vultr.com/settings/#settingsapi
# export VULTR_API_KEY="..."
# show help by type `pyvultr`
$ pyvultr
pyvultr
cli usage is very similar to the python library usage.
let's explain this with get account information api :
In Python:
from pyvultr import VultrV2
# here we get api key from env `VULTR_API_KEY`
VultrV2().account.get()
>>> AccountInfo(name='test man', email='test@xxx.xxx', acls=['manage_users', 'subscriptions_view', 'subscriptions', 'billing', 'support', 'provisioning', 'dns', 'abuse', 'upgrade', 'firewall', 'alerts', 'objstore', 'loadbalancer', 'vke'], balance=11.2, pending_charges=3.4, last_payment_date='2019-07-16T05:19:50+00:00', last_payment_amount=-10)
In CLI:
$ pyvultr account get
{
"name": "test man",
"email": "test@xxx.xxx",
"acls": [
"manage_users",
"subscriptions_view",
"subscriptions",
"billing",
"support",
"provisioning",
"dns",
"abuse",
"upgrade",
"firewall",
"alerts",
"objstore",
"loadbalancer",
"vke"
],
"balance": 11.2,
"pending_charges": 3.4,
"last_payment_date": "2019-07-16T05:19:50+00:00",
"last_payment_amount": -10
}
Actually, we have a beautiful output:
Testing
python -m pytest -v
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyvultr-0.1.3.tar.gz
(38.7 kB
view details)
Built Distribution
pyvultr-0.1.3-py3-none-any.whl
(57.1 kB
view details)
File details
Details for the file pyvultr-0.1.3.tar.gz
.
File metadata
- Download URL: pyvultr-0.1.3.tar.gz
- Upload date:
- Size: 38.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.6.8 Darwin/21.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c56485c77207ccaabd0f2614c3f92221c227c82ccc0e8fde1702a5a7fd5ff05 |
|
MD5 | 0dca9a91363b4ec074cdd66cb44e5a4a |
|
BLAKE2b-256 | f7e7137b1105057839d1832d808368dfacd0edd15ad8ab0ba5aab97ebee1617e |
File details
Details for the file pyvultr-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: pyvultr-0.1.3-py3-none-any.whl
- Upload date:
- Size: 57.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.6.8 Darwin/21.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec9e827c71d8b8c9b43821a5cf427b4a1b65ea89fca923ebc04cd64458cc5354 |
|
MD5 | 3ea590fed3438fc64398496f4d43d9e9 |
|
BLAKE2b-256 | 8423a616d066c664568d0df4c1910d9007cd66c52a5cff0fef8e8e39650bdd56 |