A cross-platform Python wrapper for the VeraCrypt CLI.
Project description
python-veracrypt
Overview
A cross platform Python wrapper for the VeraCrypt CLI. It requires the VeraCrypt application to be installed on your system and it uses the CLI to perform different operations.
Installation
Install the Python package with pip:
pip install python-veracrypt
You must also install VeraCrypt and ensure the VeraCrypt CLI is available on your PATH. Refer to the VeraCrypt downloads page for installers and platform details:
Prerequisites
- Verify the VeraCrypt CLI is available by running
veracrypt --version(or the equivalent command on your OS). - Ensure the process has permission to mount volumes (administrator or sudo may be required).
Supported Platforms
- Windows
- macOS
- Linux
Mount operations may require administrator or sudo permissions depending on your OS and system configuration.
Usage
from veracrypt import VeraCrypt, FileSystem
import os
vc = VeraCrypt()
volume_path = os.path.join('C:\\', 'Users', 'user', 'Desktop', 'test.vc')
# Create a volume
result = vc.create_volume(volume_path, 'SecretPassword', 5 * 1024 * 1024, filesystem=FileSystem.EXFAT)
# Mount a volume
result = vc.mount_volume(volume_path, 'SecretPassword', 'H', options=['/beep'])
# Dismount a volume
result = vc.dismount_volume('H', options=['/beep'])
# Custom command - Pay close attention when using this
result = vc.command(['/volume', volume_path, '/letter', 'H', '/password', 'SecretPassword', '/beep', '/quit', '/silent', '/force'])
Quick start checklist
- Install VeraCrypt and confirm the CLI is on your PATH.
- Choose a volume path and mount target (drive letter on Windows or mount point on Unix).
- Use the helper methods to create, mount, and dismount volumes.
Linux/macOS example
from veracrypt import VeraCrypt, FileSystem
vc = VeraCrypt()
volume_path = "/home/user/secure/test.vc"
mount_point = "/mnt/veracrypt"
result = vc.create_volume(volume_path, "SecretPassword", 5 * 1024 * 1024, filesystem=FileSystem.EXFAT)
result = vc.mount_volume(volume_path, "SecretPassword", mount_point, options=["--filesystem=exfat"])
result = vc.dismount_volume(mount_point)
Handling results
The methods on VeraCrypt return subprocess.CompletedProcess objects. You can inspect the return code and stderr to verify success:
result = vc.mount_volume(volume_path, "SecretPassword", "H", options=["/beep"])
if result.returncode != 0:
print("Mount failed:", result.stderr)
Security
Passwords
On nix based systems the password is passed in using --stdin, so the password will not appear in bash history or log files.
On Windows based systems the password cannot be passed to the CLI using stdin, so care should be taken to ensure that the password will not appear in history or logs. The result that is returned from the basic functional commands of the VeraCrypt class are subprocess.CompletedProcess objects, and the password is sanitized on windows in the args parameter of the object.
Best practices
- Avoid hardcoding passwords in source code. Prefer secure prompts or environment variables.
- Avoid logging the full command line if it contains sensitive values.
- Ensure mounted volumes are dismounted when not in use.
Documentation
Sphinx documentation lives in the docs/sphinx/ directory. To build HTML docs locally:
pip install ".[docs]"
sphinx-build -b html docs/sphinx docs/sphinx/_build/html
The generated docs can be opened from docs/sphinx/_build/html/index.html.
Troubleshooting
- If mounts fail, verify the VeraCrypt CLI works outside Python and that your user has sufficient permissions.
- If you use a custom VeraCrypt install location, ensure the executable directory is on your PATH.
Contributing
- Install development dependencies with
pip install -r requirements-dev.txt. - Run tests with
pytest. - Format with
blackand sort imports withisort. - Lint with
ruffand type-check withmypy.
License
This project is licensed under the terms of the LICENSE file in this repository.
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_veracrypt-0.1.0.tar.gz.
File metadata
- Download URL: python_veracrypt-0.1.0.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ceb4390a224f6c9ab2c2b15f639480cda66733e6d25c5086a8c88dc1a6bd73b
|
|
| MD5 |
90ada6d2a8d501203e5886cde82702ca
|
|
| BLAKE2b-256 |
02e21695142c0dec5357e602f73058adf8fd44502e121c9b5ca119e3ff5c86c0
|
File details
Details for the file python_veracrypt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_veracrypt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4142557a8a5eebde226039d33ca1fafa6e5d9287877564f4e1166588dbee7ca7
|
|
| MD5 |
f62906e532a98ad2dd56940795ccc269
|
|
| BLAKE2b-256 |
bb37c1c0c19e2f9008f5e4055d272af7b997ad164372f074a7bc5aea716385c4
|