Metadata-Version: 2.1
Name: pyreportjasper
Version: 2.0.2
Summary: This package aims to be a solution to compile and process JasperReports (.jrxml & .jasper files).
Home-page: https://github.com/PyReportJasper/pyreportjasper
Author: Jadson Bonfim Ribeiro
Author-email: contato@jadsonbr.com.br
License: GPLv3
Download-URL: https://pypi.python.org/pypi/jpy/2.0.2
Project-URL: Documentation, https://github.com/PyReportJasper/pyreportjasper/blob/master/README.rst
Project-URL: Code, https://github.com/PyReportJasper/pyreportjasper
Project-URL: Issue tracker, https://github.com/PyReportJasper/pyreportjasper/issues
Description: Reports for Python, with JasperReports.
        =======================================
        
        |Travis| |Coverage| |License| |Donate| |PythonVersion|
        
        **Is using Linux servers?**
        
        Do not forget to grant permission 777 for the directory where is the
        package.
        
        Introduction
        ------------
        
        This package aims to be a solution to compile and process JasperReports
        (.jrxml & .jasper files).
        
        Why?
        ~~~~
        
        Did you ever had to create a good looking Invoice with a lot of fields
        for your great web app or desktop?
        
        I had to, and the solutions out there were not perfect. Generating
        *HTML* + *CSS* to make a *PDF*? WTF? That doesn't make any sense! :)
        
        Then I found **JasperReports** the best open source solution for
        reporting.
        
        What can I do with this?
        ~~~~~~~~~~~~~~~~~~~~~~~~
        
        Well, everything. JasperReports is a powerful tool for **reporting** and
        **BI**.
        
        **From their website:**
        
            The JasperReports Library is the world's most popular open source
            reporting engine. It is entirely written in Java and it is able to
            use data coming from any kind of data source and produce
            pixel-perfect documents that can be viewed, printed or exported in a
            variety of document formats including HTML, PDF, Excel, OpenOffice
            and Word.
        
        It is recommended using `Jaspersoft
        Studio <http://community.jaspersoft.com/project/jaspersoft-studio>`__ to
        build your reports, connect it to your datasource (ex:JSON, XML, MySQL,
        POSTGRES, SQL Server), loop thru the results and output it to PDF, XLS,
        DOC, RTF, ODF, etc.
        
        *Some examples of what you can do:*
        
        -  Invoices
        -  Reports
        -  Listings
        
        Package to generate reports with
        `JasperReports <http://community.jaspersoft.com/project/jasperreports-library>`__
        library through
        `JasperStarter <https://bitbucket.org/cenote/jasperstarter/src>`__
        command-line tool.
        
        Requirements
        ------------
        
        -  Java JDK 1.8
        -  Python `subprocess.run() <https://docs.python.org/3/library/subprocess.html>`__ function
        -  Maven
        
        No support
        ------------
        .. image:: docs/mongodb-not-supported.jpg
        
        Optional
        --------
        
        -  `Mysql JDBC <http://dev.mysql.com/downloads/connector/j/>`__ (if you
           want to use database)
        -  `PostgreSQL JDBC <https://jdbc.postgresql.org/download.html>`__ (if
           you want to use database)
        -  `SQL Server
           JDBC <https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774>`__
           (if you want to use database)
        -  `Oracle
           JDBC <http://www.oracle.com/technetwork/apps-tech/jdbc-112010-090769.html>`__
           (if you want to use database)
        -  `Jaspersoft
           Studio <http://community.jaspersoft.com/project/jaspersoft-studio>`__
           (to draw and compile your reports)
        
        Note
        ~~~~
        
        -  The JDBC driver of your database should be place in the
           ``pyreportjasper/jasperstarter/jdbc/`` directory.
        -  Using **pyreportjasper**, you can also access different types of data
           sources, including CSV, JDBC, JSON, NoSQL, XML, or your own custom
           data source.
        
        
        Java (JDK and JRE)
        ~~~~~~~~~~~~~~~~~~
        
        Check if you already have Java installed:
        
        ::
        
            $ javac -version
            javac version 1.8.0_101
        
        If you get:
        
        ::
        
            command not found: javac
        
        Then install it with: (Ubuntu/Debian)
        
        ::
        
            $ sudo apt-get install default-jdk
        
        To install on: (centOS/Fedora)
        
        ::
        
            # yum install java-1.8.0-openjdk.x86_64
        
        To install on windows visit the link->
        `JDK <http://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html>`__
        and look for the most appropriate version for your system.
        
        Now run the ``javac -version`` again and check if the output is ok.
        
        Maven
        ~~~~~~~~~~~~~~~~~~
        
        Check if you already have Maven installed:
        
        ::
        
            $ mvn -version
            Maven home: /tmp/apache-maven-3.6.2
        
        If you get:
        
        ::
        
            command not found: mvn
        
        Then install it with: (Ubuntu/Debian)
        
        ::
        
            $ cd ~/Downloads
            $ wget https://www-us.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
            $ tar -zxf apache-maven-3.6.2-bin.tar.gz /tmp/
            $ sudo ln -s /tmp/apache-maven-3.6.2/bin/mvn /usr/local/bin/mvn
        
        Installation
        ------------
        
        Install `PyPI <https://pypi.python.org/pypi/pyreportjasper>`__ if you
        don't have it.
        
        ::
        
            pip install pyreportjasper
        
        Using the code
        ~~~~~~~~~~~~~~~
        
        Pyreport is actively developed in GitHub, where code is `always
        available <https://github.com/PyReportJasper/pyreportjasper>`__.
        
        You can clone the public repository:
        
        ::
        
            git clone git://github.com/PyReportJasper/pyreportjasper.git
        
        Download `tar
        file <https://github.com/PyReportJasper/pyreportjasper/tarball/master>`__:
        
        ::
        
            curl -OL https://github.com/PyReportJasper/pyreportjasper/tarball/master
        
        Or, Download the `zip
        file <https://github.com/PyReportJasper/pyreportjasper/zipball/master>`__:
        
        ::
        
            curl -OL https://github.com/PyReportJasper/pyreportjasper/zipball/master
        
        Unzip the downloaded file
        
        Navigate to the unzipped folder
        
        Once you have a copy of the code, you can easily include it in your
        Pytohn package, or install it in your site-packages directory:
        
        ::
        
            $ python setup.py install
        
        Examples
        --------
        
        The *Hello World* example.
        ~~~~~~~~~~~~~~~~~~~~~~~~~~
        
        Go to the examples directory in the root of the package Open the
        ``test/examples/hello_world.jrxml`` file with Jaspersoft Studio or with
        your favorite text editor and take a look at the source code.
        
        Compiling
        ^^^^^^^^^
        
        First we need to compile our ``JRXML`` file into a ``JASPER`` binary
        file. We just have to do this one time.
        
        **Note 1:** You don't need to do this step if you are using *Jaspersoft
        Studio*. You can compile directly within the program.
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def compiling():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/hello_world.jrxml'
                jasper = JasperPy()
                jasper.compile(input_file)
        
        This commando will compile the ``hello_world.jrxml`` source file to a
        ``hello_world.jasper`` file.
        
        Processing
        ^^^^^^^^^^
        
        Now lets process the report that we compile before:
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def processing():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/hello_world.jrxml'
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/examples'
                jasper = JasperPy()
                jasper.process(
                    input_file, output_file=output, format_list=["pdf", "rtf"])
        
        Now check the examples folder! :) Great right? You now have 2 files,
        ``hello_world.pdf`` and ``hello_world.rtf``.
        
        Check the *API* of the ``compile`` and ``process`` functions in the file
        ``pyreportjasper/jasperpy.py`` file.
        
        
        Advanced example - using a database
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
        We can also specify parameters for connecting to database:
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from platform import python_version
            from pyreportjasper import JasperPy
        
            def advanced_example_using_database():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/hello_world.jrxml'
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/examples'
                con = {
                    'driver': 'postgres',
                    'username': 'DB_USERNAME',
                    'password': 'DB_PASSWORD',
                    'host': 'DB_HOST',
                    'database': 'DB_DATABASE',
                    'schema': 'DB_SCHEMA',
                    'port': '5432'
                }
                jasper = JasperPy()
                jasper.process(
                    input_file,
                    output_file=output,
                    format_list=["pdf", "rtf", "xml"],
                    parameters={'python_version': python_version()},
                    db_connection=con,
                    locale='en_US'  # LOCALE Ex.:(pt_BR, de_GE)
                )
        
        **Note 2:**
        
        For a complete list of locales see `Supported
        Locales <http://www.oracle.com/technetwork/java/javase/java8locales-2095355.html>`__
        
        Reports from a XML
        ~~~~~~~~~~~~~~~~~~
        
        See how easy it is to generate a report with a source an XML file:
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def xml_to_pdf():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/CancelAck.jrxml'
        
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/_CancelAck'
        
                data_file = os.path.dirname(os.path.abspath(__file__)) + \
                    '/examples/CancelAck.xml'
        
                jasper = JasperPy()
        
                jasper.process(
                    input_file,
                    output_file=output,
                    format_list=["pdf"],
                    parameters={},
                    db_connection={
                        'data_file': data_file,
                        'driver': 'xml',
                        'xml_xpath': '/CancelResponse/CancelResult/ID',
                    },
                    locale='en_US'  # LOCALE Ex.:(pt_BR, de_GE)
                )
        
                print('Result is the file below.')
                print(output + '.pdf')
                
        
        Reports from a CSV File
        ~~~~~~~~~~~~~~~~~~~~~~~~
        
        See how easy it is to generate a report with a source an CSV file:
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def csv_to_pdf():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/csvMeta.jrxml'
        
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/_ContactsCSV'
        
                data_file = os.path.dirname(os.path.abspath(__file__)) + \
                    '/examples/csvExampleHeaders.csv'
        
                jasper = JasperPy()
                jasper.process(
                    input_file,
                    output_file=output,
                    format_list=["pdf"],
                    parameters={},
                    db_connection={
                        'data_file': data_file,
                        'driver': 'csv',
                        'csv_charset': 'utf8',
                        'csv_field_del': '|',
                        'csv_record_del': '\r\n',
                        #'csv_first_row': True,
                        'csv_columns': 'Name,Street,City,Phone'
                    },
                    locale='en_US'  # LOCALE Ex.:(pt_BR, de_GE)
                )
        
                print('Result is the file below.')
                print(output + '.pdf')
        
        
        Reports from a JSON File
        ~~~~~~~~~~~~~~~~~~~~~~~~
        
        See how easy it is to generate a report with a source an JSON file:
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def json_to_pdf():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/jsonql.jrxml'
        
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/_Contacts'
        
                data_file = os.path.dirname(os.path.abspath(__file__)) + \
                    '/examples/contacts.json'
        
                jasper = JasperPy()
                jasper.process_json(
                    input_file,
                    output_file=output,
                    format_list=["pdf"], # Only PDF is allowed
                    parameters={},
                    connection={
                        'data_file': data_file,
                        'driver': 'jsonql',
                        'json_query': 'contacts.person',
                        'json_locale': 'es_ES',
                        'json_date_pattern': 'yyyy-MM-dd',
                        'json_number_pattern': '#,##0.##'
                    },
                    locale='en_US'  # LOCALE Ex.:(pt_BR, de_GE)
                )
        
                print('Result is the file below.')
                print(output + '.pdf')
        
        **Note 3:**
        
        JasperReports can process JSON files using either the `original JSON DataSource
        <http://jasperreports.sourceforge.net/sample.reference/jsondatasource/index.html>`__
        or the `newer JSONQL Data Source
        <http://jasperreports.sourceforge.net/sample.reference/jsonqldatasource/index.html>`__.
        Refer to the JSONQL DataSource documentation for the differences. The example above
        uses the JSON DataSource. To use the enhanced capabilities of the JSONQL DataSource
        instead use:
        
        -   the ``jsonql.jrxml`` input file
        -   the ``jsonql`` driver setting
        -   the ``jsonql_query`` query setting
        
        by changing these three parts of the example:
        
        .. code-block:: python
        
            ...
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/jsonql.jrxml'
            ...
                    connection={
            ...
                        'driver': 'jsonql',
                        'jsonql_query': json_query,
                    },
        
        
        Reports from a JSON Request URL
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
        See how easy it is to generate a report with a source an JSON file:
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def json_to_pdf():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/jsonql.jrxml'
        
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/_Contacts'
        
                jasper = JasperPy()
                jasper.process_json(
                    input_file,
                    output_file=output,
                    format_list=["pdf"],
                    parameters={},
                    connection={
                        'url_file': 'https://acesseonline-arquivos-publicos.s3.us-east-2.amazonaws.com/contacts.json',
                        'url_method': 'GET', # POST, PUT
                        # 'url_params': {'param1': 'test'},
                        # 'url_data': {'data_field': 'abc123'},
                        # 'url_header': {'Authorization': 'Bearer xxxxxxxxxxxxxxxxxx'},
                        'driver': 'jsonql',
                        'jsonql_query': 'contacts.person',
                        'json_locale': 'es_ES',
                        'json_date_pattern': 'yyyy-MM-dd',
                        'json_number_pattern': '#,##0.##"'
                    },
                    locale='en_US'  # LOCALE Ex.:(pt_BR, de_GE)
                )
        
                print('Result is the file below.')
                print(output + '.pdf')
        
        
        Subreport Example
        ~~~~~~~~~~~~~~~~~
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
        
            def subreport_example():
        
                input_file_header = os.path.dirname(os.path.abspath(__file__)) + \
                                    '/examples/subreports/header.jrxml'
        
                input_file_details = os.path.dirname(os.path.abspath(__file__)) + \
                                     '/examples/subreports/details.jrxml'
        
                input_file_main = os.path.dirname(os.path.abspath(__file__)) + \
                                  '/examples/subreports/main.jrxml'
        
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/subreports/main.jasper'
        
                data_file = os.path.dirname(os.path.abspath(__file__)) + \
                            '/examples/subreports/contacts.xml'
        
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/examples/subreports/'
        
                jasper = JasperPy()
        
                jasper.compile(input_file_header)
                jasper.compile(input_file_details)
                jasper.compile(input_file_main)
        
                jasper.process(
                            input_file,
                            output_file=output,
                            format_list=["pdf"],
                            parameters={},
                            db_connection={
                                'data_file': data_file,
                                'driver': 'xml',
                                'xml_xpath': '"/"',
                            },
                            locale='en_US',  # LOCALE Ex.:(pt_BR, de_GE)
                            resource='examples/subreports/'
                        )
        
        Django Example
        ~~~~~~~~~~~~~~
        
        `Example Repository. <https://github.com/PyReportJasper/example_django>`__
        
        
        Flask Example
        ~~~~~~~~~~~~~
        
        Get parameters via URL and filter them if they are valid parameters for
        the *jrxml* file:
        
        After runnig you could visit
        http://localhost:5000/?myString=My%20Beautiful%20String&myInt=1&myDate=2017-01-01&this\_parameter=ignored
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from pyreportjasper import JasperPy
            from flask import Flask, request, make_response
        
        
            app = Flask(__name__)
            input_file =  os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/hello_world_params.jrxml'
            jasper = JasperPy()
        
        
            def compiling():
                jasper.compile(input_file)
        
            def processing():
                output_file = os.path.dirname(os.path.abspath(__file__)) + '/output/examples'
                jasper.process(input_file, output_file, format_list=["pdf"])
        
        
            @app.route('/')
            def my_route():
        
              processing()
        
              try:
                  with app.open_resource(os.path.dirname(os.path.abspath(__file__)) + '/output/examples/hello_world.pdf') as f:
                      content = f.read()
                  resposta = make_response(content)
                  resposta.headers['Content-Type'] = 'application/pdf; charset=utf-8'
                  resposta.headers['Content-Disposition'] = 'inline; filename=hello_world_params.pdf'
                  return resposta
              except IOError:
                  return make_response("<h1>403 Forbidden</h1>", 403)
        
            if __name__ == '__main__':
                compiling()
                app.run(host='0.0.0.0')
        
        
        Working with resources (i18n resource bundles, icons or images)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
        If you need provide resource to report, you can do that by set parameter
        ``resource`` in method ``jasper.process``. More details `jasper starter
        manual
        page <http://jasperstarter.cenote.de/usage.html#Reports_with_resources>`__.
        
        .. code-block:: python
        
            # -*- coding: utf-8 -*-
            import os
            from platform import python_version
            from pyreportjasper import JasperPy
        
            def advanced_example_using_database():
                input_file = os.path.dirname(os.path.abspath(__file__)) + \
                             '/examples/hello_world.jrxml'
                output = os.path.dirname(os.path.abspath(__file__)) + '/output/examples'
                con = {
                    'driver': 'postgres',
                    'username': 'DB_USERNAME',
                    'password': 'DB_PASSWORD',
                    'host': 'DB_HOST',
                    'database': 'DB_DATABASE',
                    'schema': 'DB_SCHEMA',
                    'port': '5432'
                }
                jasper = JasperPy()
                jasper.process(
                    input_file,
                    output_file=output,
                    format_list=["pdf", "rtf", "xml"],
                    parameters={'python_version': python_version()},
                    db_connection=con,
                    locale='en_US',  # LOCALE Ex.:(pt_BR, de_GE)
                    resource='path/to/my/resource/myresource.jar'
                )
        
        Tests
        ~~~~~
        
        All tests are in in the ``test`` directory. To run them
        
        ::
        
            python setup.py test
        
        Performance
        -----------
        
        Depends on the complexity, amount of data and the resources of your
        machine (let me know your use case).
        
        I have a report that generates a *Invoice* with a DB connection, images
        and multiple pages and it takes about **3/4 seconds** to process. I
        suggest that you use a worker to generate the reports in the background.
        
        Questions?
        ----------
        
        Open a `Issue <https://github.com/PyReportJasper/pyreportjasper/issues>`__
        
        Contribute
        ----------
        
        Contribute to the community Python, feel free to contribute, make a
        fork!!
        
        Contributors
        ~~~~~~~~~~~~
        
        -  `List of
           contributors <https://github.com/PyReportJasper/pyreportjasper/graphs/contributors>`__
        
        Thanks
        ------
        
        Thanks to `Cenote GmbH <http://www.cenote.de/>`__ for the
        `JasperStarter <http://jasperstarter.sourceforge.net/>`__ tool.
        
        .. |Travis| image:: https://travis-ci.org/PyReportJasper/pyreportjasper.svg?branch=master
           :target: https://travis-ci.org/PyReportJasper/pyreportjasper
        .. |Coverage| image:: https://coveralls.io/repos/github/PyReportJasper/pyreportjasper/badge.svg?branch=master
           :target: https://coveralls.io/github/PyReportJasper/pyreportjasper?branch=master
        .. |License| image:: https://img.shields.io/badge/License-GPLv3-blue.svg
           :target: https://github.com/PyReportJasper/pyreportjasper/blob/master/LICENSE
        .. |Donate| image:: https://img.shields.io/badge/donate-help%20keep-EB4A3B.svg
           :target: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=V2SUB9RQHYUGE&lc=US&item_name=pyreportjasper&item_number=pyreportjasper&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted
        .. |PythonVersion| image:: https://img.shields.io/badge/python->3.0-blue
           :target: https://pypi.org/project/pyreportjasper/
Keywords: report jasper python
Platform: Windows
Platform: Linux
Platform: Darwin
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Description-Content-Type: text/x-rst
