Skip to main content

A library for reading and writing XML files to interact with Delft-FEWS.

Project description

fewsxml

Table of Contents

Installation

pip install fewsxml

Overview

fewsxml provides Python APIs to construct, read, and write PI-XML files compatible with the Delft-FEWS system. It uses Pydantic models for data validation and supports the PI TimeSeries schema.

There are two main categories of functions:

  1. Creating PI-XML Files: Functions to create PIHeader, PISeries, and PITimeSeries objects, and to write them to XML files.
  2. Reading PI-XML Files: Functions to read and parse existing PI-XML files into Pydantic models.

Usage Example

Creating a PI-XML File and Writing to Disk

Below is a minimal example to create a PI-XML file with a time series, including all required header fields such as timeStep and missVal:

from fewsxml import (
    create_pi_header, create_pi_series, create_pi_timeseries, write,
    PITimeStep
)
from datetime import datetime

time_step = PITimeStep(unit="second", multiplier=3600)

# Create the header with all required fields
header = create_pi_header(
    type="instantaneous",
    location_id="LOC001",
    parameter_id="H.waterlevel",
    start_date=datetime(2023, 1, 1, 0, 0),
    end_date=datetime(2023, 1, 1, 2, 0),
    timeStep=time_step,
    missVal="-999"
)

# Create events (time series values)
events = [
    {"date": datetime(2023, 1, 1, 0, 0), "value": 1.23},
    {"date": datetime(2023, 1, 1, 1, 0), "value": 1.25},
    {"date": datetime(2023, 1, 1, 2, 0), "value": 1.20},
]

# Build the series and root object
series = create_pi_series(header, events)
pi = create_pi_timeseries(series)

# Write to XML file
write(pi, "output.xml")

Reading a PI-XML File and Creating Pydantic Models

import fewsxml as fx
parsed_timeseries = fx.read("timeseries_import.xml")

The parsed_timeseries variable now contains a PITimeSeries object with all data from the XML file, accessible via Pydantic models. As mentioned in the previous example, you can create an XML file from these models using the write function: fx.write(parsed_timeseries, "output.xml"). The created XML file will be compatible with the PI TimeSeries schema.

Developer Documentation

Developers and contributors should refer to the Developer Guide for test, CI, and pre-commit instructions.

API Reference

  • create_pi_header(...): Creates a PIHeader object (series metadata).
  • create_pi_series(header, events, ...): Creates a PISeries object from a header and events.
  • create_pi_timeseries(series, ...): Creates the root PITimeSeries object.
  • write(pi, filename): Writes a PITimeSeries object to an XML file.

Schema Compatibility

The generated XML files are compatible with the PI TimeSeries schema.

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

fewsxml-0.2.1.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

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

fewsxml-0.2.1-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file fewsxml-0.2.1.tar.gz.

File metadata

  • Download URL: fewsxml-0.2.1.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for fewsxml-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ddb75a0b8552ad660e7fb54e0866d68780f4de8fa4e364c219ee3b4a753d67e7
MD5 374a9161aff84bf860d0b3bae7dd5902
BLAKE2b-256 87a72bc312687c379128c4ac7cdb6a5c3c9dc2fb348eb3291b4ea6f0bb84ec72

See more details on using hashes here.

File details

Details for the file fewsxml-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fewsxml-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for fewsxml-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b24f63cbf2a3ffcdb4e8ea6632d49cf111fa041c3309231523d206a4374e44f5
MD5 15b0db4680ea9d7f45fcb3e9f81c4229
BLAKE2b-256 e4d4f3399c306956f34dcdd0f230a4226c87b0a70d4abc6ff863a2ae9f08cde3

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