Skip to main content

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

vhi_python-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

vhi_python-0.1.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file vhi_python-0.1.2.tar.gz.

File metadata

  • Download URL: vhi_python-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vhi_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2ba58b886500ef6622e7cda996b655127f4db97f4c2832a6c4ddf7b6e20483bf
MD5 96d129777492523e92afd2c2fe343ead
BLAKE2b-256 0e1f5e8ae893a0f179d48c7e6e7e3d22e185e94e05c20dbc4e885d8b0b7a0d61

See more details on using hashes here.

Provenance

The following attestation bundles were made for vhi_python-0.1.2.tar.gz:

Publisher: publish.yml on Irishsmurf/vhi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vhi_python-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: vhi_python-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vhi_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f56e4b41c8ed9eb44d2004894d461ea9c46c087e405064d6e10b6f7e000cc060
MD5 9878cee935b78e23ee519f27ca0550d8
BLAKE2b-256 232aa04201972d1fffee3aabc986e72f0f3556ba147f901224950cbfebdf7ba1

See more details on using hashes here.

Provenance

The following attestation bundles were made for vhi_python-0.1.2-py3-none-any.whl:

Publisher: publish.yml on Irishsmurf/vhi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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