Skip to main content

Python bindings for the Open-Meteo file format

Project description

Python Bindings for Open Meteo File Format

Python 3.9+ PyPI version Build and Test

Features

  • Read Open-Meteo (.om) files directly from cloud storage using Python
  • Traverse the hierarchical data structure
  • Arrays/array slices are returned directly as NumPy arrays
  • Support for fsspec and xarray
  • Chunked data access behind the scenes

Installation

pip install omfiles

Pre-Built Wheels & Platform Support

We provide pre-built wheels for the following platforms:

  • Linux x86_64 (manylinux_2_28)
  • Linux aarch64 (manylinux_2_28)
  • Linux musl x86_64 (musllinux_1_2)
  • Windows x64
  • macOS x86_64
  • macOS ARM64 (Apple Silicon)

Stability Notice

This project is now stable as of version 1.0.0. The public API is considered stable and will follow semantic versioning. Breaking changes will not be introduced in 1.x releases without a major version bump.

Reading

Reading Files without Hierarchy

OM files are structured like a tree of variables. The following example assumes that the file test_file.om contains an array variable as a root variable which has a dimensionality greater than 2 and a size of at least 2x100:

from omfiles import OmFileReader

reader = OmFileReader("test_file.om")
data = reader[0:2, 0:100, ...]
reader.close() # Close the reader to release resources

Reading Hierarchical Files, e.g. S3 Spatial Files

import fsspec
import numpy as np
from omfiles import OmFileReader

# URI of the file on S3
s3_uri = "s3://openmeteo/data_spatial/dwd_icon/2025/09/23/0000Z/2025-09-30T0000.om"
# Create and open filesystem, wrapping it in a blockcache
backend = fsspec.open(
    f"blockcache::{s3_uri}",
    mode="rb",
    s3={"anon": True, "default_block_size": 65536},  # s3 settings
    blockcache={"cache_storage": "cache", "same_names": True},  # blockcache settings
)
# Create reader from the fsspec file object using a context manager.
# This will automatically close the file when the block is exited.
with OmFileReader(backend) as root:
    # We are at the root of the data hierarchy!
    # What type of node is this?
    print(f"root.is_array: {root.is_array}")  # False
    print(f"root.is_scalar: {root.is_scalar}")  # False
    print(f"root.is_group: {root.is_group}")  # True

    temperature_reader = root.get_child_by_name("temperature_2m")
    print(f"temperature_reader.is_array: {temperature_reader.is_array}")  # True
    print(f"temperature_reader.is_scalar: {temperature_reader.is_scalar}")  # False
    print(f"temperature_reader.is_group: {temperature_reader.is_group}")  # False

    # What shape does the stored array have?
    print(f"temperature_reader.shape: {temperature_reader.shape}")  # (1441, 2879)

    # Read all data from the array
    temperature_data = temperature_reader.read_array((...))
    print(f"temperature_data.shape: {temperature_data.shape}")  # (1441, 2879)

    # It's also possible to read any subset of the array
    temperature_data_subset1 = temperature_reader.read_array((slice(0, 10), slice(0, 10)))
    print(temperature_data_subset1)
    print(f"temperature_data_subset1.shape: {temperature_data_subset1.shape}")  # (10, 10)

    # Numpy basic indexing is supported for direct access if the reader is an array.
    temperature_data_subset2 = temperature_reader[0:10, 0:10]
    print(temperature_data_subset2)
    print(f"temperature_data_subset2.shape: {temperature_data_subset2.shape}")  # (10, 10)

    # Compare the two temperature subsets and verify that they are the same
    are_equal = np.array_equal(temperature_data_subset1, temperature_data_subset2, equal_nan=True)
    print(f"Are the two temperature subsets equal? {are_equal}")

Writing

Single Array

import numpy as np
from omfiles import OmFileWriter

# Create sample data
data = np.random.rand(100, 100).astype(np.float32)

# Initialize writer
writer = OmFileWriter("simple.om")

# Write array with compression
array_variable = writer.write_array(
    data,
    chunks=[50, 50],
    scale_factor=1.0,
    add_offset=0.0,
    compression="pfor_delta_2d",
    name="data"
)

# Finalize the file using array_variable as entry-point
writer.close(array_variable)

Hierarchical Structure

import numpy as np
from omfiles import OmFileWriter

# Create sample data
features = np.random.rand(1000, 64).astype(np.float32)
labels = np.random.randint(0, 10, size=(1000,), dtype=np.int32)

