https://github.com/cldf/csvw

CSV on the web

https://github.com/cldf/csvw

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 4 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.5%) to scientific vocabulary

Keywords

csv csvw python tabular-data

Keywords from Contributors

linguistics
Last synced: 5 months ago · JSON representation

Repository

CSV on the web

Basic Info
  • Host: GitHub
  • Owner: cldf
  • License: apache-2.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 320 KB
Statistics
  • Stars: 38
  • Watchers: 8
  • Forks: 6
  • Open Issues: 0
  • Releases: 4
Topics
csv csvw python tabular-data
Created over 8 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog Contributing License

README.md

csvw

Build Status PyPI Documentation Status

This package provides - a Python API to read and write relational, tabular data according to the CSV on the Web specification and - commandline tools for reading and validating CSVW data.

Links

  • GitHub: https://github.com/cldf/csvw
  • PyPI: https://pypi.org/project/csvw
  • Issue Tracker: https://github.com/cldf/csvw/issues

Installation

This package runs under Python >=3.8, use pip to install:

bash $ pip install csvw

CLI

csvw2json

Converting CSVW data to JSON

shell $ csvw2json tests/fixtures/zipped-metadata.json { "tables": [ { "url": "tests/fixtures/zipped.csv", "row": [ { "url": "tests/fixtures/zipped.csv#row=2", "rownum": 1, "describes": [ { "ID": "abc", "Value": "the value" } ] }, { "url": "tests/fixtures/zipped.csv#row=3", "rownum": 2, "describes": [ { "ID": "cde", "Value": "another one" } ] } ] } ] }

csvwvalidate

Validating CSVW data

shell $ csvwvalidate tests/fixtures/zipped-metadata.json OK

csvwdescribe

Describing tabular-data files with CSVW metadata

shell $ csvwdescribe --delimiter "|" tests/fixtures/frictionless-data.csv { "@context": "http://www.w3.org/ns/csvw", "dc:conformsTo": "data-package", "tables": [ { "dialect": { "delimiter": "|" }, "tableSchema": { "columns": [ { "datatype": "string", "name": "FK" }, { "datatype": "integer", "name": "Year" }, { "datatype": "string", "name": "Location name" }, { "datatype": "string", "name": "Value" }, { "datatype": "string", "name": "binary" }, { "datatype": "string", "name": "anyURI" }, { "datatype": "string", "name": "email" }, { "datatype": "string", "name": "boolean" }, { "datatype": { "dc:format": "application/json", "base": "json" }, "name": "array" }, { "datatype": { "dc:format": "application/json", "base": "json" }, "name": "geojson" } ] }, "url": "tests/fixtures/frictionless-data.csv" } ] }

Python API

Find the Python API documentation at csvw.readthedocs.io.

A quick example for using csvw from Python code:

python import json from csvw import CSVW data = CSVW('https://raw.githubusercontent.com/cldf/csvw/master/tests/fixtures/test.tsv') print(json.dumps(data.to_json(minimal=True), indent=4)) [ { "province": "Hello", "territory": "world", "precinct": "1" } ]

