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
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.2.tar.gz
(35.1 kB
view details)
Built Distribution
pyvultr-0.1.2-py3-none-any.whl
(53.8 kB
view details)
File details
Details for the file pyvultr-0.1.2.tar.gz
.
File metadata
- Download URL: pyvultr-0.1.2.tar.gz
- Upload date:
- Size: 35.1 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 | f8c4f3c61289769cff30e639e10452ecc9a2c97aabedda5c260d3893ba336bcc |
|
MD5 | 48a25a9b636b422af548c8ede4bd3148 |
|
BLAKE2b-256 | a168809a1ab4d8806ab975d0e4da56d6aa7dac972acfbf8ec0da4ff32402f5ac |
File details
Details for the file pyvultr-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: pyvultr-0.1.2-py3-none-any.whl
- Upload date:
- Size: 53.8 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 | 56c9d5e23d663b90acd8bd60756420b3971546debe21f2f2f1e84fe5a968d92c |
|
MD5 | 32d2a4dabebc332b398f7bd6aa061223 |
|
BLAKE2b-256 | 25d3b44153b2e13a162fe43189da1dc57d7462f0b9086eadc551dbed8a005e1f |