Skip to main content

Write Excel XLSX declaratively.

Project description

Poi: The Declarative Way to Excel at Excel in Python

CI

Why Poi?

Creating Excel files programmatically has always been a chore. Current libraries offer limited flexibility, especially when you need more than a basic table. That's where Poi comes in, offering you a simple, intuitive, yet powerful DSL to make Excel files exactly the way you want them.

Installation

pip install poi

Quick start

Create a sheet object and write to a file.

from poi import Sheet, Cell
sheet = Sheet(
    root=Cell("hello world")
)

sheet.write('hello.xlsx')

hello

See, it's pretty simple and clear.

Create a Dynamic Table with Column Auto-fit & Formatting

from typing import NamedTuple
from datetime import datetime
import random

from poi import Sheet, Table


class Product(NamedTuple):
    name: str
    desc: str
    price: int
    created_at: datetime
    img: str


data = [
    Product(
        name=f"prod {i}",
        desc=f"desc {i}",
        price=random.randint(1, 100),
        created_at=datetime.now(),
        img="./docs/assets/product.jpg",
    )
    for i in range(5)
]
columns = [
    {
        "type": "image",
        "attr": "img",
        "title": "Product Image",
        "options": {"x_scale": 0.27, "y_scale": 0.25},
    },
    ("name", "Name"),
    ("desc", "Description"),
    ("price", "Price"),
    ("created_at", "Create Time"),
]
sheet = Sheet(
    root=Table(
        data=data,
        columns=columns,
        col_width="auto",  # Automatically sizes columns to fit contents perfectly!
        row_height=80,
        cell_style={
            # Apply bold red font if price is over 50
            "font_color: red; bold: true": lambda record, col: col.attr == "price" and record.price > 50
        },
        date_format="yyyy-mm-dd",
        align="center",
        border=1,
    )
)
sheet.write("table.xlsx")

table

See how simple it is to create complex tables? You just wrote a dynamically sized, auto-fitted Excel table with conditional formatting in just a few lines of code!

Features

  • 🎨 Declarative DSL: Define spreadsheets with a simple, intuitive, nesting-friendly node tree.
  • 🚀 Automatic Layout: Standard layout primitives (Row, Col, Cell, Image) automatically compute rowspans, colspans, offsets, and row/column indexes for you.
  • 📏 Smart Column Auto-fit: Use col_width="auto" to automatically size columns based on the longest value, with native support for Chinese/CJK double-width characters and date patterns.
  • 💬 Interactive Comments: Attach rich pop-up tooltips to specific cells and table headers.
  • 📚 Multi-sheet Workbooks: Organize multiple sheets together dynamically using the Book API.
  • 🔥 High Performance: Native speed powered by the xlsxwriter engine, with a fast=True option to skip writing styles for empty cells.

Documentation

For complete APIs, references, and examples, visit our comprehensive Poi Documentation Portal:

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

poi-1.2.7.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

poi-1.2.7-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file poi-1.2.7.tar.gz.

File metadata

  • Download URL: poi-1.2.7.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for poi-1.2.7.tar.gz
Algorithm Hash digest
SHA256 d5551a9128569552285126b7e916b8e8598d4744ce67da106f59d0efa0b8e96d
MD5 a8728c0b243a5873b110a5f7a1f76f4f
BLAKE2b-256 ae2dbcfa643f47bb6b5ec65dd0be7653a46792742a245b5d9a539b87f6a8cb59

See more details on using hashes here.

Provenance

The following attestation bundles were made for poi-1.2.7.tar.gz:

Publisher: release.yml on ryanwang520/poi

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

File details

Details for the file poi-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: poi-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for poi-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 462ddb15f434f733cc7dd5ed759eaee7ecd9272496a3f1c5f69114bbee89ae85
MD5 ec650af25b433c940f09bfd540075216
BLAKE2b-256 cc1d09ba1f0389f9369dcbeb9b9792802ef68e5c3941620f462f2f8e69d9bd65

See more details on using hashes here.

Provenance

The following attestation bundles were made for poi-1.2.7-py3-none-any.whl:

Publisher: release.yml on ryanwang520/poi

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