A Python client library for the Vhi API, handling authentication, MFA callbacks, claims retrieval, and document downloads.
Project description
Vhi Python Client
A Python client library for interacting dynamically with the Vhi API. Provides automated handling of Session state, Multi-Factor Authentication (MFA) callbacks, Claims Retrieval, and memory-efficient Document Downloads.
Installation
You can install the library directly from source (or via pip once published):
pip install vhi-python
Alternatively, to install it locally for development:
git clone https://github.com/agent/vhi-python.git
cd vhi-python
pip install -e .
Quick Start Example
This example demonstrates how to use the library to log in, handle an MFA callback (simulated via CLI input), retrieve claims, and download a claim PDF.
import os
from vhi.client import VhiClient
from vhi.exceptions import VhiAuthenticationError, VhiApiError
def my_cli_mfa_callback() -> str:
"""
A simple callback function that pauses execution
and waits for the user to input the 2FA code sent to their phone/email.
"""
return input("Vhi 2FA Code Required. Enter OTP: ").strip()
def main():
# 1. Initialize the client
# Replace with your actual credentials
username = os.getenv("VHI_USERNAME", "your_email@example.com")
password = os.getenv("VHI_PASSWORD", "your_password")
# We pass our callback function so the client can automatically
# pause and invoke it if the server demands MFA.
client = VhiClient(
username=username,
password=password,
mfa_callback=my_cli_mfa_callback
)
try:
# 2. Login
print("Logging in...")
client.login()
print("Login successful!")
# 3. Retrieve Claims
print("\nRetrieving claims...")
statements = client.get_claims()
if not statements:
print("No claim statements found.")
return
for claim in statements:
print(f"- Claim {claim.claim_id} | Date: {claim.date_of_service} | Status: {claim.status}")
# 4. Download a Document
# We will download the first available document as an example
first_claim = statements[0]
if first_claim.document_id:
download_path = f"{first_claim.claim_id}.pdf"
print(f"\nDownloading document {first_claim.document_id} to {download_path}...")
client.download_document(first_claim.document_id, download_path)
print("Download complete!")
except VhiAuthenticationError as e:
print(f"Authentication failed: {e}")
except VhiApiError as e:
print(f"API Error occurred: {e}")
if __name__ == "__main__":
main()
Error Handling
The library provides structural custom exceptions:
VhiAuthenticationError: Raised when login fails due to invalid credentials.VhiMfaRequiredError: Raised when the server requests MFA but you didn't provide a callback, or when the callback returns an invalid OTP.VhiApiError: Raised for any other 4xx or 5xx API errors. Contains standard HTTP status codes for debugging.
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
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 vhi_python-0.1.5.tar.gz.
File metadata
- Download URL: vhi_python-0.1.5.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cd842bc5b71e1a38af3e3a01ff1f0e8df656d09b4f3be0460b6798f423801c2
|
|
| MD5 |
d161168ca3b2721ee785bb19609be5bd
|
|
| BLAKE2b-256 |
2fe136248dfbadc3e31315ed6d9fd76535b59c5ee7c11c277ddc95b9cad0d669
|
Provenance
The following attestation bundles were made for vhi_python-0.1.5.tar.gz:
Publisher:
publish.yml on Irishsmurf/vhi-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vhi_python-0.1.5.tar.gz -
Subject digest:
9cd842bc5b71e1a38af3e3a01ff1f0e8df656d09b4f3be0460b6798f423801c2 - Sigstore transparency entry: 1138794482
- Sigstore integration time:
-
Permalink:
Irishsmurf/vhi-python@70c6d34c43a846c867bd55e1109b964dbce30ff3 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/Irishsmurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@70c6d34c43a846c867bd55e1109b964dbce30ff3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file vhi_python-0.1.5-py3-none-any.whl.
File metadata
- Download URL: vhi_python-0.1.5-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18901c4592e743d9a4add63d90a8dac3df52e88d68c0f86e7ec74af9ff5c0ead
|
|
| MD5 |
0c5025e34f6fee92e50dc4fa34e7c64f
|
|
| BLAKE2b-256 |
077014f41fedfa2a0cf299c76ccff51f6d93d8b5e2adc2b6e0656138a2ef2ec7
|
Provenance
The following attestation bundles were made for vhi_python-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on Irishsmurf/vhi-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vhi_python-0.1.5-py3-none-any.whl -
Subject digest:
18901c4592e743d9a4add63d90a8dac3df52e88d68c0f86e7ec74af9ff5c0ead - Sigstore transparency entry: 1138794598
- Sigstore integration time:
-
Permalink:
Irishsmurf/vhi-python@70c6d34c43a846c867bd55e1109b964dbce30ff3 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/Irishsmurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@70c6d34c43a846c867bd55e1109b964dbce30ff3 -
Trigger Event:
push
-
Statement type: