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:
- Creating PI-XML Files: Functions to create PIHeader, PISeries, and PITimeSeries objects, and to write them to XML files.
- 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fewsxml-0.2.0.tar.gz.
File metadata
- Download URL: fewsxml-0.2.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc8a7d0da2c19d3b5415447b77e87a8a34676102b4f018d7b6bf1e1d0a90a9bb
|
|
| MD5 |
3433821dcfc6a01ed13e8bf9f7ad35c0
|
|
| BLAKE2b-256 |
0c5fbe9ffea3c0f7ef52108df13f860e3378c3208344fbccdcb10a0deb108ff4
|
File details
Details for the file fewsxml-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fewsxml-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5f52ce534eed4e2f41431a36c225d1424722df1923a1e429a9b7165659ce000
|
|
| MD5 |
ff3570fba17ddec70c434c662167931f
|
|
| BLAKE2b-256 |
867d52ff7270085fe243d51a87eb5d18f163cc00599fe5110fbccb25ff54486c
|