Python implementation of the INC file format (INI metadata + CSV data)
Project description
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) orstr(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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inccsv-0.1.0.tar.gz.
File metadata
- Download URL: inccsv-0.1.0.tar.gz
- Upload date:
- Size: 321.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32b19408ca05687403dafe6f12a662325e5a578ca9d0566b4379a216a805f0c2
|
|
| MD5 |
98431c93235e903fb23f9be35e4416a5
|
|
| BLAKE2b-256 |
d615d2d2939b5fed38a3bcd77e616ef9f6cc4e952024ea722f0e7a8ca62a99ef
|
File details
Details for the file inccsv-0.1.0-py3-none-any.whl.
File metadata
- Download URL: inccsv-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65177c80d1eb6f7b02ac354d2ea21468fc7246015a7a6191f51279d9f6c61936
|
|
| MD5 |
a6f330ed311815ad974c05f2eb920844
|
|
| BLAKE2b-256 |
7d54e14a0ed01c35ad846c71fd0e6e7dc3d2994b379e21b835d9dd09bc2279d9
|