CLI
Python SDK Usage
19min
we provide a pypi package https //pypi org/project/vastai/ , vastai sdk , for convenient python usage pypi install you can install the latest stable pypi release with pip install vastai sdk usage import the package from vastai sdk import vastai construct a vast client with your api key vast sdk = vastai(api key='your api key') resource methods most useful available vastai resources are implemented commands for vast cli usage should have equivalent class methods on your vast client object most ides should show type hints and relevant class methods and their expected arguments for vastai , due to the implementation of our base class for example, the cli command vastai show instances has the equivalent, vast sdk show instances() from vastai sdk import vastai vast sdk = vastai(api key='your api key') output = vast sdk show instances() print(output) example usage here are some example usages of our python sdk class vastai starting and stopping instances from vastai sdk import vastai vast sdk = vastai(api key='your api key') vast sdk start instance(id=12345678) vast sdk stop instance(id=12345678) creating a new instance create a new instance based on given parameters (performs search offers + create instance) from vastai sdk import vastai vast sdk = vastai(api key='your api key') vast sdk launch instance(num gpus="1", gpu name="rtx 3090", image="pytorch/pytorch") copying files between instances from vastai sdk import vastai vast sdk = vastai(api key='your api key') vast sdk copy(src='source path', dst='destination path', identity='identity file') managing ssh keys create a new ssh key, show all ssh keys, and delete an ssh key from vastai sdk import vastai vast sdk = vastai(api key='your api key') vast sdk create ssh key(ssh key='your ssh key') ssh keys = vast sdk show ssh keys() print(ssh keys) vast sdk delete ssh key(id=123456) contribution and issue reporting this code repository https //github com/vast ai/vast python is open source and can be rapidly changing at times if you find a potential bug, please open an issue on github if you wish to contribute to improving this code and its functionality, feel welcome to open a pr with any improvements on our github repository https //github com/vast ai/vast python available methods below is a list of the available methods you can call on the vastai client these methods are categorized for better readability instance management method description start instance(id int) start an instance stop instance(id int) stop an instance reboot instance(id int) reboot an instance destroy instance(id int) destroy an instance destroy instances(ids list\[int]) destroy multiple instances recycle instance(id int) recycle an instance label instance(id int, label str) label an instance show instance(id int) show details of an instance show instances(quiet bool = false) show all instances logs(instance id int, tail optional\[str] = none) retrieve logs for an instance execute(id int, command str) execute a command on an instance launch instance( ) launch a new instance with various parameters ssh key management method description create ssh key(ssh key str) create a new ssh key delete ssh key(id int) delete an ssh key show ssh keys() show all ssh keys attach ssh(instance id int, ssh key str) attach an ssh key to an instance detach ssh(instance id int, ssh key id str) detach an ssh key from an instance api key management method description create api key(name optional\[str] = none, ) create a new api key delete api key(id int) delete an api key reset api key() reset the api key show api key(id int) show details of an api key show api keys() show all api keys set api key(new api key str) set a new api key autoscaler management method description create autoscaler(test workers int = 3, ) create a new autoscaler update autoscaler(id int, min load optional\[float] = none, ) update an autoscaler delete autoscaler(id int) delete an autoscaler show autoscalers() show all autoscalers endpoint management method description create endpoint(min load float = 0 0, ) create a new endpoint update endpoint(id int, min load optional\[float] = none, ) update an endpoint delete endpoint(id int) delete an endpoint show endpoints() show all endpoints file management method description copy(src str, dst str, identity optional\[str] = none) copy files between instances cloud copy(src optional\[str] = none, dst optional\[str] = "/workspace", ) copy files between cloud and instance cancel copy(dst str) cancel a file copy operation cancel sync(dst str) cancel a file sync operation scp url(id int) get the scp url for transferring files to/from an instance team management method description create team(team name optional\[str] = none) create a new team destroy team() destroy a team invite team member(email optional\[str] = none, role optional\[str] = none) invite a new member to the team remove team member(id int) remove a member from the team create team role(name optional\[str] = none, permissions optional\[str] = none) create a new team role remove team role(name str) remove a role from the team update team role(id int, name optional\[str] = none, permissions optional\[str] = none) update details of a team role show team members() show all team members show team role(name str) show details of a specific team role show team roles() show all team roles host management method description cleanup machine(id int) clean up a machine's configuration and resources list machine(id int, price gpu optional\[float] = none, price disk optional\[float] = none, price inetu optional\[float] = none, price inetd optional\[float] = none, discount rate optional\[float] = none, min chunk optional\[int] = none, end date optional\[str] = none) list details of a single machine with optional pricing and configuration parameters list machines(ids list\[int], price gpu optional\[float] = none, price disk optional\[float] = none, price inetu optional\[float] = none, price inetd optional\[float] = none, discount rate optional\[float] = none, min chunk optional\[int] = none, end date optional\[str] = none) list details of multiple machines with optional pricing and configuration parameters remove defjob(id int) remove the default job from a machine set defjob(id int, price gpu optional\[float] = none, price inetu optional\[float] = none, price inetd optional\[float] = none, image optional\[str] = none, args optional\[list\[str]] = none) set a default job on a machine with specified parameters set min bid(id int, price optional\[float] = none) set the minimum bid price for a machine schedule maint(id int, sdate optional\[float] = none, duration optional\[float] = none) schedule maintenance for a machine cancel maint(id int) cancel scheduled maintenance for a machine unlist machine(id int) unlist a machine from being available for new jobs show machines(quiet bool = false, filter optional\[str] = none) retrieve and display a list of machines based on specified criteria other methods method description get gpu names() returns a set of gpu names available on vast ai show connections() show all connections show deposit(id int) show deposit details for an instance show earnings(quiet bool = false, start date optional\[str] = none, end date optional\[str] = none, machine id optional\[int] = none) show earnings information show invoices(quiet bool = false, start date optional\[str] = none, end date optional\[str] = none, ) show invoice details show ipaddrs() show ip addresses show user(quiet bool = false) show user details show subaccounts(quiet bool = false) show all subaccounts of the current user transfer credit(recipient str, amount float) transfer credit to another account update ssh key(id int, ssh key str) update an ssh key generate pdf invoices(quiet bool = false, start date optional\[str] = none, end date optional\[str] = none, only charges bool = false, only credits bool = false) generate pdf invoices based on filters please refer to the vastai python sdk api reference https //github com/vast ai/vast python for detailed information on all available methods and their usage