Skip to main content

IncCSV.py

A Python implementation of the INC file format, interoperable with the original Julia library IncCSV.jl.

What is INC?

INC (INi-Csv) is a lightweight file format that embeds INI-style metadata directly inside a CSV file, separated by a --- delimiter:

---
title = Sensor readings
version = 1
[columns]
time = seconds
temperature = Celsius
---
time,temperature
0,21.4
1,21.8
2,22.1

The goal is to make tabular data self-describing — units, provenance, and other context travel with the file rather than being stored separately. Plain CSV files are read without modification, so the format is fully backward compatible.

See the Julia reference implementation for the full format specification and design rationale.

Installation

pip install inccsv

With pandas support:

pip install inccsv[pandas]

Usage

Reading

import inccsv

# Read an INC file
f = inccsv.read_inc("data.inc")
print(f.metadata)          # {'title': 'Sensor readings', 'version': 1, 'columns': {...}}
print(f.rows)              # [{'time': '0', 'temperature': '21.4'}, ...]

# Convert to a pandas DataFrame
df = f.to_dataframe()

# Plain CSV files work too
f = inccsv.read_inc("data.csv")

Writing

rows = [
    {"time": "0", "temperature": "21.4"},
    {"time": "1", "temperature": "21.8"},
]
metadata = {
    "title": "Sensor readings",
    "version": 1,
    "columns": {"time": "seconds", "temperature": "Celsius"},
}

inccsv.write_inc("data.inc", rows, metadata=metadata)

Schema validation

A schema is itself an INC file that declares required and optional metadata fields:

---
[schema]
allow_extra = false

[MUST]
title = String
version = Int

[OPTIONAL]
author = String
---
schema = inccsv.read_schema("schema.inc")
result = inccsv.validate_schema(f, schema)
print(result.valid)    # True / False
print(result.missing)  # required fields absent from the file
print(result.extra)    # fields not declared in the schema

Summary

s = inccsv.summarise(f)
print(s.n_rows, s.n_cols)
inccsv.print_summary(f)

Format notes

  • Metadata values are int (unquoted integers) or str (everything else). Quote values that look like integers to preserve them as strings: id = "007".
  • The [structure] section passes CSV options to the reader: delimiter, quotechar, comment.
  • The delimiter line accepts any sequence of 3+ Unicode dash characters (-, –, —, …).
  • Files are UTF-8 encoded.

Interoperability

This library aims to be fully interoperable with IncCSV.jl. Files written by either library should be readable by the other.

Development

git clone https://github.com/lewismath/IncCSV.py
cd IncCSV.py
pip install -e ".[dev]"
pytest

Metadata

Release files for inccsv 0.1.0

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

Source distribution (sdist)

Source distribution for inccsv 0.1.0
File Size Uploaded Provenance
inccsv-0.1.0.tar.gz 321.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for inccsv 0.1.0
File Interpreter ABI Platform
inccsv-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 333.4 kB

Release files / inccsv-0.1.0.tar.gz

Download URL inccsv-0.1.0.tar.gz
Size 321.3 kB
Tags Source
SHA-256 checksum
How to use checksums
32b19408ca05687403dafe6f12a662325e5a578ca9d0566b4379a216a805f0c2
BLAKE2b-256 checksum
How to use checksums
d615d2d2939b5fed38a3bcd77e616ef9f6cc4e952024ea722f0e7a8ca62a99ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Release files / inccsv-0.1.0-py3-none-any.whl

Download URL inccsv-0.1.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65177c80d1eb6f7b02ac354d2ea21468fc7246015a7a6191f51279d9f6c61936
BLAKE2b-256 checksum
How to use checksums
7d54e14a0ed01c35ad846c71fd0e6e7dc3d2994b379e21b835d9dd09bc2279d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Security for inccsv 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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