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 | |
License | |
Python Version | |
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:
- css-html-js-minify: 2.5 or higher
- htmlmin: 0.1 or higher
- Jinja2: 2.10 or higher
- pandas: 0.24 or higher
- python-dateutil: 2.8 or higher
- PyYAML: 5.1 or higher
- premailer: 3.5 or higher
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for reportlib-3.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03d840d9011732715e1394a3904f9f145b39bff8b3b13cab718fef4d446b1d2d |
|
MD5 | 5293cef7cc9fa0e143a7c22c67d2d16d |
|
BLAKE2b-256 | 2d7881384d6b4154624c8fdbd46b0c737e9d8b46756e2734acaed1ea20c42ccc |