No project description provided
Project description
csvw
CSV on the Web
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.4, use pip to install:
$ pip install csvw
Example
>>> import csvw
>>> tg = csvw.TableGroup.from_file('tests/csv.txt-metadata.json')
>>> tg.check_referential_integrity()
>>> assert len(tg.tables) == 1
>>> assert tg.tables[0] is tg.tabledict['csv.txt']
>>> tg.tables[0].check_primary_key()
>>> from collections import OrderedDict
>>> row = next(tg.tables[0].iterdicts())
>>> assert row == OrderedDict([('ID', 'first'), ('_col.2', 'line')])
>>> assert len(list(tg.tables[0].iterdicts())) == 2
Known limitations
- We read all data which is specified as UTF-8 encoded using the
utf-8-sig
codecs. Thus, if such data starts withU+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 acommentPrefix
is specified in aDialect
instance, this will lead to skipping rows where the first value starts withcommentPrefix
, even if the value was quoted.
Deviations from the CSVW specificaton
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
andtitles
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.
Compatibility with Frictionless Data Specs
The 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:
from csvw import TableGroup
tg = TableGroup.from_frictionless_datapackage('PATH/TO/datapackage.json')
To convert the metadata, the TableGroup
can then be serialzed:
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.
See also
- https://www.w3.org/2013/csvw/wiki/Main_Page
- 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
License
This package is distributed under the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
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
Hashes for csvw-1.10.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d478357afc4e2b476f79d9692d79d4f3da9944d2f7844b0240a948a3790a1587 |
|
MD5 | 35cc18ec66ea2b3171edb30a8aaf5ecc |
|
BLAKE2b-256 | f4d828c20059d8e11eb74918a4cfc446a450f98fb44172b84417249812099694 |