Skip to main content

Read, write, and transform iCSV files.

Project description

icsv

iCSV logo

icsv is a Python package for reading, writing, validating, and transforming interoperable CSV (iCSV) files.

Note: this repository provides the Python interface for iCSV. The iCSV format specification itself is maintained in EnviDat/icsv: https://gitlabext.wsl.ch/EnviDat/icsv

It supports:

  • Standard iCSV files (# iCSV 1.0 UTF-8)
  • 2D timeseries application profile files (# iCSV 1.0 UTF-8 2DTIMESERIES)
  • Conversion of SMET-like objects into iCSV structures

Installation

pip install interoperable-csv

Import path stays:

import icsv

What Is iCSV?

iCSV is a text-based, self-describing data format for environmental time series. It combines CSV data rows with structured header metadata.

An iCSV file is organized in sections:

  • [METADATA]: global attributes (station info, geometry, delimiter, etc.)
  • [FIELDS]: column definitions and per-column attributes
  • [DATA]: tabular data rows

Typical header example:

# iCSV 1.0 UTF-8
# [METADATA]
# field_delimiter = ,
# geometry = POINTZ(9.81 46.831 2540.0)
# srid = EPSG:4326
# [FIELDS]
# fields = timestamp,hs
# [DATA]

Required metadata keys for standard files:

  • field_delimiter
  • geometry
  • srid

Quickstart

import icsv

f = icsv.read("input.icsv")
print(f.get_field("fields"))
print(f.get_metadata("station_id"))
f.write("copy.icsv")

Create a new file:

import pandas as pd
import icsv

f = icsv.iCSVFile()
f.set_metadata("field_delimiter", ",")
f.set_metadata("geometry", "POINTZ(8.0 47.0 1200)")
f.set_metadata("srid", "EPSG:4326")
f.set_metadata("station_id", "WFJ")
f.set_fields("fields", ["timestamp", "hs"])
f.setData(pd.DataFrame({"timestamp": ["2024-01-01T00:00:00"], "hs": [40.2]}))
f.write("out.icsv")

2D timeseries profile support:

  • icsv.iCSV2DTimeseries for read/write of [DATE=...] blocks
  • icsv.append_timepoint(...) to append profile timesteps

Core API:

  • icsv.read(path) auto-detects standard vs 2D profile format
  • icsv.iCSVFile standard iCSV object
  • icsv.iCSV2DTimeseries profile object
  • icsv.from_smet(smet_obj) SMET to iCSV conversion

Documentation

Project documentation:

For iCSV format specification changes, open issues at:

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

interoperable_csv-0.2.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

interoperable_csv-0.2.1-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for interoperable_csv-0.2.1.tar.gz
Algorithm Hash digest
SHA256 55653c701d306a2959c61694436d456db6a0f54aaeafa1dc461b01c06dbe4ad7
MD5 6fca145d7c20538220bb6b18ca02c4c4
BLAKE2b-256 2bd31dbbe8d87232a4ad6727ea606357db3cbf061c8866b0ae748de43d170c3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for interoperable_csv-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b50f46c39a89f042f80e75d3a91c3f2fe408de0e90edffe4ed4d95be445eb88
MD5 0cac1b565805c54e13d98cc0c6738b10
BLAKE2b-256 1968cc21e8844cd7fbcbfce277927a79f5a53523bf9b750f2b956715493a7fdd

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