API Reference

Class Config

class Config(*args, **kwargs)

Class for defining the settings to generate the reports.

jvm_maxmem

Maximum memory used by the JVM

Type:str
Value:‘512M’
jvm_classpath

The class path is the path that the Java runtime environment searches for classes and other resource files.

Type:str
dbType

Data source type

Type:str
Options:None, csv, xml, json, jsonql, mysql, postgres, oracle, generic
dbDriver

Jdbc driver class name for use with dbType: generic

Type:str
dbHost

Database host

Type:str
dbName

Database name

Type:str
dbPasswd

Database password

Type:str
dbPort

Database port

Type:int
dbSid

Oracle sid

Type:str
dbUrl

Jdbc url without user, passwd with dbType: generic

Type:str
dbUser

Database user

Type:str
jdbcDir

Directory where jdbc driver jars are located.

Type:str
input

Input file (.jrxml|.jasper|.jrprint)

Type:str
dataFile

Input file for file based datasource

Type:str
csvFirstRow

First row contains column headers

Type:bool
csvColumns

Comma separated list of column names

Type:list(str)
csvRecordDel

CSV Record Delimiter - defaults to line.separator

Type:str
csvFieldDel

CSV Field Delimiter - defaults to “,”

Type:str
csvCharset

CSV charset - defaults to “utf-8”

Type:str
xmlXpath

XPath for XML Datasource

Type:str
jsonQuery

JSON query string for JSON Datasource

Type:str
jsonQLQuery

JSONQL query string for JSONQL Datasource

Type:str
locale

Set locale with two-letter ISO-639 code or a combination of ISO-639 and ISO-3166 like en_US.

For a complete list of locales see Supported Locales

Type:str
output

Directory or basename of outputfile(s)

Type:str
outputFormats

A list of output formats

Type:list(str)
Options:pdf, rtf, docx, odt, xml, xls, xlsx, csv, csv_meta, ods, pptx, jrprint
params

Dictionary with the names of the parameters and their respective values.

Exemple: {'NAME_PARAM_1': 'value param 1', 'NAME_PARAM_2': 'value param 2'}

Type:dict
printerName

Name of printer

Type:str
reportName

Set internal report/document name when printing

Type:str
resource

Path to report resource dir or jar file. If <resource> is not given the input directory is used.

Type:str
writeJasper

Write .jasper file to imput dir if jrxml is processed

Type:bool
Value:False
outFieldDel

Export CSV (Metadata) Field Delimiter - defaults to “,”

Type:str
outCharset

Export CSV (Metadata) Charset - defaults to “utf-8”

Type:str
askFilter
Type:

str

Options:

a - all (user and system definded) prarms

ae - all empty params

u - user params

ue - empty user params

p - user params marked for prompting

pe - empty user params markted for prompting

classmethod has_output()

Valid if there is a path or file for the output

Returns:Returns true if there is a defined path or file for output otherwise false.
Return type:bool
classmethod is_write_jasper()

Valid if it is to generate a .jasper

Returns:Returns true if the .jasper is to be generated, otherwise it is false.
Return type:bool
classmethod has_jdbc_dir()

Validates if there is a path or file for jdbc .jar

Returns:Returns true if it exists, otherwise false.
Return type:bool
classmethod has_resource()

Validates if there is a .jar or path with several .jar to add to the class path

Returns:Returns true if it exists, otherwise false.
Return type:bool

Class Report

class Report(config: Config, input_file)

Class responsible for instantiating the JVM and loading the necessary Java objects for manipulating the files to compile, generate and export the reports.

Parameters:
  • config (Config) – Config class instance
  • input_file (str) – Input file (.jrxml|.jasper|.jrprint)
classmethod compile()

Compile the report

classmethod compile_to_file()

Emit a .jasper compiled version of the report definition .jrxml file.

classmethod fill()

Executes the fill_internal() method

classmethod fill_internal()

Method responsible for filling the report

classmethod get_output_stream(suffix)

Return a file-based output stream with the given suffix

Parameters:suffix (str) – File suffix
Returns:Returns an output stream from the input file.
Return type:OutputStream (java)
classmethod export_pdf()

Export the report in pdf format

classmethod export_rtf()

Export the report in rtf format

classmethod export_docx()

Export the report in docx format

classmethod export_odt()

Export the report in odt format

classmethod export_xml()

Export the report in xml format

classmethod export_xls()

Export the report in xls format

classmethod export_xls_meta()

Export the report in xls Metadata Exporter format

classmethod export_xlsx()

Export the report in xlsx format

classmethod export_csv()

Export the report in csv format

classmethod export_csv_meta()

Export the report in csv Metadata Exporter format

classmethod export_ods()

Export the report in ods format

classmethod export_pptx()

Export the report in pptx format

classmethod export_jrprint()

Export the report in jrprint format

classmethod get_report_parameters()

Returns a list of all report parameters

Returns:Returns a list of parameters
Return type:list(str)
classmethod get_main_dataset_query()

For JSON, JSONQL and any other data types that need a query to be provided, an obvious default is to use the one written into the report, since that is likely what the report designer debugged/intended to be used. This provides access to the value so it can be used as needed.

Returns:Return a string of main dataset query.
Return type:str
classmethod add_jar_class_path(dir_or_jar)

Method responsible for adding a .jar to class_path or a list of .jar files in an informed directory

Parameters:dir_or_jar (str) – A .jar file or directory containing one or more .jar

Class Db

class Db

Class responsible for managing the report data source

classmethod get_csv_datasource(config: Config)

Method responsible for creating a data source from an informed csv file

Parameters:config (Config) – Config class instance
Returns:Returns a data source of type csv
Return type:net.sf.jasperreports.engine.data.JRCsvDataSource (java)
classmethod get_xml_datasource(config: Config)

Method responsible for creating a data source from an informed xml file

Parameters:config (Config) – Config class instance
Returns:Returns a data source of type xml
Return type:net.sf.jasperreports.engine.data.JRXmlDataSource (java)
classmethod get_json_datasource(config: Config)

Method responsible for creating a data source from an informed json file

Parameters:config (Config) – Config class instance
Returns:Returns a data source of type json
Return type:net.sf.jasperreports.engine.data.JsonDataSource (java)
classmethod get_jsonql_datasource(config: Config)

Method responsible for creating a data source from an informed json file

Parameters:config (Config) – Config class instance
Returns:Returns a data source of type jsonql
Return type:net.sf.jasperreports.engine.data.JsonQLDataSource (java)
classmethod get_data_file_input_stream(config: Config)

Get InputStream corresponding to the configured dataFile.

Parameters:config (Config) – Config class instance
Returns:Returns a InputStream
Return type:java.io.InputStream (java)
classmethod get_connection(config: Config)

Method responsible for obtaining a connection to a database

Returns:Returns database connection
Return type:java.sql.Connection (java)