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

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

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

Uploaded Python 3

File details

Details for the file reportlib-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: reportlib-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

File hashes

Hashes for reportlib-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03d840d9011732715e1394a3904f9f145b39bff8b3b13cab718fef4d446b1d2d
MD5 5293cef7cc9fa0e143a7c22c67d2d16d
BLAKE2b-256 2d7881384d6b4154624c8fdbd46b0c737e9d8b46756e2734acaed1ea20c42ccc

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