tablec Python Bindings
Python bindings for the tablec (Table Compiler) library.
Installation
Development
# Install dependencies using uv
cd binding-python
uv sync
# Build the Rust extension
uv run maturin develop
From wheel (future)
pip install tablec
Usage
Basic API
import tablec
# Build Excel to JSON
tablec.build('input.xlsx', 'output.json', 'json')
# Build Excel to MessagePack
tablec.build('input.xlsx', 'output.msgpack', 'msgpack')
# Validate Excel file
tablec.check('input.xlsx')
High-level API
from tablec.core import Project
# Load a project from Excel
project = Project.load('project.xlsx')
# Access tables by name
table = project['TableName']
# Iterate over tables
for table_name in project:
table = project[table_name]
for row in table:
print(row)
# Export project
project.export('output.json', 'json')
Type System
from tablec.types import parse
# Parse type strings
int_type = parse('int')
array_type = parse('int[]')
map_type = parse('map<string, int>')
struct_type = parse('{a:int, b:string}')
# Type checking
if array_type.is_array():
print('This is an array type')
Excel Format
Excel sheets should follow this format:
| Row 1 | Field names (e.g., id, name, score) | | Row 2 | Field types (e.g., int, string, float) | | Row 3 | Descriptions (use # for none) | | Row 4 | Constraints (e.g., @unique, @seq) | | Row 5+ | Data rows |
Supported Types
- Primitives:
int,int8,int16,int32,int64,uint,uint8,uint16,uint32,uint64,float,float32,float64,string - Arrays:
int[],string[], etc. - Maps:
map<string, int>,map<int, string> - Structs:
{a:int, b:string},struct{id:int, name:string}
Constraints
@unique- Field must be unique@unique(field1, field2)- Combination of fields must be unique@seq- Sequential field (1, 2, 3, ...)@seq(step)- Sequential with step (1, 3, 5, ...)@order- Ordered ascending@order(desc)- Ordered descending
Testing
# Run all tests
uv run pytest tests/ -v
# Run specific test file
uv run pytest tests/test_python_binding.py -v
Building for Distribution
# Build release wheel
uv run maturin build --release
# Build for multiple Python versions
uv run maturin build --release --strip --compatibility manylinux
Error Handling
try:
tablec.check('file.xlsx')
except Exception as e:
print(f"Validation failed: {e}")
Import name vs package name
The package published to PyPI is tablec. The Python import name is also tablec
(PEP 421 allows the two to differ, but here they match on purpose):
pip install tablec
python -c "import tablec; tablec.check('your.xlsx')"
If you pip install a checkout of this repo, the editable install uses the
project's name (tablec) — import tablec is the canonical import.
License
Same as the main tablec project.
Metadata
Release files for tablec 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tablec-0.1.0.tar.gz | 78.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tablec-0.1.0-cp310-abi3-manylinux_2_34_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.34+ x86-64 | Details |
Total release size: 1.5 MB
Release files / tablec-0.1.0.tar.gz
| Download URL | tablec-0.1.0.tar.gz |
|---|---|
| Size | 78.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac2d4deffa9ccc257b3dca7ee38b2cafc058d0d94fe4612e4076af082a540f4c
|
|
BLAKE2b-256 checksum How to use checksums |
8ef7e7170f332e730083926d8121e5d2a4db528c2f793252f8725e546adf6b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.2
|
Release files / tablec-0.1.0-cp310-abi3-manylinux_2_34_x86_64.whl
| Download URL | tablec-0.1.0-cp310-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ddb383e51158a614bc5b51ca681502b406e932954f7829da80168b838b2f18a7
|
|
BLAKE2b-256 checksum How to use checksums |
0fe54c67c7be21a45fcdbf7674539f8d7045e775f9ada138af09318967d70296
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.2
|