Skip to main content

pyimporters-csv

Sherpa knowledge import plugin for CSV, Excel and plain text files.

It registers three parsers through the pyimporters.plugins entry point group:

Plugin Class Extensions
text pyimporters_csv.text:TXTKnowledgeParser txt, text, zip
csv pyimporters_csv.csv_parser:CSVKnowledgeParser csv, tsv, zip
excel pyimporters_csv.excel:ExcelKnowledgeParser xls, xlsx

Each parser yields Term objects from pyimporters_plugins.base. Archives (zip) are unwrapped transparently for the text and CSV parsers.

Requirements

  • Python 3.12+
  • pyimporters_plugins (>=1.6.0,<1.7.0), pandas (>=2.0), structlog, openpyxl, xlrd

Installation

pip install pyimporters-csv

Usage

from pathlib import Path

from progress.bar import Bar

from pyimporters_csv.csv_parser import CSVKnowledgeParser, CSVOptionsModel

parser = CSVKnowledgeParser()
options = CSVOptionsModel(
    encoding="utf-8",
    identifier_col="ID",
    preferredForm_col="prefLabel_en",
    altForms_cols="altLabel_en",
    multivalue_separator="|",
)
terms = list(parser.parse(Path("terms.csv"), options.model_dump(), Bar("Processing")))

Options

TXTOptions (text parser):

Option Default Description
encoding utf-8 Encoding of the file

CSVOptions extends TXTOptions:

Option Default Description
separator , Field separator
quotechar " Quote character
multivalue_separator | Separator used to split multivalued columns
header 0 Row number (0-indexed) used as column names, blank if there is no header
identifier_col identifier Name of the column used as the concept identifier
preferredForm_col preferredForm Name of the column used as the preferred form
altForms_cols altForms Name of the column used as alternative forms

ExcelOptions is the same as CSVOptions without separator and quotechar.

The three *_col options take a column name, not an index: an unknown name falls back to the default (column 0 for the identifier, the identifier column for the preferred form, no alternative forms at all) and logs a warning. Values in altForms_cols are split on multivalue_separator, so a single column can hold several alternative forms.

Development

The build is driven by Task and uv, with the shared stages coming from the python-archetype submodule:

git submodule update --init
task stages          # print the pipeline stages, in order
task                 # run the pipeline up to (but excluding) py:publish
task -- --skip-tests # same, without the test stage
task up-to -- lint   # run the pipeline up to and including one stage
task jenkins         # run every stage, exactly what Jenkins runs

Individual stages:

Task Description
task py:sync Install the workspace and its dependencies (uv sync)
task py:lint ruff check and ruff format --check
task py:format Reformat the code with ruff
task py:test Run the test suite
task py:test-marker -- <m> Run the tests carrying one pytest marker
task py:sbom Generate a CycloneDX SBOM of the resolved environment
task py:check-vulnerabilities Check for known CVEs
task py:check-updates Check for dependency updates
task py:build Build the wheel and sdist (uv build)
task py:publish Publish the distributions (uv publish)

uv.lock is not versioned here (the Jenkinsfile removes it before building), so py:sync always resolves dependencies from scratch.

SBOM & vulnerability check

task py:sbom and task py:check-vulnerabilities wrap the underlying tools; to run them by hand:

uv sync --extra sbom
uv run cyclonedx-py environment -o sbom.cdx.json --output-format json
uv run pip-audit --format json --output audit-report.json
uv run pip-audit --strict   # fail on any known vulnerability

Metadata

Release files for pyimporters-csv 1.6.491

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyimporters-csv 1.6.491
File Size Uploaded
pyimporters_csv-1.6.491.tar.gz 72.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyimporters-csv 1.6.491
File Interpreter ABI Platform
pyimporters_csv-1.6.491-py3-none-any.whl Python 3 none any Details

Total release size: 79.9 kB

Release files / pyimporters_csv-1.6.491.tar.gz

Download URL pyimporters_csv-1.6.491.tar.gz
Size 72.2 kB
Tags Source
SHA-256 checksum
How to use checksums
75b4a8c241945cdfebebd8dde49c2eca761298ae25659c0e915c5fe0a605edb8
BLAKE2b-256 checksum
How to use checksums
39aef4c9d64c240b5cde7166a79caf9d14cf5bc6feeb5de428f727aca5e1eaaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyimporters_csv-1.6.491-py3-none-any.whl

Download URL pyimporters_csv-1.6.491-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6ed94804a9faa352aae517cc5d89bb8881b9b6b3ad7ef9f3f4f275f60cdb653
BLAKE2b-256 checksum
How to use checksums
ade139b23c2623545bba61a0b29c206971a2166c4ff36ae44a2836b3923c736f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.6.491 This release

2 release files

1.6.55

2 release files

1.6.53

2 release files

1.6.51

2 release files

1.6.48

2 release files

1.6.8

2 release files

1.6.6

2 release files

0.7.12

2 release files

0.7.10

2 release files

0.7.6

2 release files

0.7.4

2 release files

0.6.46

2 release files

0.6.44

2 release files

0.6.42

2 release files

0.6.40

2 release files

0.6.38

2 release files

0.6.36

2 release files

0.6.34

2 release files

0.6.32

2 release files

0.6.30

2 release files

0.6.28

2 release files

0.6.26

2 release files

0.6.23

2 release files

0.4.133

1 release file

0.4.98

2 release files

0.4.96

2 release files

0.4.93

2 release files

0.4.90

2 release files

0.4.86

2 release files

0.4.84

2 release files

0.4.81

2 release files

0.4.72

2 release files

0.4.64

2 release files

0.4.61

2 release files

0.4.59

2 release files

0.4.51

2 release files

0.4.49

2 release files

0.4.47

2 release files

0.4.44

2 release files

0.4.40

2 release files

0.4.38

2 release files

0.3.7

2 release files

0.3.5

2 release files

0.1.36

2 release files

0.1.32

2 release files

0.1.28

2 release files

0.1.25

2 release files

0.1.23

2 release files

0.1.19

2 release files

0.1.13

2 release files

0.1.9

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page