Skip to main content

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.

Metadata

Release files for fewsxml 0.2.2

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

Source distribution (sdist)

Source distribution for fewsxml 0.2.2
File Size Uploaded
fewsxml-0.2.2.tar.gz 33.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fewsxml 0.2.2
File Interpreter ABI Platform
fewsxml-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 71.2 kB

Release files / fewsxml-0.2.2.tar.gz

Download URL fewsxml-0.2.2.tar.gz
Size 33.2 kB
Tags Source
SHA-256 checksum
How to use checksums
54cbac8ba940f0349dba166b1bd142e8ecf1a8351ddcd2ff26631490ca261530
BLAKE2b-256 checksum
How to use checksums
5ffe83872eb12336cedb2b1dd1f9267b491475e750125db72b36a4f01993fb73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / fewsxml-0.2.2-py3-none-any.whl

Download URL fewsxml-0.2.2-py3-none-any.whl
Size 37.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5aa8f05721c8014f4be83c9addb5924e0a24776db08b1a0ffe37d9031c168ba5
BLAKE2b-256 checksum
How to use checksums
a7164e35a9741e37556fc71bc456a763a58eb916c0aebc634c63373e2af0be9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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