A Python function to make sure you are connected to your favorite VPN before running your script or function. It just raises an exception if you're not connected.
Supported VPN providers
- Custom IP
- ExpressVPN (
"expressvpn"
) - HideMyAss (
"hidemyass"
) - Hotspot Shield (
"hotspotshield"
) - IPVanish (
"ipvanish"
) - IVPN (
"ivpn"
) - Mullvad (
"mullvad"
) - NordVPN (
"nordvpn"
) - Private Internet Access (
"privateinternetaccess"
) - ProtonVPN (
"protonvpn"
) - Surfshark (
"surfshark"
) - VyprVPN (
"vyprvpn"
)
Add your own!
Installation
pip install ensure-vpn
Usage
Import the function and run it as the first thing in your script:
from ensure_vpn import ensure_vpn
ensure_vpn("mullvad")
You can also use a custom IP or subnet:
ensure_vpn("2.235.200.110")
You can also use the decorator to run the check every time before running a specific function. This is to make sure you don't run untrusted code if you lose your VPN connection after starting your program.
Note that this can be resource intensive depending on how often you call your function so it may slow down your program considerably or get you rate-limited by the services used by this script.
from ensure_vpn import ensure_vpn_decorator
@ensure_vpn_decorator("nordvpn")
def do_stuff():
do_stuff()