V2Hub - VPN Subscription API Client
Professional Python client library for VPN Subscription API with async/sync support, comprehensive error handling, and production-ready features.
Features
- 🚀 Async & Sync: Both
AsyncVPNClientandVPNClient(sync wrapper) - 📦 Pydantic Models: Full type safety and validation with Pydantic v2
- 🔄 Smart Retry: Exponential backoff with jitter and circuit breaker
- 🛡️ Exception Hierarchy: 11 typed exceptions with
is_retryableandrecovery_hint - 🎯 Type Safe: Full type hints for IDE support
- 📊 Production Ready: Logging, observability, and middleware support
Installation
pip install v2hub
Quick Start
Async Usage
from v2hub import AsyncVPNClient
async with AsyncVPNClient("https://api.example.com", "your-api-token") as client:
# Create subscription
sub = await client.create_subscription("my-vpn")
# Add sources
await client.add_sources(sub.token, ["vless://server1", "vmess://server2"])
# Get subscription config
config = await client.get_subscription_config(sub.token)
print(config)
Sync Usage
from v2hub import VPNClient
with VPNClient("https://api.example.com", "your-api-token") as client:
# Create subscription
sub = client.create_subscription("my-vpn")
# Add sources
client.add_sources(sub.token, ["vless://server1"])
# List subscriptions
subs = client.list_subscriptions()
for s in subs:
print(f"{s.name}: {s.token}")
Error Handling
from v2hub import (
AsyncVPNClient,
VPNAPIError,
RateLimitError,
NotFoundError,
)
async with AsyncVPNClient(base_url, token) as client:
try:
sub = await client.get_subscription("token123")
except NotFoundError:
print("Subscription not found")
except RateLimitError as e:
print(f"Rate limited. Retry after: {e.retry_after}")
except VPNAPIError as e:
if e.is_retryable:
print(f"Retryable error: {e.recovery_hint}")
else:
print(f"Permanent error: {e}")
Configuration
Retry Configuration
from v2hub import AsyncVPNClient, RetryConfig
config = RetryConfig(
max_retries=5,
initial_delay=1.0,
max_delay=60.0,
exponential_base=2,
jitter=True,
)
client = AsyncVPNClient(
base_url="https://api.example.com",
api_token="your-token",
retry_config=config,
)
Circuit Breaker
from v2hub import AsyncVPNClient, CircuitBreakerConfig
breaker = CircuitBreakerConfig(
failure_threshold=5,
recovery_timeout=60.0,
expected_exception=VPNAPIError,
)
client = AsyncVPNClient(
base_url="https://api.example.com",
api_token="your-token",
circuit_breaker_config=breaker,
)
API Coverage
Subscriptions
create_subscription(name, comment?)- Create new subscriptionget_subscription(token)- Get subscription detailslist_subscriptions()- List all subscriptionsupdate_subscription(token, name?, comment?)- Update subscriptiondelete_subscription(token)- Delete subscriptionrefresh_subscription(token)- Refresh subscription config
Sources
add_sources(token, uris)- Add source URIsreplace_sources(token, uris)- Replace all sourcesremove_sources(token, uris)- Remove specific sourcesget_sources(token)- Get all sources for subscription
Public Access
get_subscription_config(token)- Get public subscription config (no auth)get_public_info(token)- Get public subscription metadata (no auth)
Development
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Type checking
mypy src/
# Linting
ruff check src/
Extensions
- v2hub-admin: Admin API extension with HMAC authentication
- v2hub-cli: Beautiful command-line interface
License
MIT License - see LICENSE file for details.
Author
nestt
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 v2hub-1.0.8.tar.gz.
File metadata
- Download URL: v2hub-1.0.8.tar.gz
- Upload date:
- Size: 37.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61c9396e7ba949ebbeac0e4c21b54f72ecda782460a9717becc76640c64f6f8d
|
|
| MD5 |
ed3b20ef1cd85d1b38aac0d4459801f9
|
|
| BLAKE2b-256 |
ae5dbd91b464db62b6c6c6c8ed5fe1352655f492ae4ceb6646d3b6df4216dd56
|
Provenance
The following attestation bundles were made for v2hub-1.0.8.tar.gz:
Publisher:
publish.yml on nestthub/v2hub-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
v2hub-1.0.8.tar.gz -
Subject digest:
61c9396e7ba949ebbeac0e4c21b54f72ecda782460a9717becc76640c64f6f8d - Sigstore transparency entry: 2223954010
- Sigstore integration time:
-
Permalink:
nestthub/v2hub-core@2e87c22ff45f995b2fd45026a0bce6b30fddbdf9 -
Branch / Tag:
refs/tags/v1.0.8 - Owner: https://github.com/nestthub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2e87c22ff45f995b2fd45026a0bce6b30fddbdf9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file v2hub-1.0.8-py3-none-any.whl.
File metadata
- Download URL: v2hub-1.0.8-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1b203e29042f4e4b842904243797ca96468536414bfb90dbe1fc9a5a08adfd5
|
|
| MD5 |
a391157f055f681366f0e61ccd13e6ad
|
|
| BLAKE2b-256 |
6c62ee938a9e94f585cc4fbcb88eb0fb29dcc4095159bf7fc52674ce9a2a50ba
|
Provenance
The following attestation bundles were made for v2hub-1.0.8-py3-none-any.whl:
Publisher:
publish.yml on nestthub/v2hub-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
v2hub-1.0.8-py3-none-any.whl -
Subject digest:
e1b203e29042f4e4b842904243797ca96468536414bfb90dbe1fc9a5a08adfd5 - Sigstore transparency entry: 2223954399
- Sigstore integration time:
-
Permalink:
nestthub/v2hub-core@2e87c22ff45f995b2fd45026a0bce6b30fddbdf9 -
Branch / Tag:
refs/tags/v1.0.8 - Owner: https://github.com/nestthub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2e87c22ff45f995b2fd45026a0bce6b30fddbdf9 -
Trigger Event:
push
-
Statement type: