Python library for Vultr API
Project description
Python Library for Vultr API
The unofficial python library for the Vultr API in python.
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.1.tar.gz
(29.6 kB
view details)
Built Distribution
pyvultr-0.1.1-py3-none-any.whl
(47.6 kB
view details)
File details
Details for the file pyvultr-0.1.1.tar.gz
.
File metadata
- Download URL: pyvultr-0.1.1.tar.gz
- Upload date:
- Size: 29.6 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 | c1991d3da470ee906e98aaa0af05aed5345ec74b50ccc66b31354816acac7fa4 |
|
MD5 | d7a4a6a881f6bfeacf851e219739545d |
|
BLAKE2b-256 | f371516d72fa199d38a10b772916096462c5b58c2610f4264732600fb6c89909 |
File details
Details for the file pyvultr-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pyvultr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 47.6 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 | 5ff80898aff983ac376679531725d665d4e7c869fd559b250f7eadb76ff7a4d7 |
|
MD5 | cc1714890ad9a5a487264203fbdc7cdc |
|
BLAKE2b-256 | 1502ed94d5253bec4d2c6875e2113813c4e263905c65146c5acc8d5825469e7d |