# Initialize writer
writer = OmFileWriter("hierarchical.om")

# Write child arrays first
features_var = writer.write_array(features, chunks=[100, 64], name="features", compression="pfor_delta_2d")
labels_var = writer.write_array(labels, chunks=[100], name="labels")
metadata_var = writer.write_scalar(42, name="metadata")

# Create root group with children
root_var = writer.write_group(
    name="root",
    children=[features_var, labels_var, metadata_var],
)
# Finalize the file using root_var as entry-point into the hierarchy
writer.close(root_var)

Development

# install the required dependencies in .venv directory
uv sync
# to run the tests
uv run pytest tests/
# to build the wheels
uv run build
# or to trigger maturin directly:
# maturin develop

Tests

cargo test

runs rust tests.

uv run pytest tests/

runs Python tests.

Python Type Stubs

Can be generated from the rust doc comments via

cargo run stub_gen

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

omfiles-1.0.0.tar.gz (201.0 kB view details)

Uploaded Source

Built Distributions

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

omfiles-1.0.0-cp39-abi3-win_amd64.whl (802.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

omfiles-1.0.0-cp39-abi3-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

omfiles-1.0.0-cp39-abi3-manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

omfiles-1.0.0-cp39-abi3-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

omfiles-1.0.0-cp39-abi3-macosx_11_0_arm64.whl (936.2 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

omfiles-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl (919.4 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file omfiles-1.0.0.tar.gz.

File metadata

  • Download URL: omfiles-1.0.0.tar.gz
  • Upload date:
  • Size: 201.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for omfiles-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a407be2eb14b1ceb778ebc5e776a5f6881ffb7285e71ed41380cd6de65ecabad
MD5 f68feda1aa828c139de4c8aa20f3e7a0
BLAKE2b-256 ffa8475ce93e0b0ca4424818ac425814b2a9625ab8f5918e9ab7648ae0626f42

See more details on using hashes here.

File details

Details for the file omfiles-1.0.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: omfiles-1.0.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 802.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for omfiles-1.0.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e2e0a60b1c63237956f9ebdc822b76bab281bff2566d16392046afae3e2e0fc8
MD5 ca5fe559af83d0b9113972545e25bf57
BLAKE2b-256 71419b957c1802576bd4fd51a8ff0b3e404d57a196c159669ef5b1d9195db2a5

See more details on using hashes here.

File details

Details for the file omfiles-1.0.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-1.0.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 affaf3c443dd21cb75a1f2cf433657f4d5c4cdd49e23a4782a8d9054d0ec8d20
MD5 70a33906739c734dfd5077d92a9a5614
BLAKE2b-256 11fa06371c802fd413b854a5249266f9be0ce4231584e9f3a45ce266a0000bf9

See more details on using hashes here.

File details

Details for the file omfiles-1.0.0-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-1.0.0-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a68ce442fee8bc5d4b4255f4047b86c688cd346a861b6cfe31a35f42f87e5583
MD5 edb8200d67626b99a46249755c08dc9f
BLAKE2b-256 3083ba2d49a0ec31c8567e0b5d16c531b3005da563c9c6cfa2fc1c4c66a81ea2

See more details on using hashes here.

File details

Details for the file omfiles-1.0.0-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for omfiles-1.0.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e1914e30581770b2c17b1d97fb476c1f21952b888bd8aa49307265edb90f17f9
MD5 4ec284cf812b255df6ea1cabc4cf9aaf
BLAKE2b-256 1c7ccd84c7c9c4edcdc5da65b024f661e793a2894c3976d2294cc40ea9583c4d

See more details on using hashes here.

File details

Details for the file omfiles-1.0.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for omfiles-1.0.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a1511e6e063028a1bb7928fe43e470f2e27411f85bca0fdaf3c2f0410e5b84c
MD5 db72e5124b108036ac3b0dd6be7e38e9
BLAKE2b-256 7e79c890fc54d2a1e4c236b8128b05ca76af3d4a77f4007ab8f2dcbe0f01f1d7

See more details on using hashes here.

File details

Details for the file omfiles-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8008959831fa71507d301464049a7c54a77f63a89cdfcb2bec101ed5b2b463f0
MD5 bad8d5130f94ce5d6150bf238f93919b
BLAKE2b-256 da5a3505033239c48d31fa524d5dacdfd4c2f2aea731ca8369599f594fa5341f

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