Declarative Excel schema builder, reader and validator
Project description
Excel Schema Engine
A lightweight Python library for generating, validating, and reading Excel files using a declarative schema.
Define your Excel structure once and use it to:
- generate Excel templates
- validate uploaded files
- read rows as structured data
- highlight errors directly in Excel
Built on top of openpyxl.
Installation
pip install excel-schema-engine
or, with Poetry:
poetry add excel-schema-engine
Quickstart
For a complete runnable example, see:
examples/quickstart.py– define a schema, build a workbook, write rows, autosize columns.
Core concepts
- ExcelSchema: top‑level object that describes the whole workbook (sheets, styles, author for comments).
- SheetSchema: describes a single sheet (its name and list of columns).
- Column: describes a logical column with:
- key: dictionary key used when reading/writing rows
- header: text shown in the Excel header
- style: name of a style defined in
ExcelSchema.styles - comment: optional
Commentshown in the header cell - subcolumns: nested columns for multi‑level headers
- CellStyle: strongly‑typed wrapper around
openpyxlstyles (Font,PatternFill,Alignment,Border). - ExcelErrorsSchema: defines styles used to mark and highlight errors and fixed values.
All these classes are simple @dataclass models and can be constructed in plain Python.
Building Excel templates
See:
-
examples/quickstart.py -
Headers:
- Single‑row headers are created when a
Columnhas nosubcolumns. - Multi‑row headers are created when a
Columnhassubcolumns(the parent header is merged across all subcolumns).
- Single‑row headers are created when a
-
Styles and comments:
- Header styles are looked up by name in
schema.styles. - Header comments are created using
Comment(comment, author, width, height)whereauthorcomes fromExcelSchema.author.
- Header styles are looked up by name in
Writing data rows
Use ExcelBuilder.write_rows to write dictionaries into the sheet based on the schema.
See:
-
examples/quickstart.py -
Missing sheet: if the given
sheet_nameis not present in the schema, a localized error message is printed and nothing is written. -
Column mapping: keys from each
rowdict must matchColumn.keyvalues (including nested subcolumns).
Validating uploaded files
ExcelValidator checks that the headers in a user‑submitted file match the schema (order and names).
See:
examples/validation_and_reading.py
validate_headers returns a list of human‑readable error messages (already localized).
The validator checks:
- Number of columns (expected vs found)
- Missing columns
- Wrong header text (position, expected text, actual text)
Reading rows as structured data
ExcelReader converts worksheet rows into dictionaries using the same SheetSchema.
See:
examples/validation_and_reading.py
Each row is a dict where keys are Column.key values and values are cell contents.
Highlighting and marking errors in Excel
Use ExcelErrorsSchema and ExcelErrors to visually mark problematic cells and rows.
See:
-
examples/mark_errors.py -
mark_error: colors the cell with
error_schema.error_fill(or a customCellStyle) and optionally adds a localized comment. -
highlight_row: colors all cells in a row with
error_schema.highlight_fill(or custom style). -
mark_fixed: re‑styles previously marked cells using
error_schema.fixed_fill(or custom style) and optionally replaces the comment text.
Localization
The library supports multiple languages for validator and builder messages via the Language enum and ValidatorErrComment:
- Supported out of the box:
Language.EN– EnglishLanguage.RU– RussianLanguage.PL– PolishLanguage.BOBR– a playful demo language
You can extend or override messages at runtime:
from excel_schema_engine.global_vars import Language, ValidatorErrComment
ValidatorErrComment.messages[Language.FR] = {
"missing_column": "Colonne manquante : {column}",
"wrong_header": "Colonne {index} : attendu '{expected}', trouvé '{found}'",
"columns_count": "Colonnes attendues : {expected}, trouvées : {found}",
"miss_sheet": "La feuille nommée {sheet_name} est introuvable.",
"error_prefix": "Erreur : ",
}
Messages are formatted using str.format, so you can use any placeholders expected by the library ({column}, {index}, {expected}, {found}, {sheet_name}, etc.).
API overview
Everything you typically need is re‑exported from the package root:
- Schema and styles
ExcelSchemaSheetSchemaColumnCommentCellStyleExcelErrorsSchema
- Builders and readers
ExcelBuilderExcelReaderExcelValidatorExcelErrors
- Utilities
autosize_columns
For more advanced usage, you can also import:
LanguageandValidatorErrCommentfromexcel_schema_engine.global_vars
This should be enough to build templates, validate uploaded files, and work with structured Excel data in your applications.
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 Distributions
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 excel_schema_engine-0.1.8-py3-none-any.whl.
File metadata
- Download URL: excel_schema_engine-0.1.8-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d359f742d6665856f0459a40de5036a676d37bd15471507aa284fdf52ac6a171
|
|
| MD5 |
1fcd26563e54760043a38ee017ecf55c
|
|
| BLAKE2b-256 |
3affb15c34a083f770d495aac3b30f27a455b46ac7fb484f072ee1047251f5ad
|