Reference client implementation for GluRPC - provides Python SDK and Gradio web interface for glucose prediction service.
Project description
GluRPC Client - Reference Implementation
Official reference client implementation for GluRPC, the glucose prediction server. This package demonstrates best practices for integrating with GluRPC and provides both a Python SDK and a production-ready Gradio web interface for uploading CGM data and visualizing glucose predictions.
Features
🎯 Reference Client Capabilities
- 🌐 Full GluRPC API Coverage: Complete Python SDK with sync and async support
- 🖥️ Production-Ready Web Interface: Beautiful Gradio UI with real-time updates
- 📊 Advanced Visualization: Interactive Plotly charts with confidence intervals
- 🔍 Real-time Health Monitoring: Live server metrics with historical graphs
- ⚡ Smart Request Management: Automatic request cancellation and client-side optimization
- 💾 Format Conversion: Upload raw CGM files, get unified format with data quality warnings
- 🎚️ Interactive Exploration: Slider-based navigation through prediction samples
- 🔐 Secure Authentication: API key support for protected servers
- 📥 Export Capabilities: Download unified CSV and interactive HTML plots
- 🧪 Development Tools: Built-in test server for local development
- 📈 Performance Tracking: Client-side request timing and server queue monitoring
Installation
Using uv (Recommended)
uv sync
Using pip
pip install glucosedao-client
Quick Start
Quickest Start: Using uv Scripts
# Run client + server together (recommended for development)
uv run dev
# Run only the client (connect to existing server)
uv run client
# Run only the server
uv run server
Option 1: Connect to Existing Server
If you have a GluRPC server running elsewhere:
# Start the client interface
glucosedao-client launch
# Or with custom host/port
glucosedao-client launch --host 0.0.0.0 --port 7860
Then open your browser and:
- Enter the server URL (e.g.,
http://your-server:8000) - Enter API key if required
- Upload your CGM data file
- View predictions!
Option 2: Launch with Local Test Server
For development or testing, start both client and server together:
# Start both client and server
glucosedao-client launch --with-server
# With custom ports
glucosedao-client launch --with-server --port 7860 --server-port 8001
Option 3: Start Only the Server
If you want to run just the server:
glucosedao-client server --host 0.0.0.0 --port 8000
CLI Commands
launch - Start the Web Interface
glucosedao-client launch [OPTIONS]
Options:
--share: Create a public Gradio share link--host HOST: Hostname to bind to (default: 127.0.0.1)--port PORT: Port to bind to (default: 7860)--with-server: Start GluRPC server locally for testing--server-host HOST: GluRPC server host when using --with-server (default: 127.0.0.1)--server-port PORT: GluRPC server port when using --with-server (default: 8000)
Examples:
# Basic launch
glucosedao-client launch
# Launch with local test server
glucosedao-client launch --with-server
# Create public share link
glucosedao-client launch --share
# Custom configuration
glucosedao-client launch --host 0.0.0.0 --port 8080 --with-server --server-port 8001
server - Start Only the Server
glucosedao-client server [OPTIONS]
Options:
--host HOST: Host to bind to (default: 0.0.0.0)--port PORT: Port to bind to (default: 8000)
Example:
glucosedao-client server --host 0.0.0.0 --port 8000
check - Health Check
glucosedao-client check [OPTIONS]
Options:
--url URL: Server URL to check (default: http://localhost:8000)
Example:
glucosedao-client check --url http://your-server:8000
Python API
You can also use the client programmatically:
from glucosedao_client import GluRPCClient, GluRPCConfig
# Initialize client
config = GluRPCConfig(
base_url="http://localhost:8000",
api_key="your-api-key" # Optional
)
client = GluRPCClient(config)
# Convert raw CGM file to unified format
convert_response = client.convert_to_unified("path/to/dexcom.csv")
if not convert_response.error:
# Process the data
process_response = client.process_unified(convert_response.csv_content)
if not process_response.error:
# Generate plot for a specific sample
png_bytes = client.draw_plot(
handle=process_response.handle,
index=0
)
# Save plot
with open("prediction.png", "wb") as f:
f.write(png_bytes)
# Check server health
health = client.health()
print(f"Server status: {health.status}")
print(f"Models initialized: {health.models_initialized}")
print(f"Total requests: {health.total_requests_processed}")
# Clean up
client.close()
Async API
For async applications:
from glucosedao_client import AsyncGluRPCClient, GluRPCConfig
async def main():
config = GluRPCConfig(base_url="http://localhost:8000")
async with AsyncGluRPCClient(config) as client:
# Convert file
convert_response = await client.convert_to_unified("data.csv")
# Process data
process_response = await client.process_unified(
convert_response.csv_content
)
# Get plot
png_bytes = await client.draw_plot(
process_response.handle,
index=0
)
Using the Web Interface
- Configure Server: Enter the GluRPC server URL and API key (if required)
- Check Health: Click "Check Server Health" to verify connectivity
- Upload Data: Upload a CGM data file (Dexcom, LibreView, etc.)
- View Predictions: The app will automatically process and show predictions
- Explore Samples: Use the slider to view predictions for different time windows
Supported Data Formats
The client supports any CGM data format that GluRPC server supports:
- Dexcom
- LibreView (Freestyle Libre)
- Nightscout exports
- And more...
The server handles all format conversion automatically.
Configuration
Environment Variables
You can set default configuration using environment variables:
export GLURPC_URL="http://localhost:8000"
export GLURPC_API_KEY="your-api-key"
Logging
Logs are saved to logs/app_<timestamp>.log with both console and file output. The client uses Python's standard logging library with DEBUG level for files and INFO level for console output.
Development
Setting up Development Environment
# Clone the repository
git clone https://github.com/glucosedao/glucosedao_client.git
cd glucosedao_client
# Install dependencies with uv
uv sync
# Run in development mode
uv run python -m glucosedao_client.app
Running Tests
# Install test dependencies
uv add --dev pytest pytest-asyncio httpx
# Run tests
uv run pytest
Architecture
This reference implementation demonstrates proper client architecture:
Core Components
-
client.py: Complete HTTP client for GluRPC API- Sync (
GluRPCClient) and async (AsyncGluRPCClient) implementations - Type-safe response models with Pydantic
- Connection pooling and timeout management
- Error handling and retry logic
- Sync (
-
app.py: Production-ready Gradio web interface (1000+ LOC)- Real-time server health monitoring with live graphs
- Automatic request cancellation for smooth slider interaction
- Data quality warnings from server validation
- Format conversion and unified CSV export
- Interactive Plotly visualizations
- Client-side performance tracking
-
server.py: Development server utilities- Local test server management
- Process lifecycle handling
-
cli.py: Typer-based CLI- Multiple launch modes (client-only, with-server, server-only)
- Health check utilities
- Flexible configuration options
Client-Server Interaction
The reference implementation demonstrates:
-
Efficient API Usage:
- File upload → Convert to unified format
- Process unified data → Get handle + warnings
- Draw plots on demand with caching
-
Request Management:
- Client-side request ID tracking
- Automatic cancellation of stale requests
- Server-side concurrent request handling
-
Real-time Monitoring:
- Health polling with 1-second updates
- Historical metrics visualization
- Queue size and processing time tracking
-
User Experience:
- Automatic plot generation on file upload
- Smooth slider interaction with debouncing
- Clear status messages and error handling
- Download options for data and plots
Troubleshooting
Server Not Responding
# Check if server is running
glucosedao-client check --url http://your-server:8000
# Try starting a local test server
glucosedao-client launch --with-server
API Key Errors
Make sure you're providing the correct API key in the web interface or:
config = GluRPCConfig(
base_url="http://localhost:8000",
api_key="your-api-key"
)
Port Already in Use
If the default port is in use:
# Use a different port
glucosedao-client launch --port 8080
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Apache 2.0 - See LICENSE file for details.
Links
Why This is a Reference Implementation
This client serves as the official example of how to properly integrate with GluRPC:
✅ Complete API Coverage: Shows how to use all GluRPC endpoints
✅ Best Practices: Demonstrates proper error handling, caching, and request management
✅ Type Safety: Uses Pydantic models for all API interactions
✅ Production Ready: Includes monitoring, logging, and performance tracking
✅ Async Support: Shows both sync and async usage patterns
✅ User Experience: Implements smart features like request cancellation and live updates
Use this client as a template when building your own GluRPC integrations!
Technology Stack
- Gradio 4.x - Interactive web interface with real-time updates
- httpx - Modern async HTTP client
- Typer - CLI framework with type hints
- Plotly - Interactive scientific visualization
- Pydantic 2 - Data validation and settings management
- cgm-format - CGM data format handling
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 glucosedao_client-0.2.0.tar.gz.
File metadata
- Download URL: glucosedao_client-0.2.0.tar.gz
- Upload date:
- Size: 276.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f25536925b8817e7ffac9c8837d59a62b71a533e3a245f72bf59bf2b10f738c2
|
|
| MD5 |
38b6343ad1bbf7c453be4ecff2c53faa
|
|
| BLAKE2b-256 |
0abb8920ce76e401efd26475e82e037c901df992f09c6c6ebbe5f605497b6790
|
File details
Details for the file glucosedao_client-0.2.0-py3-none-any.whl.
File metadata
- Download URL: glucosedao_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
349a9f9a1330fef8331312166c12d129e27421d508cbda813f99cf7ede475663
|
|
| MD5 |
ac2a061b5f5c24724ecdfca2b7db0f33
|
|
| BLAKE2b-256 |
3d6ddde25ea6b47b45c5271d0c1eab598ea8dd9a9952e2114f3e4fc69a8998d3
|