Skip to main content

A package containing templates for reporting with Python.

Project description

reportio

Short Description

A package containing templates for reporting with Python.

Long Description

reportio is a Python package providing template classes in an effort to speed up report building for BI Developers. It aims to provide users with an API for interacting with various data sources and end-user file types as well as a simple object for quickly building straight-forward reports.

Examples

SimpleReport

from reportio import SimpleReport


# Initialize report object
objReport = SimpleReport("Yearly Sales")

# Add queries to report object
objReport.addQuery("Category", "SELECT * FROM CATEGORY", 'sqlite')
objReport.addQuery("Subcategory", "SELECT * FROM SUB_CATEGORY", 'sqlite')
objReport.addQuery("Segment", "SELECT * FROM SEGMENT", 'sqlite')

# Process and export
objReport.run()

ReportTemplate

import os
from typing import Dict, Any

from reportio import ReportTemplate


\# Create report object at runtime
class Report(ReportTemplate):
    """Test report."""

    def __init__(self,
                 report_name: str = 'test',
                 log_location: str = os.path.join(
                     os.path.dirname(__file__), 'simple_log.txt'),
                 config_location: str = os.path.join(
                     os.path.dirname(__file__), 'simple_config.txt'),
                 connection_dictionary: Dict[str, object] = {},
                 client: Any = None,
                 optional_function: callable = None) -> None:
        super().__init__(report_name,
                         log_location,
                         config_location,
                         connection_dictionary,
                         client,
                         optional_function)

    \# 'run' method must be instantiated
    def run(self):
        """Run test report."""
        self.file = self.get_data('test_data',
                                  "SELECT * FROM CATEGORY",
                                  'sqlite')[0]
        self.export_data(self.file, self.config['REPORT']['export_to'])


\# Script report object to run
if __name__ == '__main__':
    report = Report()
    try:
        report.run()
    except Exception:
        report.log("See log for debug details", 'CRITICAL')
        report.backup_data()
        report.log("Backup successful")
        input("PRESS ENTER KEY TO QUIT")
        report.log("QUITTING")

Windows Authentication of SSMS Database

Before utilizing reportio the user should first examine the config file. Below [DB] the user should add their database details if they plan to use a saved connection. Additional parameters may be added after the initial semicolon. For example:

myservername = DSN=servername;TrustedConnection=yes;

Additionally, be sure to verify the filepaths below the [REPORT] header.

Alternatively to using saved connections, the user may create their own connection at runtime. In this case, the header of your script should import reportio and your preferred connection module, and define your connection.

import reportio as r
import pyodbc

conn = pyodbc.connect(driver='{SQL Server Native Client 11.0}',
                      server='myserver',
                      database='mydatabase',
                      trusted_connection = 'yes')

You can create an instance of SimpleReport to get started. You need to provide a string name for your report. You can add, remove, and rename queries. When adding queries, you must provide a string name for the query, the SQL as a string, and the name of your saved connection or your created connection. When you run the report, the queries will be run with multithreading. To use single threading pass False into the run method.

rep=r.SimpleReport("test")
rep.addQuery("testQuery",
             "SELECT * FROM mydatabase.dbo.mytable",
             connection=conn)
rep.addQuery("testQuery2",
             "SELECT * FROM mydatabase.dbo.myothertable",
             connection=conn)
rep.run(False)

Logging

reportio has robust logging functionality. Refer to your config to find the filepaths for the output and logs. The console will also display this information, as well as the filepath to your report in an Excel file. If you run multiple queries in one report, your workbook will have a tab for each query.

Limitations

User should have solid grasp Python and object oriented programming. User should be familiar with available data sources and structures. User must be prepared to interact with data sources using SQL. User must deliver reports outside the scope of this module.

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

reportio-0.3.5.tar.gz (72.3 kB view details)

Uploaded Source

Built Distribution

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

reportio-0.3.5-py3-none-any.whl (86.3 kB view details)

Uploaded Python 3

File details

Details for the file reportio-0.3.5.tar.gz.

File metadata

  • Download URL: reportio-0.3.5.tar.gz
  • Upload date:
  • Size: 72.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for reportio-0.3.5.tar.gz
Algorithm Hash digest
SHA256 875e6c21348d4223acb16c726a8b24c7077f5e289e62a19be05c4d933d912196
MD5 6e634f7e3a96475a97ca8ba3aa2fea4d
BLAKE2b-256 9ebca3ca1cbc5e4d5f50b008f09c07a935588070280ef888ba7d7e47f163b801

See more details on using hashes here.

File details

Details for the file reportio-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: reportio-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 86.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for reportio-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 188bbb2e201ab8923fc42135f8728dd31a30ea7e24866d1c3546907d703a5f19
MD5 2cb81f82b76500886ea4e085bd80bdaa
BLAKE2b-256 6c3e38ccde7ac87a58d061f1159818ff4192c1cfa852adc4c2364294dfec29f1

See more details on using hashes here.

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