Skip to main content

Minimal OpenVPN connection manager for ProtonVPN - WSL-optimized

Project description

VPN Controller

Minimal OpenVPN connection manager for ProtonVPN - WSL-optimized.

Designed for Python developers who need VPN protection in their WSL scripts.

Installation

pip install vpn-controller

Setup

Create a .env file in your project directory:

# ProtonVPN credentials (from account settings)
OPENVPN_USER="username+b1"
OPENVPN_PASS="password"

# OpenVPN config file (download from ProtonVPN)
OVPN_CONFIG="./config.ovpn"

# Path to OpenVPN executable on Windows
OPENVPN_EXE="/mnt/c/Program Files/OpenVPN/bin/openvpn.exe"

# Optional: Your country for connection validation
HOME_COUNTRY="Brazil"

# Optional: Connection timeout in seconds
CONNECT_TIMEOUT="15"

Path formats supported: Relative (./file), home (~/file), absolute (/home/user/file), Windows drives (/mnt/c/...)

Quick Start

from vpn_controller import VPNController

with VPNController() as vpn:
    if vpn.connect():
        print("Connected to VPN")
        # Your protected code here
    # Automatic disconnect on exit

API Reference

VPNController

Context manager for OpenVPN connection lifecycle.

Methods

connect(force=False) -> bool

Connects to VPN and validates the connection.

Parameters:

  • force (bool): If True, kills any existing OpenVPN process before connecting. Default: False

Returns:

  • bool: True if connected successfully, False otherwise

Raises:

  • RuntimeError: Another VPN is running and force=False
  • FileNotFoundError: OpenVPN executable or config file not found
  • ValueError: Invalid or missing configuration in .env

Example:

vpn = VPNController()

# Safe mode - fails if VPN already running
vpn.connect()

# Force mode - kills existing VPN first
vpn.connect(force=True)
disconnect() -> bool

Disconnects from VPN and cleans up resources (auth files, processes).

Returns:

  • bool: Always returns True

Example:

vpn.disconnect()
is_connected() -> bool

Checks if VPN is currently connected by validating IP geolocation.

Returns:

  • bool: True if connected to VPN, False otherwise

Example:

if vpn.is_connected():
    print("VPN is active")

Context Manager

Automatically disconnects on exit:

with VPNController() as vpn:
    if vpn.connect():
        # Your code here
    # Automatic disconnect happens here

Requirements

  • Python: 3.6+
  • Platform: WSL (Windows Subsystem for Linux)
  • Windows: OpenVPN installed (download)
  • Windows: gsudo installed (winget install gerardog.gsudo)
  • Python packages: requests (installed automatically via pip)
  • ProtonVPN: Account with OpenVPN config file

License: MIT

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

vpn_controller-1.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vpn_controller-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file vpn_controller-1.0.0.tar.gz.

File metadata

  • Download URL: vpn_controller-1.0.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for vpn_controller-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b1bc14cda1f7de30b7f43ebce489281db964b5b4d19c11b0d17a238bb9fb49f3
MD5 efb5ba253410c1d77ec88db9ac1e78ad
BLAKE2b-256 9d74b0b10b8e939f91ccf5664fc73cdbc2bf716359fa1608c401bab3d6ceb047

See more details on using hashes here.

File details

Details for the file vpn_controller-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: vpn_controller-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for vpn_controller-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6735dfcfd3b63da0b8a2b43424873f4eaec721e24e49cf0e45c939c6b0f9858e
MD5 a3c3881aeaa465bd1fa3b7b86bfb8284
BLAKE2b-256 2f0ca792337dbb97da53f72ce180c4b6e0162e9bcb5952f34dc3ae41f9aef9e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page