Skip to main content

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.

Metadata

Release files for aihw-myhospitals-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aihw-myhospitals-api 0.1.0
File Size Uploaded Provenance
aihw_myhospitals_api-0.1.0.tar.gz 50.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aihw-myhospitals-api 0.1.0
File Interpreter ABI Platform
aihw_myhospitals_api-0.1.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details

Total release size: 2.2 MB

Release files / aihw_myhospitals_api-0.1.0.tar.gz

Download URL aihw_myhospitals_api-0.1.0.tar.gz
Size 50.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fbb2e4c0707ce3fb0c7b7c71ab2c3a8c02f2e73d2a3310edcdc4cffb65aa45ef
BLAKE2b-256 checksum
How to use checksums
7ed3b97dd4e069bbfdb14a038da5164732deb8d4a99d30b8001cb9f018cda155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Release files / aihw_myhospitals_api-0.1.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL aihw_myhospitals_api-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Size 2.2 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8370e9cb0fb6935c05df88bf43a8378ebf97a6311405ccbd2f3a3c574d4329b1
BLAKE2b-256 checksum
How to use checksums
0b59903c655b3ecbd46be04a6e969598028fe1089ab1126daedeb1a970fc8b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Security for aihw-myhospitals-api 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page