Table Schema

1.21.0 · active · verified Wed Apr 15

A utility library for working with Table Schema in Python, enabling validation, inference, and manipulation of tabular data based on the Table Schema standard. It is actively maintained with frequent releases, currently at version 1.21.0. An important notice indicates that the broader Frictionless Framework offers a more complete data solution, extending `tableschema`'s functionality.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `Table` with data and a schema, iterate through its rows, and infer a schema from raw data. It creates temporary `data.csv` and `schema.json` files to provide a runnable example.

import os
from tableschema import Table, Schema

# Create dummy data and schema files for demonstration
data_csv_content = """
id,name,age
1,Alice,30
2,Bob,24
3,Charlie,35
"""

schema_json_content = """
{
  "fields": [
    {"name": "id", "type": "integer"},
    {"name": "name", "type": "string"},
    {"name": "age", "type": "integer"}
  ]
}
"""

with open('data.csv', 'w') as f:
    f.write(data_csv_content)
with open('schema.json', 'w') as f:
    f.write(schema_json_content)

# 1. Create a Table instance with data and schema
table = Table('data.csv', schema='schema.json')

# 2. Print schema descriptor
print("Schema Descriptor:", table.schema.descriptor)

# 3. Read and print data as keyed rows
print("\nData Rows (keyed):")
for keyed_row in table.iter(keyed=True):
    print(keyed_row)

# 4. Infer schema from data
headers = ['id', 'name', 'age']
rows = [[1, 'Alice', 30], [2, 'Bob', 24], [3, 'Charlie', 35]]
inferred_schema_descriptor = Schema.infer(rows, headers)
print("\nInferred Schema Descriptor:", inferred_schema_descriptor)

# Clean up dummy files
os.remove('data.csv')
os.remove('schema.json')

view raw JSON →