Registry / devops / python-vagrant

python-vagrant

JSON →
library1.0.0pypypi✓ verified 26d ago

python-vagrant provides Python bindings for interacting with Vagrant virtual machines, allowing programmatic control over Vagrant environments. The current stable version is 1.0.0. Releases are somewhat irregular but active, with bug fixes and minor features released as needed, typically every few months.

pip install python-vagrant
INSTALL
IMPORT
SIG · PYTHON-VAGRANT
P
python-vagrant
devopspythonv1.0.0
Install
1.6s avg
Import
35ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.038s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.032s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Vagrant
from vagrant import Vagrant

This quickstart demonstrates how to initialize `python-vagrant`, bring up a VM, check its status, and destroy it. It requires the Vagrant CLI tool to be installed and available in your system's PATH. A simple Vagrantfile is created for demonstration purposes if not already present.

import vagrant import os # Ensure you have a Vagrantfile in this directory or provide its root path # Example: Create a dummy Vagrantfile for testing if not present vagrantfile_path = './test_vagrant_project' if not os.path.exists(vagrantfile_path): os.makedirs(vagrantfile_path) if not os.path.exists(os.path.join(vagrantfile_path, 'Vagrantfile')): with open(os.path.join(vagrantfile_path, 'Vagrantfile'), 'w') as f: f.write("Vagrant.configure(\"2\") do |config|\n config.vm.box = \"hashicorp/bionic64\"\nend") # Initialize Vagrant object with the root path of the Vagrant project v = vagrant.Vagrant(root=vagrantfile_path) try: # Bring up the VM print(f"Bringing up Vagrant VM in {vagrantfile_path}...") v.up() print("VM is up.") # Get VM status status = v.status() for vm_status in status: print(f"VM Name: {vm_status.name}, Provider: {vm_status.provider}, State: {vm_status.state}") finally: # Destroy the VM print("Destroying Vagrant VM...") v.destroy() print("VM destroyed.") # Clean up dummy Vagrantfile and directory if os.path.exists(os.path.join(vagrantfile_path, 'Vagrantfile')): os.remove(os.path.join(vagrantfile_path, 'Vagrantfile')) if os.path.exists(vagrantfile_path): os.rmdir(vagrantfile_path)
vagrant --version
Debug
Known issues
breakingThe `up()` method in version 1.0.0 changed its signature. The `vm_name` argument is now the first positional argument. If you were calling `up(provision=True)` you must now call `up(vm_name=None, provision=True)` or `up(None, provision=True)`.
fix
Update calls to `up()` to explicitly pass `vm_name` as the first argument, or `None` if no specific VM name is desired, before other keyword arguments like `provision`.
affects: >=1.0.0
breakingVersion 1.0.0 dropped support for Python 3.7. The minimum required Python version is now 3.8.
fix
Upgrade your Python environment to Python 3.8 or newer.
affects: >=1.0.0
gotchaThis library acts as a wrapper around the Vagrant CLI tool. It does NOT bundle Vagrant itself. You must have the Vagrant CLI installed on your system and available in your PATH for `python-vagrant` to function correctly.
fix
Install Vagrant CLI from HashiCorp's official website (vagrantup.com) or your system's package manager before using `python-vagrant`.
affects: All versions
deprecatedSupport for Python 3.8 has been deprecated in the upcoming 1.1.0 release (already available on GitHub, but not yet PyPI at the time of writing). While it might still work, future versions will likely drop support.
fix
Plan to upgrade your Python environment to Python 3.9 or newer to ensure continued compatibility with `python-vagrant`.
affects: Future versions (>=1.1.0)
gotchaVersion 1.0.0 adopted a `src` code layout. While this primarily affects packaging, users with non-standard import patterns or those directly accessing internal modules might need to adjust their paths.
fix
Ensure you are using the public API (e.g., `from vagrant import Vagrant`) and avoid relying on internal module paths.
affects: >=1.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'vagrant'
The `python-vagrant` library has not been installed in the current Python environment.
fix
pip install python-vagrant
VagrantError: The executable 'vagrant' could not be found
The Vagrant command-line interface (CLI) tool is either not installed on the system or is not included in the system's PATH environment variable.
fix
Install the Vagrant CLI tool from its official website and ensure its installation directory is added to your system's PATH.
VagrantError: No Vagrantfile found in directory
The `python-vagrant` instance was initialized or a command was executed in a directory that does not contain a `Vagrantfile`.
fix
Initialize the `Vagrant` object with the correct path to a directory containing a `Vagrantfile`, or create a `Vagrantfile` in the current working directory.
VagrantError: The VM is not running.
A `python-vagrant` command was attempted on a virtual machine that is currently powered off, suspended, or was never successfully provisioned.
fix
Ensure the Vagrant VM is running by calling `v.up()` before attempting operations that require a running VM, or check its status with `v.status()`.
Upgrade
Version history
1.0.0latest on PyPI · released Mar 31, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
python-vagrant — pip install python-vagrant · libregistry