PDF reports in Python web applications — Part 1: Server side report generation

Image by edar from Pixabay

Why would we do that?

To start with I’ll focus on the server side reasons by comparing different aspects between the well-established Java-based reporting framework Jasper and ReportBro. I’ll discuss the client side aspects in another article.

1. Installation

Jasper requires a Java Runtime Environment (JRE) plus corresponding Tomcat server configuration. Besides the necessity of adopting the appropriate know-how regarding its setup and optimization this means to reserve designated resources for running the reporting server. The JasperReports Server needs to be installed and started so that reports can be generated with REST requests (see Request handling below).

$ pip install reportbro-lib

2. Resource allocation

Running and servicing a resource-intense JAVA server for the purpose of reporting only is a major disadvantage when the main application intends to be a lightweight and process-optimized Python web application.

3. Request handling

Users of web applications expect quick results and low latency. Especially when creating hundreds of relatively simple reports at once — all of them with a fairly manageable amount of data (like invoices or monthly analysis) — overall application performance shouldn’t be interfered by report generation.

4. Data processing

Jasper is specialized in processing huge volumes of data. Therefore, the request for data is usually done within the report via data source (e.g. a database query). This also implies the risk of inconsistencies due to separated data queries and data processing within the application (for the web view) and the report. We can eliminate the risk of data inconsistency in ReportBro by using the same functions for data requests both in the web application and for report generation. This is possible because both the controller for the web view and for the report are executed in Python.

5. Creation and maintenance of reports

We have a separate instance for each of our clients, this means we also have separate databases and individual reports. Therefore, each time we setup a new client we also have to configure the client reports. In Jasper this includes creation of a data source (for the database query), folder (for the customer), report objects (containing the report itself) and report units to access a report with the correct data source. We also have to update the report on the server everytime the report is changed. These tasks are quite cumbersome which led us to write a script to automate the repeating jobs as much as possible.

Report management within our web application

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store