CSVW Python Library

3.7.0 · active · verified Sun Apr 12

The `csvw` Python library (version 3.7.0) provides an API to read and write relational, tabular data in adherence to the W3C CSV on the Web specification. It offers functionalities for parsing CSVW described data, converting it to JSON, and validating metadata. The project maintains an active development status with regular releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a `CSVW` object from a URL pointing to a TSV file (or a CSVW metadata file) and then convert the described data to a JSON representation. The `to_json()` method serializes the tabular data according to the CSVW specification.

import json
from csvw import CSVW
import os

# Example using a remote CSVW metadata file
# Note: In a real application, you might use a local file path.
# Ensure 'https://raw.githubusercontent.com/cldf/csvw/master/tests/fixtures/test.tsv' is accessible.

try:
    data = CSVW('https://raw.githubusercontent.com/cldf/csvw/master/tests/fixtures/test.tsv')
    # Convert the CSVW data to JSON
    json_output = data.to_json()
    print(json.dumps(json_output, indent=2))
except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure the URL is correct and accessible.")

view raw JSON →