Write Excel XLSX declaratively.
Project description
Poi: The Declarative Way to Excel at Excel in Python
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')
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")
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
BookAPI. - 🔥 High Performance: Native speed powered by the
xlsxwriterengine, with afast=Trueoption to skip writing styles for empty cells.
Documentation
For complete APIs, references, and examples, visit our comprehensive Poi Documentation Portal:
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 Distribution
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5551a9128569552285126b7e916b8e8598d4744ce67da106f59d0efa0b8e96d
|
|
| MD5 |
a8728c0b243a5873b110a5f7a1f76f4f
|
|
| BLAKE2b-256 |
ae2dbcfa643f47bb6b5ec65dd0be7653a46792742a245b5d9a539b87f6a8cb59
|
Provenance
The following attestation bundles were made for poi-1.2.7.tar.gz:
Publisher:
release.yml on ryanwang520/poi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
poi-1.2.7.tar.gz -
Subject digest:
d5551a9128569552285126b7e916b8e8598d4744ce67da106f59d0efa0b8e96d - Sigstore transparency entry: 1626837259
- Sigstore integration time:
-
Permalink:
ryanwang520/poi@7990694ef0567c81d6395e9ed98f448f0fd3ba5e -
Branch / Tag:
refs/tags/v1.2.7 - Owner: https://github.com/ryanwang520
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7990694ef0567c81d6395e9ed98f448f0fd3ba5e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462ddb15f434f733cc7dd5ed759eaee7ecd9272496a3f1c5f69114bbee89ae85
|
|
| MD5 |
ec650af25b433c940f09bfd540075216
|
|
| BLAKE2b-256 |
cc1d09ba1f0389f9369dcbeb9b9792802ef68e5c3941620f462f2f8e69d9bd65
|
Provenance
The following attestation bundles were made for poi-1.2.7-py3-none-any.whl:
Publisher:
release.yml on ryanwang520/poi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
poi-1.2.7-py3-none-any.whl -
Subject digest:
462ddb15f434f733cc7dd5ed759eaee7ecd9272496a3f1c5f69114bbee89ae85 - Sigstore transparency entry: 1626837290
- Sigstore integration time:
-
Permalink:
ryanwang520/poi@7990694ef0567c81d6395e9ed98f448f0fd3ba5e -
Branch / Tag:
refs/tags/v1.2.7 - Owner: https://github.com/ryanwang520
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7990694ef0567c81d6395e9ed98f448f0fd3ba5e -
Trigger Event:
push
-
Statement type: