Skip to main content

A versatile Django REST Report (DRR) toolkit for generating reports from various backends

Project description

Django REST Report

A versatile Django toolkit for managing reports.

JasperReports

Easily generate JasperReports from your Django views using the JasperReports Server REST API. This package handles authentication, URL construction, and maps Django responses to the correct file types automatically.

🛠 Prerequisites

Before using this package, you must have a JasperReports Server instance running.

You can host it yourself or use a cloud instance.

Ensure the REST API is accessible (typically at port 8080).

🚀 Installation

pip install djangorestreport

⚙️ Setup

Add your JasperServer credentials to your Django settings.py.

# settings.py
JASPER_SERVER_URL = "http://server-ip:8080"
JASPER_USER = "username"
JASPER_PASSWORD = "password"

You can also load these values from environment variables if that matches your project setup.

📄 Supported Formats

Pass these strings into the output_format parameter to receive the corresponding file type:

Documents: pdf, docx, rtf, odt, html, xml

Spreadsheets: xlsx, xls, csv, ods

Presentations: pptx

📖 Usage

Basic Example (DRF View)

In your views.py, you can extract query parameters from the URL and pass them directly to your Jasper report.

from rest_report import JasperReport
from rest_framework.views import APIView
from rest_framework.response import Response

class ReportView(APIView):
    def get(self, request):
        report = JasperReport()

        # 1. Path to the report unit in your JasperServer repository
        report_path = "/organization/reports/NameofReport"

        # 2. Get all query params (e.g., ?id=5&status=active)
        params = request.query_params.dict()

        # 3. Extract the format (default to 'pdf')
        output_format = params.pop("output_format", "pdf")

        # 4. Generate and return the report as a file download
        try:
            return report.generate(report_path, output_format=output_format, params=params)
        except Exception as e:
            return Response({"error": str(e)}, status=400)

Extended Example (DRF View)

In your views.py, you can set a custom filename and message, then pass them directly to your Jasper report.

from rest_report import JasperReport
from rest_framework.views import APIView
from rest_framework.response import Response

class ReportView(APIView):
    def get(self, request):
        report = JasperReport()
        report_path = "/organization/reports/SalesOverview"
        
        # Extract format and parameters
        params = request.query_params.dict()
        output_format = params.pop("output_format", "pdf")

        try:
            return report.generate(
                report_path,
                output_format=output_format,
                params=params,
                filename="Monthly_Sales_Report",  # 1. Custom Filename
                message="Report generated successfully for User ID 101"  # 2. Custom Message
            )
        except Exception as e:
            return Response({"error": str(e)}, status=400)

Multiple Report/Report Path Handle (DRF View)

In your views.py, you can manage more reports/report path, filename then pass them directly to your Jasper report.

params = request.query_params.dict()
output_format = params.pop("output_format", "pdf")

if params.get("id"):
    report_path = "/organization/reports/NameofSingleReport"
    filename = "Name_of_Single_Report"
else:
    report_path = "/organization/reports/NameofDetailsReport"
    filename = "Name_of_Details_Report"

return report.generate(
    report_path,
    output_format=output_format,
    params=params,
    filename=filename,
)

💡 Working with Parameters

The params dictionary keys must exactly match the parameter names defined in your .jrxml file. For example, if you pass {"id": 10}, your Jasper report should have a parameter defined as $P{id}.

⚠️ Error Handling

  • Missing settings raise ImproperlyConfigured when JasperReport is initialized.
  • Invalid formats raise ValueError.
  • JasperServer request failures raise RuntimeError with the underlying request error.

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

djangorestreport-0.0.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

djangorestreport-0.0.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file djangorestreport-0.0.4.tar.gz.

File metadata

  • Download URL: djangorestreport-0.0.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for djangorestreport-0.0.4.tar.gz
Algorithm Hash digest
SHA256 689174a8f81e20bce86fae7f6014d0db4135f5f1cbb7ed18d394d54026e741c2
MD5 49492907da9f8f43eaeb2698575d239f
BLAKE2b-256 9a121283125e99800ed35953f1c0de9112d6aed1ee3c4a2c0ed3bdf86ac5a66d

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangorestreport-0.0.4.tar.gz:

Publisher: python-publish.yml on chinmayroy/djangorestreport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djangorestreport-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for djangorestreport-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b0c04abf26a0bdd85e7af9014a4f2da0a8424df1738d2182b522847f66eb323f
MD5 7d0735b3ced6c84efb125c99948d1f35
BLAKE2b-256 21de1b8d6aa1512dadc4c562c20354fa41563d4d6c089a0950c43b4a692666a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangorestreport-0.0.4-py3-none-any.whl:

Publisher: python-publish.yml on chinmayroy/djangorestreport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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