Metadata-Version: 2.4
Name: q2report
Version: 0.1.70
Summary: 
License-File: LICENSE
Author: Andrei Puchko
Author-email: andrei.puchko@gmx.de
Requires-Python: >=3.8.1
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Description-Content-Type: text/markdown

# Q2Report

Q2Report is a lightweight Python report builder for creating formatted reports in PDF, XLSX, DOCX, and HTML.

![Results Screenshot](docs/results.png)


It combines a report layout (pages, columns, rows, and cells) with named data sets, expressions, styles, images, tables, grouping, headers, and footers.

## Installation

Python 3.8.1 or newer is required.

```bash
pip install q2report
```

PDF output requires a supported Qt binding: PySide or PyQt. If none is installed, generating a PDF raises an `ImportError`. Q2Report detects an installed binding automatically; you do not need to configure which one to use.

For example, install Q2Report with PySide6:

```bash
pip install q2report pyside6
```

The Qt binding is only needed for PDF output. HTML, XLSX, and DOCX output do not require PySide or PyQt.

## Quick start

```python
from q2report import Q2Report

report = Q2Report()

report.set_style(report.make_style(border_width="0 0 1 0"))
report.add_page(page_width=21, page_height=29.7)
report.add_column(width="20%")
report.add_column()

report.set_cell(0, 0, "First Name", style={"font-weight": "bold"})
report.set_cell(0, 1, "{firstname}")
report.set_cell(1, 0, "Last Name", style={"text-align": "right"})
report.set_cell(1, 1, "{lastname}")

data = {"firstname": "Ada", "lastname": "Lovelace"}

rep = report.run("temp/report.docx", data=data)
```

This example opens the docx automatically after rendering. Set `open_output_file=False` to suppress that behavior.

## A data-driven table

```python
from q2report import Q2Report, Q2Report_rows

report = Q2Report()
report.add_page()
report.add_column(width=3)
report.add_column(width=3)

num_style = {"text-align": "right"}

table = Q2Report_rows(
    role="table",
    data_source="items",
    style=report.make_style(border_width="0 0 1 0"),
)
table.set_cell(0, 0, "{name}")
table.set_cell(0, 1, "{num(price)*num(qt)}", format="F2",
               name="line_total", style=num_style)

header = Q2Report_rows(style={"text-align": "center", "font-size": 8})
header.set_cell(0, 0, "Item")
header.set_cell(0, 1, "Total")
table.set_table_header(header)

footer = Q2Report_rows(style=num_style)
footer.set_cell(0, 0, "Grand total")
footer.set_cell(0, 1, "{sum:line_total}", format="F2",
                style={"font-weight": "bold"})
table.set_table_footer(footer)

report.add_rows(rows=table)

data = {
    "items": [
        {"name": "Pen", "price": "2.50", "qt": 10},
        {"name": "Notebook", "price": "4.00", "qt": 3},
    ]
}

report.run("temp/report.xlsx", data=data)

```

## Supported output

The output format is inferred from the file extension:

- `.html`
- `.pdf`
- `.xlsx`
- `.docx`

You can pass `output_type` explicitly if needed.

## Documentation

- [Documentation index](docs/index.md)
- [How-to guide](docs/howto.md)
- [Report JSON format](docs/json-format.md)
- [API reference](docs/api.md)
- [Demos](demo/)
- [JSON examples](test_data/)

## Running the demos

```bash
python demo/demo.py
```

Most individual demo modules expose a `demo(type="pdf", open_output_file=True)` function.

