Skip to main content

A comprehensive Python library for the Kipu Healthcare API with HMAC SHA1 authentication and recursive JSON flattening

Project description

Kipu API Python library

PyPI version Python Support License: MIT

The Kipu Python library provides convenient access to the Kipu API from any Python 3.8+ application. The library includes HMAC SHA1 authentication, recursive JSON flattening capabilities and type definitions for most of the request params and response fields, and offers asynchronous clients powered by [asyncio].

It is generated from our KipuAPI V3 specification

🚀 Features

  • Complete API Coverage: All 80+ Kipu API V3 endpoints implemented
  • 🔐 Secure Authentication: HMAC SHA1 signature generation
  • 📊 Automatic Flattening: Converts nested JSON responses to pandas DataFrames
  • Async Support: Built with asyncio for high performance
  • 🛡️ Error Handling: Comprehensive exception hierarchy
  • 📝 Type Hints: Full typing support for better development experience
  • 🔄 Flexible Response Format: Choose between raw JSON or flattened DataFrames

📦 Installation

pip install kipu-python

🔧 Quick Start

import asyncio
from kipu import KipuClient

async def main():
    async with KipuClient(
        access_id="your_access_id",
        secret_key="your_secret_key", 
        app_id="your_app_id"
    ) as client:
        
        # Get patient census as flattened DataFrame
        census_df = await client.get_patients_census()
        print(f"Found {len(census_df)} patients")
        
        # Get specific patient as raw JSON
        patient_data = await client.get_patient("patient_id", flatten=False)
        print(f"Patient: {patient_data['first_name']} {patient_data['last_name']}")

asyncio.run(main())

🔑 Authentication

The library handles HMAC SHA1 signature generation automatically. You need three credentials from Kipu:

  • access_id: Your API access identifier
  • secret_key: Your secret key for signature generation
  • app_id: Your application ID (also called recipient_id)

📚 API Coverage

Patient Management

# Get patient census
census_df = await client.get_patients_census(params={
    "phi_level": "high",
    "page": 1,
    "per": 50
})

# Get specific patient
patient = await client.get_patient("patient_id")

# Create new patient
patient_data = {
    "document": {
        "recipient_id": app_id,
        "data": {
            "first_name": "John",
            "last_name": "Doe",
            "dob": "1990-01-01"
        }
    }
}
new_patient = await client.create_patient(patient_data)

Medical Records

# Get vital signs
vital_signs_df = await client.get_vital_signs()
patient_vitals = await client.get_patient_vital_signs("patient_id")

# Get allergies
allergies_df = await client.get_allergies()
patient_allergies = await client.get_patient_allergies("patient_id")

# Create vital signs
vital_data = {
    "document": {
        "recipient_id": app_id,
        "data": {
            "systolic_blood_pressure": 120,
            "diastolic_blood_pressure": 80,
            "heart_rate": 72
        }
    }
}
await client.create_patient_vital_signs("patient_id", vital_data)

Appointments

# Get appointments
appointments_df = await client.get_scheduler_appointments(params={
    "start_date": "2024-01-01",
    "end_date": "2024-12-31"
})

# Get patient appointments
patient_appointments = await client.get_patient_appointments("patient_id")

Administrative

# Get locations, users, providers
locations_df = await client.get_locations()
users_df = await client.get_users()
providers_df = await client.get_providers()

🔄 Response Processing

Automatic Flattening (Default)

# Returns a flattened pandas DataFrame
census_df = await client.get_patients_census()
print(type(census_df))  # <class 'pandas.core.frame.DataFrame'>

Raw JSON Response

# Returns raw JSON
census_data = await client.get_patients_census(flatten=False)
print(type(census_data))  # <class 'dict'> or <class 'list'>

Global Flattening Control

# Disable auto-flattening globally
async with KipuClient(
    access_id, secret_key, app_id,
    auto_flatten=False
) as client:
    raw_data = await client.get_patients_census()  # Raw JSON
    flat_data = await client.get_patients_census(flatten=True)  # DataFrame

🛡️ Error Handling

from kipu.exceptions import (
    KipuAPIError,
    KipuAuthenticationError,
    KipuValidationError,
    KipuNotFoundError,
    KipuServerError
)

try:
    patient = await client.get_patient("invalid_id")
except KipuNotFoundError as e:
    print(f"Patient not found: {e.message}")
except KipuAuthenticationError as e:
    print(f"Authentication failed: {e.message}")
except KipuAPIError as e:
    print(f"API error: {e.message} (Status: {e.status_code})")

📎 File Uploads

# Patient with attachment
patient_data = {
    "document[recipient_id]": app_id,
    "document[data][first_name]": "John",
    "document[data][last_name]": "Doe"
}

files = {
    "document[attachments_attributes][0][attachment]": {
        "content": file_bytes,
        "filename": "patient_id.jpg",
        "content_type": "image/jpeg"
    }
}

await client.create_patient(patient_data, files=files)

📋 Available Endpoints

Core Categories

  • Patients: Census, individual records, admissions, latest updates
  • Medical Records: Vital signs, allergies, assessments, glucose logs
  • Evaluations: Patient evaluations, evaluation templates
  • Appointments: Scheduling, types, statuses, resources
  • Users & Providers: User management, provider records, roles
  • Administrative: Locations, care levels, flags, settings
  • Insurance: Insurance records, verification
  • Groups: Group sessions, patient groups

Complete Method List

# Patient endpoints
client.get_patients_census()
client.get_patient(patient_id)
client.create_patient(data)
client.update_patient(patient_id, data)
client.get_patients_admissions()
client.get_patients_latest()

# Medical records
client.get_vital_signs()
client.get_patient_vital_signs(patient_id)
client.create_patient_vital_signs(patient_id, data)
client.get_allergies()
client.get_patient_allergies(patient_id)
client.get_cows()
client.get_ciwa_ars()
client.get_glucose_logs()

# And 70+ more endpoints...

🧪 Development & Testing

# Clone the repository
git clone https://github.com/Rahulkumar010/kipu-python.git
cd kipu-python

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black kipu/
isort kipu/

# Type checking
mypy kipu/

📄 Requirements

  • Python: 3.8+
  • Dependencies:
    • aiohttp>=3.8.0 - Async HTTP client
    • pandas>=1.3.0 - Data manipulation
    • numpy>=1.20.0 - Numerical computing
    • tqdm>=4.60.0 - Progress bars

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📃 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

🏥 Healthcare Compliance

This library is designed for healthcare applications. Ensure your implementation complies with:

  • HIPAA (Health Insurance Portability and Accountability Act)
  • Local healthcare data protection regulations
  • Kipu's terms of service and security requirements

Built with ❤️ for the opensource community

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

kipu_python-0.0.1.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

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

kipu_python-0.0.1-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file kipu_python-0.0.1.tar.gz.

File metadata

  • Download URL: kipu_python-0.0.1.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kipu_python-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fb35434be3fee1ffde1a4be68957c2d3cd094a9aefaa4f125d7d6a1ed1bbf55c
MD5 89f37f4b78ed21fff638caae5b47be03
BLAKE2b-256 9bcb40d167bba2161265f255741af5ac6a228d74823b7b33c83234677f3eb4f5

See more details on using hashes here.

File details

Details for the file kipu_python-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: kipu_python-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kipu_python-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb9f99c463da7221edd531e4a2d53bd7d6bc08f03d87dd2b72f8e929a44dc09b
MD5 39d38b36a60d3d0ecfa32dd765c733c1
BLAKE2b-256 c74fc2f7a8c48ec283e482e38e80879614c0081b64ded99c0ae506cc602c8680

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