Skip to main content

No project description provided

Project description

csvw

Build Status codecov Requirements Status PyPI

CSV on the Web

Links

Installation

This package runs under Python >=3.6, 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 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).

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 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.

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

License

This package is distributed under the Apache 2.0 license.

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

csvw-2.0.0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

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

csvw-2.0.0-py2.py3-none-any.whl (35.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file csvw-2.0.0.tar.gz.

File metadata

  • Download URL: csvw-2.0.0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.56.2 importlib-metadata/4.10.1 keyring/22.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for csvw-2.0.0.tar.gz
Algorithm Hash digest
SHA256 97cf1bf28cd739475d58b6a7c846faac07d7d3191b0b25acda4a4419364d15dd
MD5 3219037b0ecf3036e01dccc65654fbe4
BLAKE2b-256 a18acb368053d3e08b912859aeb77e9715b9a4923fd302d664088e5d08b93853

See more details on using hashes here.

File details

Details for the file csvw-2.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: csvw-2.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 35.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.56.2 importlib-metadata/4.10.1 keyring/22.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for csvw-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2aaf52b5449254cbde42c6ad8ca662c3ebf42bfe5fc32a976ecb1a89163c0997
MD5 596251a52932d3f474e529b82d6a1a3b
BLAKE2b-256 106444ac707161c8e3d46d93b83edd3aad820b9467ad3106472eda4d84525723

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