Registry / data / tableschema

tableschema

JSON →
library1.21.0pypypi✓ verified 85d ago

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.

pip install tableschema
INSTALL
IMPORT
SIG · TABLESCHEMA
T
tableschema
datapythonv1.21.0
Install
9.5s avg
Import
1267ms
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.21.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.328s · 90.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 9.5s · import 1.206s · 90MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Table
from tableschema import Table
Schema
from tableschema import Schema
Field
from tableschema import Field
validate
from tableschema import validate
infer
from tableschema import infer

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')
Debug
Known issues
breakingVersion `1.0` introduced significant breaking changes, including API renames (e.g., `tableschema.push/pull_resource` to `tableschema.Table`, `tableschema.model` to `tableschema.Schema`, `tableschema.types` to `tableschema.Field`) and changes in parameter signatures for `Field.cast/test_value`.
fix
Review the `v1.0` migration guide and update API calls and parameter usage according to the new patterns. It is highly recommended to pin version ranges (e.g., `tableschema>=1.0,<2.0`) to avoid unexpected major version updates.
affects: <1.0
gotchaThe `tableschema` library, while functional, is part of the broader Frictionless Data ecosystem. The Frictionless Framework (a separate library) provides extended and improved `tableschema` functionality as a more complete data solution. While existing `tableschema` code is not breaking, users are encouraged to consider the Frictionless Framework for new projects or future enhancements.
fix
For new projects or if advanced data management features are needed, explore migrating to or directly using the Frictionless Framework for a more comprehensive solution. Existing `tableschema` implementations should continue to work as expected.
affects: All versions
gotchaThe `validate` function (e.g., `tableschema.validate`) is designed to validate a Table Schema *descriptor* itself, not to validate *data* against a given schema. Passing data directly to `validate` will not perform data validation.
fix
To validate data against a schema, load the data using `Table` with a specified `schema` and then iterate through the data. Validation errors will be raised during iteration if the data does not conform to the schema (especially in strict mode). Use `Table.iter()` which handles casting and validation.
affects: All versions
gotchaThe library uses semantic versioning, meaning major versions (e.g., v1.x.x to v2.x.x) can introduce breaking changes. Relying on `tableschema` without a version constraint in your `requirements.txt` can lead to unexpected breakages when new major versions are released.
fix
Always specify a version range for `tableschema` in your `requirements.txt` or `setup.py` (e.g., `tableschema>=1.0,<2.0`) to ensure predictable dependency behavior and prevent automatic upgrades to potentially breaking major versions.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tableschema'
The 'tableschema' Python package is not installed in the current environment or is not accessible in the Python path.
fix
Install the package using pip: `pip install tableschema`
The row is not valid: type 'string' is not 'integer'
A value in the data row does not conform to the data type specified for its corresponding field in the schema (e.g., a string found where an integer is expected).
fix
Correct the data type in the source data, modify the field's `type` in the schema to match the data, or implement data conversion before validation.
AttributeError: 'Schema' object has no attribute 'validate_row'
Attempting to call a method that exists on a `Table` object (for data validation) directly on a `Schema` object, which only defines the data structure.
fix
To validate data against a schema, first create a `Table` object with the data and schema, then use `table.validate()`.
ValueError: The schema must be a dictionary, a string or a file path
The constructor for `tableschema.Schema` received input that is not in one of the expected formats (e.g., not a dictionary, JSON string, or file path).
fix
Ensure the input provided to `tableschema.Schema()` is a valid schema dictionary, JSON string, or file path.
Upgrade
Version history
1.21.0latest on PyPI · released Nov 14, 2024
Audit
Dependencies
requestsrequiredUsed for fetching remote schema and data sources.
python-dateutilrequiredUsed for parsing and handling various date and time formats.
tabulatorrequiredUnderpins data loading capabilities for various formats (CSV, Excel, etc.), though often implicitly handled by `Table`.
Agent activity
20 hits · last 30 days
node
14
OpenAI (training)
1
Resources
tableschema — pip install tableschema · libregistry