Skip to main content

mpt-extension-contrib-reports

Reusable building blocks for generating tabular vendor reports and publishing them to Confluence, for SoftwareONE MPT extensions built on the Extension SDK.

It extracts the daily pending-order report previously implemented inside the AWS extension into a shared library, so any extension can publish business observability without re-implementing it. The column layout and Confluence credentials are supplied by the caller, so no product-specific business logic lives in the library.

See AGENTS.md for the module documentation map.

Install

pip install mpt-extension-contrib-reports

Compatible with the Extension SDK >= 6.0.0; it depends on mpt-api-client (the SDK's Marketplace API client) plus openpyxl, requests, and atlassian-python-api, which are pulled in as dependencies.

Public API

mpt_extension_contrib.reports exposes:

Object Purpose
publish_xlsx_to_confluence Turnkey daily pending-orders report → Confluence page (sync MPTClient).
publish_xlsx_to_confluence_async Async variant of the job for an AsyncMPTClient.
PendingOrdersReportSettings Protocol for the settings that job reads (Confluence config + page id).
ReportCreator Fetch resources by RQL query and build a Report (headers + rows).
AsyncReportCreator Async counterpart of ReportCreator for an AsyncMPTClient collection.
Report The built report: headers and rows (returned by create()).
ExcelReportBuilder Turn headers and rows into .xlsx bytes.
ConfluenceClient Attach file bytes to a Confluence page.
QueryableService, AsyncQueryableService Protocols for the (sync/async) collection the creators accept.
PENDING_ORDER_STATUSES The order statuses (Querying, Processing) treated as pending.
EXCEL_MIME_TYPE MIME type for .xlsx workbooks, passed as content_type when attaching them.
ReportRow, ReportRows, RowMapper, SheetDefinition Public type aliases.

Usage

Daily pending-orders report

publish_xlsx_to_confluence packages the original AWS use case: it fetches every pending order, builds a workbook, and attaches it to a Confluence page under a date-stamped filename (orders-<DD-MM-YYYY>.xlsx) with a Total orders <N> comment. The Confluence config and target page come from your extension settings, which must satisfy the PendingOrdersReportSettings protocol:

confluence_base_url: str
confluence_user: str
confluence_token: str
pending_orders_information_report_page_id: str

You pass the API client, the settings, and the column layout:

from mpt_extension_contrib.reports import publish_xlsx_to_confluence

HEADERS = ["ID", "Order Type", "Status", "Product"]


def to_row(order: dict) -> list[str]:
    return [
        order.get("id", ""),
        order.get("type", ""),
        order.get("status", ""),
        order.get("product", {}).get("name", ""),
    ]


uploaded = publish_xlsx_to_confluence(
    client,
    settings,  # satisfies PendingOrdersReportSettings
    row_mapper=to_row,
    headers=HEADERS,
)

The helper reads the Confluence base URL, credentials, and page id from settings, queries the client's commerce.orders collection, and bakes in the pending-status filter, the workbook build (sheet name included), the filename, and the comment.

row_mapper and headers are a pair: pass both to control the exact column layout, or omit both for a quick report whose columns are inferred from the order fields (nested objects flattened into dotted columns like client.id, audit.created.at). Providing only one raises ValueError. select (default ("audit", "parameters")) controls which order attributes are fetched — narrow it to match a custom row_mapper, or to limit what an inferred report exposes.

For an AsyncMPTClient, use publish_xlsx_to_confluence_async — same arguments and behaviour, fetched with async for (the blocking Confluence upload runs in a worker thread):

uploaded = await publish_xlsx_to_confluence_async(
    async_client, settings, row_mapper=to_row, headers=HEADERS
)

Building blocks

For other reports, compose the pieces directly with ReportCreator:

from mpt_api_client.rql import RQLQuery
from mpt_extension_contrib.reports import ExcelReportBuilder, ReportCreator

# Any queryable Marketplace collection works, e.g. `client.commerce.subscriptions`.
creator = ReportCreator(
    client.commerce.orders,
    to_row,
    query=RQLQuery(status__in=["Querying", "Processing"]),
    select=["audit", "parameters"],
)
report = creator.create()  # Report(headers, rows)
workbook = ExcelReportBuilder(HEADERS, sheet_name="Pending Orders").build_sheet(report.rows)

Documentation

Download files

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

Source Distribution

mpt_extension_contrib_reports-2.0.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

mpt_extension_contrib_reports-2.0.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file mpt_extension_contrib_reports-2.0.0.tar.gz.

File metadata

  • Download URL: mpt_extension_contrib_reports-2.0.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mpt_extension_contrib_reports-2.0.0.tar.gz
Algorithm Hash digest
SHA256 3fd9ea83d810b4164d37fa476998e323d4a080d593bd9e16505e7c353cd01c12
MD5 3c2f9cfddb77b53d13dc30f554b32f26
BLAKE2b-256 f869dba386b793f85412cdef7b0443af5fce4c069a4c6b952f451b61c4b8fb5a

See more details on using hashes here.

File details

Details for the file mpt_extension_contrib_reports-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: mpt_extension_contrib_reports-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mpt_extension_contrib_reports-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbdb5f983b539b81344371c6414ee0bb50126d8ff2f08fc23c2886127e0b90d4
MD5 f10727bedc1a92cba12ab1e9d1f780b0
BLAKE2b-256 033bc43a00ecabe5e368fce55678ccd64dde7d067753f838d3b7463af201869c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page