Skip to main content

Extract structured data from Excel files using YAML schema definitions

Project description

stencilpy

Extract structured data from Excel files using YAML schema definitions into dynamically-generated Pydantic models.

Installation

pip install stencilpy

The stencil open command serves the bundled editor UI locally and opens it in your browser.

Quick Start

from stencilpy import Stencil

# Load a schema
lab = Stencil("lab_report.stencil.yaml")

# Extract data — version auto-detected via discriminator
report = lab.extract("january_lab.xlsx")
print(report.patient_name)
print(report.model_dump())

Schema Format

Create a .stencil.yaml file:

name: lab_report
description: Monthly lab report

discriminator:
  cells:
    - A1

versions:
  "v2.0":
    fields:
      patient_name:
        cell: B3
      sample_date:
        cell: B4
        type: datetime
      readings:
        range: D5:D
        type: list[float]
      report_version:
        cell: header:right
      footer_note:
        cell: footer:center

Scalar cell references can also target worksheet headers and footers:

  • header:left
  • header:center
  • header:right
  • footer:left
  • footer:center
  • footer:right
  • Sheet1!header:first:right
  • Sheet1!footer:even:center

These references also work in discriminator.cells, which is useful when a workbook version is printed in the page header/footer instead of a normal cell.

Header And Footer References

Use header/footer refs anywhere a scalar cell ref is accepted.

Example: extract version text and report metadata from the page chrome.

name: lab_report
description: Monthly lab report

discriminator:
  cells:
    - A1

versions:
  "v2.0":
    fields:
      patient_name:
        cell: B3
      report_version:
        cell: header:right
      report_title:
        cell: header:center
      generated_by:
        cell: footer:left
      footer_note:
        cell: footer:center

If the workbook uses separate first-page or even-page headers/footers, include the page selector:

versions:
  "v2.0":
    fields:
      first_page_title:
        cell: header:first:center
      even_page_version:
        cell: footer:even:right
      cover_sheet_version:
        cell: Cover!header:first:right

Supported formats:

  • header:left
  • header:center
  • header:right
  • header:first:left
  • header:even:center
  • footer:right
  • footer:first:center
  • Sheet1!header:right
  • Sheet1!footer:even:left

Header-Based Version Detection

If a workbook stores its version in a header or footer instead of a normal cell, add those refs to discriminator.cells.

name: lab_report
description: Monthly lab report

discriminator:
  cells:
    - A1
    - header:right
    - Cover!footer:first:center

versions:
  "v1.0":
    fields:
      patient_name:
        cell: A3
  "v2.0":
    fields:
      patient_name:
        cell: B3

stencilpy will check each discriminator ref in order until one matches a known version key.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stencilpy-0.5.2.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stencilpy-0.5.2-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file stencilpy-0.5.2.tar.gz.

File metadata

  • Download URL: stencilpy-0.5.2.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stencilpy-0.5.2.tar.gz
Algorithm Hash digest
SHA256 4265007c1f582a45e054cd843757bf9ddf6c94f9d5ec5edd603d06061925e35f
MD5 d9884fd66287f7292dc3eb813e871158
BLAKE2b-256 c045e2ca3b4e4b183d6c94b1a813101e03d249c3d0cbf443db83cd3e6513cd6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for stencilpy-0.5.2.tar.gz:

Publisher: publish.yml on phlohouse/stencil

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stencilpy-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: stencilpy-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stencilpy-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1fd86b576aee3e7a18d932de9b49de7380e77ef491652a0d8e336c1cdfc5b3ba
MD5 ee9942938b9d8697a105fdee2fc56b16
BLAKE2b-256 882b69cf78274d3a5d84716b14df8e16427bc4bf226793bdd0bfcdc774e4a64e

See more details on using hashes here.

Provenance

The following attestation bundles were made for stencilpy-0.5.2-py3-none-any.whl:

Publisher: publish.yml on phlohouse/stencil

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page