Skip to main content

Python client for the MyHospitals Data API (Australian Institute of Health and Welfare)

Project description

aihw_myhospitals_api

A Rust client for the MyHospitals Data API provided by the Australian Institute of Health and Welfare (AIHW).

Features

  • Auto-generated from OpenAPI specification using Progenitor
  • Async/await support with Tokio
  • Builder pattern for ergonomic API calls
  • Strongly typed requests and responses
  • 38 API endpoints covering all MyHospitals data

Installation

Add to your Cargo.toml:

[dependencies]
aihw_myhospitals_api = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

Quick Start

use aihw_myhospitals_api::{Client, new_client};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Using the convenience function
    let client = new_client();

    // Or with explicit URL
    let client = Client::new("https://myhospitalsapi.aihw.gov.au");

    // Fetch measure categories
    let response = client.get_measure_categories().send().await?;
    println!("Found {} categories", response.result.len());

    // Fetch datasets
    let response = client.get_datasets().send().await?;
    for dataset in &response.result {
        println!("{}: {} to {}",
            *dataset.data_set_name,
            dataset.reporting_start_date,
            dataset.reporting_end_date
        );
    }

    Ok(())
}

API Coverage

The client provides access to all MyHospitals API endpoints:

Category Endpoints Description
Caveats 2 Data footnotes and suppressions
Suppressions 2 Legacy suppression data (use Caveats)
DataSets 3 Grouped data periods
Measures 4 Health metrics and indicators
MeasureCategories 3 Measure classifications
ReportedMeasures 4 Reported measurement forms
ReportedMeasureCategories 3 Reported measure groupings
ReportingUnits 5 Hospitals and health services
ReportingUnitTypes 3 Unit classifications (Hospital, State, National)
FlatDataExtracts 2 Bulk data retrieval (paginated, max 1000)
Downloads 7 Excel/XLSX exports

Examples

Run the examples to explore the API:

# Basic usage
cargo run --example basic_usage

# Caveats and suppressions
cargo run --example caveats

# Datasets and data items
cargo run --example datasets

# Measures and categories
cargo run --example measures

# Reporting units (hospitals, states)
cargo run --example reporting_units

# Bulk data extracts with pagination
cargo run --example data_extracts

# Excel download codes
cargo run --example downloads

Response Structure

All API responses are wrapped in an envelope containing:

  • result - The actual data
  • version_information - API version and data version metadata
let response = client.get_reporting_unit_types().send().await?;

// Access the data
for unit_type in &response.result {
    println!("{}", *unit_type.reporting_unit_type_name);
}

// Access version info
if let Some(info) = &response.version_information {
    println!("API Version: {:?}", info.api_version);
}

Newtype Wrappers

Many fields use newtype wrappers for type safety. Dereference with * to access the underlying string:

let response = client.get_measures().send().await?;
for measure in &response.result {
    // Use * to dereference the newtype wrapper
    println!("Code: {}", *measure.measure_code);
    println!("Name: {}", *measure.measure_name);
}

Pagination

The flat data extract endpoints use skip/top pagination:

use std::num::NonZeroU32;

let response = client
    .get_flat_data_extract_by_measure_category_code()
    .measure_category_code("ED")
    .skip(0)                              // Start from beginning
    .top(NonZeroU32::new(100).unwrap())   // Get 100 items (max 1000)
    .send()
    .await?;

File Downloads

Download endpoints return ByteStream. Collect to bytes:

use futures::StreamExt;

let response = client
    .get_simple_downloads_by_download_code()
    .download_code("some-code")
    .send()
    .await?;

let mut bytes = Vec::new();
let mut stream = response.into_inner();
while let Some(chunk) = stream.next().await {
    bytes.extend_from_slice(&chunk?);
}
std::fs::write("output.xlsx", &bytes)?;

Development

Running Tests

# Unit tests
cargo test

# Integration tests (requires network)
cargo test --features integration-tests

Debug Build Output

Set DEBUG_CODEGEN=1 to see generated code paths:

DEBUG_CODEGEN=1 cargo build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Releasing

Releases are automated via GitHub Actions. To create a new release:

  1. Update version in Cargo.toml
  2. Update CHANGELOG.md with the new version
  3. Commit: git commit -am "Release v0.x.y"
  4. Tag: git tag v0.x.y
  5. Push: git push && git push --tags

The release workflow will:

  • Run all CI checks
  • Publish to crates.io
  • Create a GitHub release with changelog notes

License

Licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

Data License

Data from the MyHospitals API is licensed under CC-BY 3.0 by the Australian Institute of Health and Welfare.

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

aihw_myhospitals_api-0.1.0.tar.gz (50.1 kB view details)

Uploaded Source

Built Distribution

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

aihw_myhospitals_api-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file aihw_myhospitals_api-0.1.0.tar.gz.

File metadata

  • Download URL: aihw_myhospitals_api-0.1.0.tar.gz
  • Upload date:
  • Size: 50.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for aihw_myhospitals_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fbb2e4c0707ce3fb0c7b7c71ab2c3a8c02f2e73d2a3310edcdc4cffb65aa45ef
MD5 a675ea440eeff37d451f0d6b9ea33a9d
BLAKE2b-256 7ed3b97dd4e069bbfdb14a038da5164732deb8d4a99d30b8001cb9f018cda155

See more details on using hashes here.

File details

Details for the file aihw_myhospitals_api-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for aihw_myhospitals_api-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8370e9cb0fb6935c05df88bf43a8378ebf97a6311405ccbd2f3a3c574d4329b1
MD5 6c7099c67b0a044a8a4d3a33b20b261b
BLAKE2b-256 0b59903c655b3ecbd46be04a6e969598028fe1089ab1126daedeb1a970fc8b4e

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