Skip to main content

No project description provided

Project description

The light Python report builder.

Converts data into formatted text (PDF, XLSX, DOCX, HTML):

data = {'data_source1':[{'col1': 'value row1', ....}, ...],
        'data_source2':[{'col_1': 'valie_row1', ....}, ...],
        }

Available formatting (styling options):

"style": {
        "font-family": "Arial",
        "font-size": "10pt",
        "font-weight": "normal",  # bold
        "text-decoration": "",  # underline
        "font-style": "",  # italic
        "color": "black",  # font color
        "background": "white",  # background color
        "border-color": "black",  # border color
        "border-width": "1 1 1 1",
        "padding": "0.05cm 0.05cm 0.05cm 0.05cm",
        "text-align": "left",
        "vertical-align": "top",
  }

Concept

The report definition consists of sections (Report, Pages, Columns, Rows, Cells).
Each section inherits style from previous and may override some styling options.
*see examples in folder test_data*

Report:      # top-level report object containing the base style
    Pages:   # page size, margins, and page-level styles
        Columns:    # column widths: fixed, %, or auto-width; supports styles
            Rows:   # row heights: auto, fixed, minimum, or maximum; supports styles
                    # rows may be data-bound and can include subsections:
                    # header, footer, group-header, group-footer
                Cells:  # contain plain text and data placeholders — {col1} (f-strings style)
                        # support aggregate functions — {sum:col1}
                        # support basic HTML formatting: <b> <i> <u> <br>
            Rows:
                Cells:  # cells can be merged (span)
            ...
        Columns:
            ...
    Pages:
        ...
    ...```

---

## Main API (`Q2Report`)

### Initialization

```python
from q2report.q2report import Q2Report

report = Q2Report(style={...})

Adding Pages and Columns

report.add_page(page_width=21, page_height=29.7, page_margin_left=2, page_margin_right=1)
report.add_columns(page_index=0, widths=[5, 5, 5], style={...})

Adding Rows and Cells

rows = report.add_rows(page_index=0, columns_index=0, heights=[1, 1, 1], style={...})
rows.set_cell(0, 0, "{col1}", style={"font-weight": "bold"})
rows.set_cell(1, 0, "{sum:col2}", format="F2")

Or directly via report:

report.set_cell(0, 1, "Some value", page_index=0, columns_index=0, rows_index=0)

Data Binding

  • Use {column_name} in cell data to bind to data source columns.
  • Use {sum:column_name} for aggregation in table footers or group footers.

Grouping and Aggregation

rows.add_table_group(
    groupby="col1",
    header=Q2Report_rows(...),
    footer=Q2Report_rows(...)
)

Rendering

report.run(output_file="output.pdf", data=data)
  • Supported output types: "html", "pdf", "xlsx", "docx"

Features

  • Flexible styling: Inherit and override styles at any level.
  • Data-driven: Bind data sources to tables, rows, and cells.
  • Aggregates: Built-in support for {sum:col} and similar formulas.
  • Grouping: Group rows by one or more columns, with group headers/footers.
  • Images: Embed images using {q2image(path)} or cell format "I".
  • Multi-format output: Export to HTML, PDF, XLSX, DOCX.
  • Custom formulas: Use Python expressions in {...}.

Example

from q2report.q2report import Q2Report

report = Q2Report()
report.add_page()
report.add_columns(widths=[5, 5, 5])
rows = report.add_rows(heights=[1, 1, 1])
rows.set_cell(0, 0, "Header 1", style={"font-weight": "bold"})
rows.set_cell(0, 1, "Header 2", style={"font-weight": "bold"})
rows.set_cell(1, 0, "{col1}")
rows.set_cell(1, 1, "{col2:F2}")
report.run(output_file="report.pdf", data={"data_source": [{"col1": "A", "col2": 123456}]})

Advanced

  • Custom styles: Use Q2Report.make_style(...) to generate style dicts.
  • Direct JSON: You can load report definitions from JSON files or strings.
  • Accessing data: Use report.d.<dataset> for advanced row access in formulas.

See Also

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

q2report-0.1.54.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

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

q2report-0.1.54-py3-none-any.whl (48.3 kB view details)

Uploaded Python 3

File details

Details for the file q2report-0.1.54.tar.gz.

File metadata

  • Download URL: q2report-0.1.54.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.7 Windows/10

File hashes

Hashes for q2report-0.1.54.tar.gz
Algorithm Hash digest
SHA256 7620189f6aa0965b0b016fb7b88c6d92a830b32b0b5bcb01c78d1e01cd8bf43e
MD5 0809eef72942a8f67586a84a910e2b7e
BLAKE2b-256 1b8a986e9500fe7e6adb1ac0bf03fc2ad7fd761970b667f50df2592e9c06439a

See more details on using hashes here.

File details

Details for the file q2report-0.1.54-py3-none-any.whl.

File metadata

  • Download URL: q2report-0.1.54-py3-none-any.whl
  • Upload date:
  • Size: 48.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.7 Windows/10

File hashes

Hashes for q2report-0.1.54-py3-none-any.whl
Algorithm Hash digest
SHA256 645e11c7e24fc171baa0086d7bb1981b253975422220572c8f699bfa96c0bc33
MD5 c5928c295f336acf73f28d549b9f277e
BLAKE2b-256 39909ab07483087533c30c1cee184c963b9a6d1dd71772f7ba4f4007e56576df

See more details on using hashes here.

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