Skip to main content

Generator HTML from pandas via Jinja2

Project description

reportlib

Flexible and powerful report library for Python or Python Notebooks with Pandas and Jinja2 support

Latest Release latest release
License license
Python Version python version
Wheel wheel

What is it?

reportlib is a Python package providing fast and flexible utilities to decorate and render a report. Because it based on pandas's Styler, it is friendly with pandas DataFrame, so if you got your data, you can easily display and export it.

Main Features

Here are just a few of the things that reportlib does well:

  • Powerful and flexible Styler based on pandas's Styler, friendly with pandas DataFrame, with more styling methods
  • Friendly with Email: The HTML output use inline-css, you can send via email and that email also can be forwarded
  • Friendly with Python Notebooks, so you can display Styler or Report in html
  • Config parser: from string to other data types, for quickly get config from environment or other config files
  • Customize everything with Jinja2 support: table head & foot (Styler), Report template, css

Where to get it

The source code is currently hosted on Teko's Gitlab at: https://git.teko.vn/data/libs/reportlib

Binary installers for the latest released version are available at the Python package index

pip install reportlib

Dependencies:

Installation from sources:

Clone the repository then execute following command in the reportlib directory (same one where you found this file after cloning the git repo)

python setup.py install

Alternatively, you can use pip if you want all the dependencies pulled in automatically (the -e option is for installing it in development mode):

pip install -e .

Basic usage

Project structure

root/ (or root/src/)
 |-+-templates/
 | |-styles.css
 |-report.py
 |-metadata.yml
 ...

Config report

export REPORT_DATE='2019-06-30'

Render report

"""report.py"""

import os
import pandas as pd
import numpy as np
from datetime import datetime
from dateutil.relativedelta import relativedelta
import reportlib
from reportlib import Report, ConfigParser, Styler

# Parse config from env
config = ConfigParser(config=os.environ)
report_date = config.date('REPORT_DATE', default='yesterday')

# Prepare data
df = pd.DataFrame(np.random.randn(8, 4), columns=['a', 'b', 'c', 'd'])

# Config report
reportlib.add_template_dir('templates')
Styler.set_option('precision', 2)
Styler.set_option('fillna', '-')
Styler.set_option('fillinf', '-')
Styler.set_option('fillzero', '-')

# Initial generator
report = Report(
  styles='styles.css',
  title='Report Demo',
  context={
    'report_date': report_date
  },
)

# Styling data
style = (
  Styler(df)
  .add_class('bold highlight', subset=pd.IndexSlice[0:1, df.columns])  # Bold and Highlight some row by using class `highlight`
  .add_class('text-right', columns=df.columns)  # Align right columns
)

# Add tables
report.add_table(style)

# Run report
html_string = report.render()

# Or display it if you use a Python Notebook Interface like Jupyter
report.show()

Full Documentation

You can found full documentation in Wiki

Getting Help

For usage questions, the best place to go to is Full Documentation. Further, for general questions and discussions, you can create an issue or contact me via email at nhat.nv@teko.vn or via Teko's workplace

Contributing to reportlib

All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

reportlib-3.4.0-py3-none-any.whl (15.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page