Known limitations

  • We read all data which is specified as UTF-8 encoded using the utf-8-sig codecs. Thus, if such data starts with U+FEFF this will be interpreted as BOM and skipped.
  • Low level CSV parsing is delegated to the csv module in Python's standard library. Thus, if a commentPrefix is specified in a Dialect instance, this will lead to skipping rows where the first value starts with commentPrefix, even if the value was quoted.
  • Also, cell content containing escapechar may not be round-tripped as expected (when specifying escapechar or a csvw.Dialect with quoteChar but doubleQuote==False), when minimal quoting is specified. This is due to inconsistent csv behaviour across Python versions (see https://bugs.python.org/issue44861).

CSVW conformance

While we use the CSVW specification as guideline, this package does not (and probably never will) implement the full extent of this spec.

  • When CSV files with a header are read, columns are not matched in order with column descriptions in the tableSchema, but instead are matched based on the CSV column header and the column descriptions' name and titles atributes. This allows for more flexibility, because columns in the CSV file may be re-ordered without invalidating the metadata. A stricter matching can be forced by specifying "header": false and "skipRows": 1 in the table's dialect description.

However, csvw.CSVW works correctly for - 269 out of 270 JSON tests, - 280 out of 282 validation tests, - 10 out of 18 non-normative tests

from the CSVW Test suites.

Compatibility with Frictionless Data Specs

A CSVW-described dataset is basically equivalent to a Frictionless DataPackage where all Data Resources are Tabular Data. Thus, the csvw package provides some conversion functionality. To "read CSVW data from a Data Package", there's the csvw.TableGroup.from_frictionless_datapackage method: python from csvw import TableGroup tg = TableGroup.from_frictionless_datapackage('PATH/TO/datapackage.json') To convert the metadata, the TableGroup can then be serialzed: python tg.to_file('csvw-metadata.json')

Note that the CSVW metadata file must be written to the Data Package's directory to make sure relative paths to data resources work.

This functionality - together with the schema inference capabilities of frictionless describe - provides a convenient way to bootstrap CSVW metadata for a set of "raw" CSV files, implemented in the csvwdescribe command described above.

See also

  • https://www.w3.org/2013/csvw/wiki/Main_Page
  • https://csvw.org
  • https://github.com/CLARIAH/COW
  • https://github.com/CLARIAH/ruminator
  • https://github.com/bloomberg/pycsvw
  • https://specs.frictionlessdata.io/table-schema/
  • https://github.com/theodi/csvlint.rb
  • https://github.com/ruby-rdf/rdf-tabular
  • https://github.com/rdf-ext/rdf-parser-csvw
  • https://github.com/Robsteranium/csvwr

License

This package is distributed under the Apache 2.0 license.

Owner

  • Name: Cross-Linguistic Data Formats
  • Login: cldf
  • Kind: organization

GitHub Events

Total
  • Issues event: 1
  • Watch event: 6
  • Push event: 6
  • Fork event: 1
  • Create event: 2
Last Year
  • Issues event: 1
  • Watch event: 6
  • Push event: 6
  • Fork event: 1
  • Create event: 2

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 224
  • Total Committers: 4
  • Avg Commits per committer: 56.0
  • Development Distribution Score (DDS): 0.286
Top Committers
Name Email Commits
xrotwang x****g@g****m 160
Sebastian Bank s****k@u****e 59
Stephan Schiffels s****s@m****m 4
Tiago Tresoldi t****i@s****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 61
  • Total pull requests: 18
  • Average time to close issues: 3 months
  • Average time to close pull requests: 1 day
  • Total issue authors: 16
  • Total pull request authors: 5
  • Average comments per issue: 2.74
  • Average comments per pull request: 2.33
  • Merged pull requests: 17
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 8
  • Pull requests: 0
  • Average time to close issues: 1 day
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 4.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • xrotwang (28)
  • Anaphory (8)
  • megin1989 (6)
  • xflr6 (4)
  • stschiff (2)
  • alexshpilkin (2)
  • LinguList (2)
  • SimonGreenhill (2)
  • ioggstream (1)
  • PaprikaSteiger (1)
  • fmatter (1)
  • danbri (1)
  • bencomp (1)
  • fabaff (1)
  • brockfanning (1)
Pull Request Authors
  • xrotwang (10)
  • xflr6 (5)
  • stschiff (1)
  • Anaphory (1)
  • tresoldi (1)
Top Labels
Issue Labels
bug (9) enhancement (4) wontfix (3) invalid (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 379,956 last-month
  • Total docker downloads: 427,687
  • Total dependent packages: 20
  • Total dependent repositories: 317
  • Total versions: 40
  • Total maintainers: 3
pypi.org: csvw

Python library to work with CSVW described tabular data

  • Versions: 40
  • Dependent Packages: 20
  • Dependent Repositories: 317
  • Downloads: 379,956 Last month
  • Docker Downloads: 427,687
Rankings
Dependent packages count: 0.6%
Dependent repos count: 0.8%
Docker downloads count: 1.0%
Downloads: 1.1%
Average: 4.8%
Stargazers count: 11.1%
Forks count: 14.2%
Maintainers (3)
Last synced: 6 months ago

Dependencies

.github/workflows/python-package.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
pyproject.toml pypi
requirements.txt pypi
setup.py pypi